From 3a62bff4f5022078eb56a9b56af597ded52183af Mon Sep 17 00:00:00 2001 From: Jesus Imery Date: Thu, 9 Feb 2017 23:04:29 -0500 Subject: [PATCH] #1 #2 tentative PausableTrailRnderer implementation and test scene that might get thrown away --- Assets/Prefabs/Shadow Trail Renderer.prefab | 140 ++++++++++++++++++ .../Prefabs/Shadow Trail Renderer.prefab.meta | 8 + Assets/Prefabs/Test Shadow Cube.prefab | 102 +------------ .../Testing Custom Timereset.unity | 3 +- Assets/Scripts/Time Mechanics/Looper.cs | 13 +- Assets/Scripts/Time Mechanics/Recorder.cs | 10 +- .../Scripts/Time Mechanics/TimelineManager.cs | 13 +- Assets/Scripts/UI.meta | 9 ++ .../Scripts/UI/PausableTrailRendererTarget.cs | 31 ++++ .../UI/PausableTrailRendererTarget.cs.meta | 12 ++ 10 files changed, 234 insertions(+), 107 deletions(-) create mode 100644 Assets/Prefabs/Shadow Trail Renderer.prefab create mode 100644 Assets/Prefabs/Shadow Trail Renderer.prefab.meta create mode 100644 Assets/Scripts/UI.meta create mode 100644 Assets/Scripts/UI/PausableTrailRendererTarget.cs create mode 100644 Assets/Scripts/UI/PausableTrailRendererTarget.cs.meta diff --git a/Assets/Prefabs/Shadow Trail Renderer.prefab b/Assets/Prefabs/Shadow Trail Renderer.prefab new file mode 100644 index 0000000..1ccf92c --- /dev/null +++ b/Assets/Prefabs/Shadow Trail Renderer.prefab @@ -0,0 +1,140 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!1001 &100100000 +Prefab: + m_ObjectHideFlags: 1 + serializedVersion: 2 + m_Modification: + m_TransformParent: {fileID: 0} + m_Modifications: [] + m_RemovedComponents: [] + m_ParentPrefab: {fileID: 0} + m_RootGameObject: {fileID: 1452260926465948} + m_IsPrefabParent: 1 +--- !u!1 &1452260926465948 +GameObject: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + serializedVersion: 5 + m_Component: + - component: {fileID: 4552144090377578} + - component: {fileID: 96964719732289224} + m_Layer: 0 + m_Name: Shadow Trail Renderer + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &4552144090377578 +Transform: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 1452260926465948} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 323.86365, y: 0.5478251, z: 122.20422} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!96 &96964719732289224 +TrailRenderer: + serializedVersion: 2 + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 1452260926465948} + m_Enabled: 1 + m_CastShadows: 1 + m_ReceiveShadows: 1 + m_MotionVectors: 1 + m_LightProbeUsage: 0 + m_ReflectionProbeUsage: 0 + m_Materials: + - {fileID: 2100000, guid: 9070154db9d0b5d4c9f02c4b0da14cf8, type: 2} + m_StaticBatchInfo: + firstSubMesh: 0 + subMeshCount: 0 + m_StaticBatchRoot: {fileID: 0} + m_ProbeAnchor: {fileID: 0} + m_LightProbeVolumeOverride: {fileID: 0} + m_ScaleInLightmap: 1 + m_PreserveUVs: 0 + m_IgnoreNormalsForChartDetection: 0 + m_ImportantGI: 0 + m_SelectedEditorRenderState: 3 + m_MinimumChartSize: 4 + m_AutoUVMaxDistance: 0.5 + m_AutoUVMaxAngle: 89 + m_LightmapParameters: {fileID: 0} + m_SortingLayerID: 0 + m_SortingOrder: 0 + m_Time: 10000000 + m_Parameters: + serializedVersion: 2 + widthMultiplier: 1 + widthCurve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 2 + time: 0 + value: 1 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 + colorGradient: + key0: + serializedVersion: 2 + rgba: 4294967295 + key1: + serializedVersion: 2 + rgba: 4294967295 + key2: + serializedVersion: 2 + rgba: 0 + key3: + serializedVersion: 2 + rgba: 0 + key4: + serializedVersion: 2 + rgba: 0 + key5: + serializedVersion: 2 + rgba: 0 + key6: + serializedVersion: 2 + rgba: 0 + key7: + serializedVersion: 2 + rgba: 0 + ctime0: 0 + ctime1: 65535 + ctime2: 0 + ctime3: 0 + ctime4: 0 + ctime5: 0 + ctime6: 0 + ctime7: 0 + atime0: 0 + atime1: 65535 + atime2: 0 + atime3: 0 + atime4: 0 + atime5: 0 + atime6: 0 + atime7: 0 + m_Mode: 0 + m_NumColorKeys: 2 + m_NumAlphaKeys: 2 + numCornerVertices: 0 + numCapVertices: 0 + alignment: 0 + textureMode: 0 + m_MinVertexDistance: 0.1 + m_Autodestruct: 0 diff --git a/Assets/Prefabs/Shadow Trail Renderer.prefab.meta b/Assets/Prefabs/Shadow Trail Renderer.prefab.meta new file mode 100644 index 0000000..b071ccf --- /dev/null +++ b/Assets/Prefabs/Shadow Trail Renderer.prefab.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 89d696b01c8236c46a0925a288b34308 +timeCreated: 1486698160 +licenseType: Free +NativeFormatImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Prefabs/Test Shadow Cube.prefab b/Assets/Prefabs/Test Shadow Cube.prefab index a5cfed6..a1757b3 100644 --- a/Assets/Prefabs/Test Shadow Cube.prefab +++ b/Assets/Prefabs/Test Shadow Cube.prefab @@ -23,7 +23,7 @@ GameObject: - component: {fileID: 65735452598567560} - component: {fileID: 23834119766803998} - component: {fileID: 114935342693874920} - - component: {fileID: 96677447906534260} + - component: {fileID: 114480644409964434} m_Layer: 0 m_Name: Test Shadow Cube m_TagString: Untagged @@ -94,104 +94,18 @@ BoxCollider: serializedVersion: 2 m_Size: {x: 1, y: 1, z: 1} m_Center: {x: 0, y: 0, z: 0} ---- !u!96 &96677447906534260 -TrailRenderer: - serializedVersion: 2 +--- !u!114 &114480644409964434 +MonoBehaviour: m_ObjectHideFlags: 1 m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 100100000} m_GameObject: {fileID: 1614062590372156} m_Enabled: 1 - m_CastShadows: 1 - m_ReceiveShadows: 1 - m_MotionVectors: 1 - m_LightProbeUsage: 0 - m_ReflectionProbeUsage: 0 - m_Materials: - - {fileID: 2100000, guid: 9070154db9d0b5d4c9f02c4b0da14cf8, type: 2} - m_StaticBatchInfo: - firstSubMesh: 0 - subMeshCount: 0 - m_StaticBatchRoot: {fileID: 0} - m_ProbeAnchor: {fileID: 0} - m_LightProbeVolumeOverride: {fileID: 0} - m_ScaleInLightmap: 1 - m_PreserveUVs: 0 - m_IgnoreNormalsForChartDetection: 0 - m_ImportantGI: 0 - m_SelectedEditorRenderState: 3 - m_MinimumChartSize: 4 - m_AutoUVMaxDistance: 0.5 - m_AutoUVMaxAngle: 89 - m_LightmapParameters: {fileID: 0} - m_SortingLayerID: 0 - m_SortingOrder: 0 - m_Time: 10000000 - m_Parameters: - serializedVersion: 2 - widthMultiplier: 1 - widthCurve: - serializedVersion: 2 - m_Curve: - - serializedVersion: 2 - time: 0 - value: 1 - inSlope: 0 - outSlope: 0 - tangentMode: 0 - m_PreInfinity: 2 - m_PostInfinity: 2 - m_RotationOrder: 4 - colorGradient: - key0: - serializedVersion: 2 - rgba: 4294967295 - key1: - serializedVersion: 2 - rgba: 4294967295 - key2: - serializedVersion: 2 - rgba: 0 - key3: - serializedVersion: 2 - rgba: 0 - key4: - serializedVersion: 2 - rgba: 0 - key5: - serializedVersion: 2 - rgba: 0 - key6: - serializedVersion: 2 - rgba: 0 - key7: - serializedVersion: 2 - rgba: 0 - ctime0: 0 - ctime1: 65535 - ctime2: 0 - ctime3: 0 - ctime4: 0 - ctime5: 0 - ctime6: 0 - ctime7: 0 - atime0: 0 - atime1: 65535 - atime2: 0 - atime3: 0 - atime4: 0 - atime5: 0 - atime6: 0 - atime7: 0 - m_Mode: 0 - m_NumColorKeys: 2 - m_NumAlphaKeys: 2 - numCornerVertices: 0 - numCapVertices: 0 - alignment: 0 - textureMode: 0 - m_MinVertexDistance: 0.1 - m_Autodestruct: 0 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 783425d233a54f44ea51f570a7391c62, type: 3} + m_Name: + m_EditorClassIdentifier: + trailRendererObject: {fileID: 0} --- !u!114 &114935342693874920 MonoBehaviour: m_ObjectHideFlags: 1 diff --git a/Assets/Scene/Test Scenes/Testing Custom Timereset.unity b/Assets/Scene/Test Scenes/Testing Custom Timereset.unity index 1db659d..9f5a267 100644 --- a/Assets/Scene/Test Scenes/Testing Custom Timereset.unity +++ b/Assets/Scene/Test Scenes/Testing Custom Timereset.unity @@ -120,6 +120,8 @@ MonoBehaviour: m_EditorClassIdentifier: shadowPrefab: {fileID: 1614062590372156, guid: fcf9134591e22d94aa1b0215e54cef7b, type: 2} + trailRendererPrefab: {fileID: 1452260926465948, guid: 89d696b01c8236c46a0925a288b34308, + type: 2} --- !u!4 &238929857 Transform: m_ObjectHideFlags: 0 @@ -833,7 +835,6 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: recordedTransform: {fileID: 2053729386} - recordedTrail: {fileID: 0} --- !u!4 &2053729386 stripped Transform: m_PrefabParentObject: {fileID: 400000, guid: 5e9e851c0e142814dac026a256ba2ac0, type: 2} diff --git a/Assets/Scripts/Time Mechanics/Looper.cs b/Assets/Scripts/Time Mechanics/Looper.cs index 8e906b1..7ea9c95 100644 --- a/Assets/Scripts/Time Mechanics/Looper.cs +++ b/Assets/Scripts/Time Mechanics/Looper.cs @@ -18,6 +18,8 @@ public class Looper : MonoBehaviour Queue recordedRotations; Queue recordedTimes; + bool temp = false; + // Use this for initialization void Start() { @@ -46,7 +48,7 @@ private void FixedUpdate() } } - public void StartLooping(Queue recordedPositions, Queue recordedRotations, Queue recordedTimes, TrailRenderer trailRenderer) + public void StartLooping(Queue recordedPositions, Queue recordedRotations, Queue recordedTimes) { this.recordedPositions = recordedPositions; this.recordedTimes = recordedTimes; @@ -75,12 +77,21 @@ void NextFrameAction() gameObject.transform.position = tempVector; gameObject.transform.localRotation = tempQuartenion; //Debug.Log(originalRecordedTimes.Count); + + if (temp) + { + GetComponent().ToogleTrailRenderer(); + temp = false; + } } while (loopingTimer > tempFloat && recordedPositions.Count > 0); } private void Reloop() { + GetComponent().ToogleTrailRenderer(); + temp = true; + recordedPositions = new Queue(originalRecordedPositions); recordedRotations = new Queue(originalRecordedRotations); recordedTimes = new Queue(originalRecordedTimes); diff --git a/Assets/Scripts/Time Mechanics/Recorder.cs b/Assets/Scripts/Time Mechanics/Recorder.cs index 751bf68..84066d8 100644 --- a/Assets/Scripts/Time Mechanics/Recorder.cs +++ b/Assets/Scripts/Time Mechanics/Recorder.cs @@ -6,7 +6,6 @@ public class Recorder : MonoBehaviour { // Public references public Transform recordedTransform; // NOTE TO SELF: GET REFERENCE ON START - public TrailRenderer recordedTrail; // Private references private TimelineManager timelineManager; @@ -60,15 +59,11 @@ private void StartRecording() { recordingTimer = 0; - recordedTrail.enabled = true; - recording = true; } private void StopRecording() { - recordedTrail.enabled = false; - recording = false; } @@ -83,9 +78,6 @@ private void RecordFrame() private void CreateShadow() { - - recordedTrail.time = 100; // FIX ME TO NOT HARDCODED - timelineManager.CreateShadow(recordedPositions, recordedRotations, recordedTimes, recordedTrail); - recordedTrail.time = 500000000000; // FIX ME TO NOT HARDCODED + timelineManager.CreateShadow(recordedPositions, recordedRotations, recordedTimes); } } diff --git a/Assets/Scripts/Time Mechanics/TimelineManager.cs b/Assets/Scripts/Time Mechanics/TimelineManager.cs index a6b8416..6b19ab8 100644 --- a/Assets/Scripts/Time Mechanics/TimelineManager.cs +++ b/Assets/Scripts/Time Mechanics/TimelineManager.cs @@ -5,6 +5,7 @@ public class TimelineManager : Singleton { public GameObject shadowPrefab; + public GameObject trailRendererPrefab; List loopingShadows; @@ -18,13 +19,21 @@ void Update () { } - public void CreateShadow(Queue recordedPositions, Queue recordedRotations, Queue recordedTimes, TrailRenderer trailRenderer) + public void CreateShadow(Queue recordedPositions, Queue recordedRotations, Queue recordedTimes) { // NOTE TO SELF: CAST CONCERNS? GameObject shadow = (GameObject) Instantiate(shadowPrefab); + // Create pausable time renderer and attach to shadow + GameObject trail = (GameObject)Instantiate(trailRendererPrefab); + + // TODO: some code here to assign the color of this trail + + shadow.GetComponent().trailRendererObject = trail; + shadow.GetComponent().ToogleTrailRenderer(); + loopingShadows.Add(shadow); - shadow.GetComponent().StartLooping(recordedPositions, recordedRotations, recordedTimes, trailRenderer); + shadow.GetComponent().StartLooping(recordedPositions, recordedRotations, recordedTimes); } } diff --git a/Assets/Scripts/UI.meta b/Assets/Scripts/UI.meta new file mode 100644 index 0000000..e3469fa --- /dev/null +++ b/Assets/Scripts/UI.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 193fd8f85e17309478b8a6f8a2414fbc +folderAsset: yes +timeCreated: 1486697984 +licenseType: Free +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/UI/PausableTrailRendererTarget.cs b/Assets/Scripts/UI/PausableTrailRendererTarget.cs new file mode 100644 index 0000000..e0ea664 --- /dev/null +++ b/Assets/Scripts/UI/PausableTrailRendererTarget.cs @@ -0,0 +1,31 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class PausableTrailRendererTarget : MonoBehaviour +{ + //Attach this code to the object the trailRenderer needs to follow. + //the trail renderer itself should be a separate object not a child of this one + //[HideInInspector] + public GameObject trailRendererObject; + + bool trailActiveBool = false; + + void Start() + { + + } + + void Update() + { + if (trailActiveBool == true) + { + trailRendererObject.transform.position = gameObject.transform.position; + } + } + + public void ToogleTrailRenderer() + { + trailActiveBool = !trailActiveBool; + } +} diff --git a/Assets/Scripts/UI/PausableTrailRendererTarget.cs.meta b/Assets/Scripts/UI/PausableTrailRendererTarget.cs.meta new file mode 100644 index 0000000..b6e6535 --- /dev/null +++ b/Assets/Scripts/UI/PausableTrailRendererTarget.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 783425d233a54f44ea51f570a7391c62 +timeCreated: 1486698000 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: