├── .gitignore ├── Assets ├── Scenes.meta ├── Scenes │ ├── exampleActionTimeline.unity │ └── exampleActionTimeline.unity.meta ├── Scripts.meta └── Scripts │ ├── ColorAction.cs │ ├── ColorAction.cs.meta │ ├── ITimeChanging.cs │ ├── ITimeChanging.cs.meta │ ├── LineMovement.cs │ ├── LineMovement.cs.meta │ ├── StandardManager.cs │ ├── StandardManager.cs.meta │ ├── TimeLineBehavior.cs │ ├── TimeLineBehavior.cs.meta │ ├── TimeManager.cs │ └── TimeManager.cs.meta └── ProjectSettings ├── AudioManager.asset ├── DynamicsManager.asset ├── EditorBuildSettings.asset ├── EditorSettings.asset ├── GraphicsSettings.asset ├── InputManager.asset ├── NavMeshAreas.asset ├── NetworkManager.asset ├── Physics2DSettings.asset ├── ProjectSettings.asset ├── ProjectVersion.txt ├── QualitySettings.asset ├── TagManager.asset ├── TimeManager.asset ├── UnityAdsSettings.asset └── UnityAnalyticsManager.asset /.gitignore: -------------------------------------------------------------------------------- 1 | Library/ 2 | Temp/ 3 | .vs/timelineExample/v14/.suo 4 | timelineActionExample.CSharp.csproj 5 | timelineActionExample.sln 6 | -------------------------------------------------------------------------------- /Assets/Scenes.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: bccdb98f28163584bbf65a14ac99638b 3 | folderAsset: yes 4 | timeCreated: 1467566175 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Scenes/exampleActionTimeline.unity: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexander91/timelineActionExample/33b21b20b9589e28da0f7a51802a87e86b49d576/Assets/Scenes/exampleActionTimeline.unity -------------------------------------------------------------------------------- /Assets/Scenes/exampleActionTimeline.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2e0eaebd82e31d64a8213be3369e9ca1 3 | timeCreated: 1467566175 4 | licenseType: Free 5 | DefaultImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Scripts.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c072532c356557e44ab97e216934383a 3 | folderAsset: yes 4 | timeCreated: 1467566238 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Scripts/ColorAction.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | public class ColorAction : MonoBehaviour 5 | { 6 | [SerializeField] 7 | StandardManager timeManager; 8 | 9 | public void OnTriggerEnter(Collider other) 10 | { 11 | 12 | var renderer = GetComponent(); 13 | 14 | // remember value before changing 15 | var startColor = renderer.material.color; 16 | // change 17 | renderer.material.color = Color.red; 18 | 19 | // remember as reversible action 20 | timeManager.TimeManager.RememberAction(()=> 21 | { 22 | renderer.material.color = startColor; 23 | }); 24 | 25 | } 26 | 27 | GameObject explosionPrefab; 28 | 29 | // Use this for initialization 30 | void Start() 31 | { 32 | 33 | } 34 | 35 | // Update is called once per frame 36 | void Update() 37 | { 38 | 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Assets/Scripts/ColorAction.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: cae50d0c022377d41b1ad488793881f4 3 | timeCreated: 1472592720 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Scripts/ITimeChanging.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | public interface ITimeChanging 5 | { 6 | void AddTime(float dt); 7 | } 8 | -------------------------------------------------------------------------------- /Assets/Scripts/ITimeChanging.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 87f818e987e3f9d4f8edb9bd5b4ca9ab 3 | timeCreated: 1467566294 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Scripts/LineMovement.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | using System; 4 | 5 | public class LineMovement : MonoBehaviour, ITimeChanging { 6 | 7 | [SerializeField] 8 | Vector3 direction = Vector3.up; 9 | [SerializeField] 10 | float speed = 0.2f; 11 | 12 | public void AddTime(float dt) 13 | { 14 | transform.position += dt * speed * direction.normalized; 15 | } 16 | 17 | // Use this for initialization 18 | void Start () { 19 | 20 | } 21 | 22 | // Update is called once per frame 23 | void Update () { 24 | 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Assets/Scripts/LineMovement.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2fa698b98a164774c8592e9504deed12 3 | timeCreated: 1467566791 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Scripts/StandardManager.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | 6 | public class StandardManager : MonoBehaviour { 7 | private TimeManager timeManager = new TimeManager(); 8 | 9 | [SerializeField] 10 | UnityEngine.UI.Text label; 11 | 12 | [SerializeField] 13 | float playTime = 2.5f; 14 | 15 | float sign = 1.0f; 16 | 17 | public TimeManager TimeManager 18 | { 19 | get 20 | { 21 | return timeManager; 22 | } 23 | } 24 | 25 | // Use this for initialization 26 | void Start () { 27 | 28 | 29 | var allBehs = GetComponentsInChildren(); 30 | var allBehsList = new List(allBehs); 31 | var timeDependant = allBehsList.OfType(); 32 | 33 | timeManager.TimeDependants = timeDependant; 34 | 35 | } 36 | 37 | // Update is called once per frame 38 | void Update () { 39 | timeManager.Time += sign * Time.deltaTime; 40 | if (timeManager.Time > playTime) 41 | { 42 | sign = -1.0f; 43 | 44 | label.text = "Reverse Time"; 45 | label.color = Color.red; 46 | } 47 | if (timeManager.Time < 0) 48 | { 49 | sign = 1.0f; 50 | 51 | label.text = "Forward Time"; 52 | label.color = Color.green; 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /Assets/Scripts/StandardManager.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: fd02388eee1628740a0b2fd1705539ec 3 | timeCreated: 1467566666 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Scripts/TimeLineBehavior.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | using System.Collections; 4 | using System.Collections.Generic; 5 | 6 | #if UNITY_EDITOR 7 | using UnityEditor; 8 | using System.Linq; 9 | #endif 10 | 11 | 12 | [ExecuteInEditMode] 13 | public class TimeLineBehavior : MonoBehaviour { 14 | 15 | public float nowTime; 16 | 17 | [SerializeField] 18 | bool setZero = false; 19 | 20 | [SerializeField] 21 | bool setNowAsZero = false; 22 | 23 | TimeManager timeManager = new TimeManager(); 24 | 25 | #if UNITY_EDITOR 26 | // Use this for initialization 27 | void Start () { 28 | EditorApplication.playmodeStateChanged += HandleOnPlayModeChanged; 29 | } 30 | 31 | void OnDestroy(){ 32 | EditorApplication.playmodeStateChanged -= HandleOnPlayModeChanged; 33 | } 34 | 35 | void UpdateTime() 36 | { 37 | var allBehs = GetComponentsInChildren(); 38 | var allBehsList = new List(allBehs); 39 | var timeDependant = allBehsList.OfType(); 40 | 41 | timeManager.TimeDependants = timeDependant; 42 | 43 | timeManager.Time = nowTime; 44 | nowTime = timeManager.Time; 45 | } 46 | 47 | void CheckSetNowAsZero() 48 | { 49 | if (setNowAsZero) 50 | { 51 | timeManager.SetTimeBruteForce(0f); 52 | nowTime = 0f; 53 | setNowAsZero = false; 54 | } 55 | } 56 | 57 | void HandleOnPlayModeChanged() 58 | { 59 | // This method is run whenever the playmode state is changed. 60 | 61 | if (EditorApplication.isPlaying) { return; } 62 | 63 | if (EditorApplication.isPlayingOrWillChangePlaymode) 64 | { 65 | nowTime = 0; 66 | UpdateTime(); 67 | } 68 | } 69 | 70 | void CheckSetZero() 71 | { 72 | if (setZero) 73 | { 74 | setZero = false; 75 | nowTime = 0; 76 | } 77 | } 78 | 79 | // Update is called once per frame 80 | public void Update () { 81 | if (EditorApplication.isPlaying) return; 82 | 83 | CheckSetZero(); 84 | UpdateTime(); 85 | CheckSetNowAsZero(); 86 | } 87 | #endif 88 | } 89 | 90 | 91 | -------------------------------------------------------------------------------- /Assets/Scripts/TimeLineBehavior.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6a008c334f10a3143abf5a4edfb5bb81 3 | timeCreated: 1467566476 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Scripts/TimeManager.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using UnityEngine; 5 | 6 | public delegate void ReversingTimeActionDelegate(); 7 | 8 | class ReversingActionWithTime 9 | { 10 | public ReversingActionWithTime(float time, ReversingTimeActionDelegate action) 11 | { 12 | this.time = time; 13 | this.actionToCarry = action; 14 | } 15 | public float time; 16 | public ReversingTimeActionDelegate actionToCarry; 17 | } 18 | 19 | public class TimeManager 20 | { 21 | private float time; 22 | 23 | public TimeManager() 24 | { 25 | TimeDependants = new List(); 26 | } 27 | 28 | public float Time 29 | { 30 | get 31 | { 32 | return time; 33 | } 34 | set 35 | { 36 | if (value != time) 37 | { 38 | var delta = value - time; 39 | if (delta < 0) 40 | { 41 | while ((actions.Count > 0) && (actions.Peek().time >= time + delta)) 42 | { 43 | var nowDelta = actions.Peek().time - time; 44 | applyTimechange(nowDelta); 45 | var action = actions.Pop(); 46 | action.actionToCarry(); 47 | applyTimechange(nowDelta); 48 | delta -= nowDelta; 49 | } 50 | applyTimechange(delta); 51 | } 52 | else 53 | { 54 | applyTimechange(delta); 55 | } 56 | } 57 | 58 | } 59 | } 60 | 61 | private void applyTimechange(float delta) 62 | { 63 | foreach (var timeDep in TimeDependants) 64 | { 65 | timeDep.AddTime(delta); 66 | } 67 | time += delta; 68 | } 69 | 70 | public void SetTimeBruteForce(float time) 71 | { 72 | this.time = time; 73 | } 74 | 75 | public IEnumerable TimeDependants { get; set; } 76 | 77 | public void RememberAction(ReversingTimeActionDelegate action) 78 | { 79 | actions.Push(new ReversingActionWithTime(Time, action)); 80 | } 81 | 82 | Stack actions = new Stack(); 83 | 84 | } 85 | 86 | -------------------------------------------------------------------------------- /Assets/Scripts/TimeManager.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1f0b8a2f85e53ce4d83ce51c493fae00 3 | timeCreated: 1467566270 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /ProjectSettings/AudioManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexander91/timelineActionExample/33b21b20b9589e28da0f7a51802a87e86b49d576/ProjectSettings/AudioManager.asset -------------------------------------------------------------------------------- /ProjectSettings/DynamicsManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexander91/timelineActionExample/33b21b20b9589e28da0f7a51802a87e86b49d576/ProjectSettings/DynamicsManager.asset -------------------------------------------------------------------------------- /ProjectSettings/EditorBuildSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexander91/timelineActionExample/33b21b20b9589e28da0f7a51802a87e86b49d576/ProjectSettings/EditorBuildSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/EditorSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexander91/timelineActionExample/33b21b20b9589e28da0f7a51802a87e86b49d576/ProjectSettings/EditorSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/GraphicsSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexander91/timelineActionExample/33b21b20b9589e28da0f7a51802a87e86b49d576/ProjectSettings/GraphicsSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/InputManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexander91/timelineActionExample/33b21b20b9589e28da0f7a51802a87e86b49d576/ProjectSettings/InputManager.asset -------------------------------------------------------------------------------- /ProjectSettings/NavMeshAreas.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexander91/timelineActionExample/33b21b20b9589e28da0f7a51802a87e86b49d576/ProjectSettings/NavMeshAreas.asset -------------------------------------------------------------------------------- /ProjectSettings/NetworkManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexander91/timelineActionExample/33b21b20b9589e28da0f7a51802a87e86b49d576/ProjectSettings/NetworkManager.asset -------------------------------------------------------------------------------- /ProjectSettings/Physics2DSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexander91/timelineActionExample/33b21b20b9589e28da0f7a51802a87e86b49d576/ProjectSettings/Physics2DSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/ProjectSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexander91/timelineActionExample/33b21b20b9589e28da0f7a51802a87e86b49d576/ProjectSettings/ProjectSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/ProjectVersion.txt: -------------------------------------------------------------------------------- 1 | m_EditorVersion: 5.2.2f1 2 | m_StandardAssetsVersion: 0 3 | -------------------------------------------------------------------------------- /ProjectSettings/QualitySettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexander91/timelineActionExample/33b21b20b9589e28da0f7a51802a87e86b49d576/ProjectSettings/QualitySettings.asset -------------------------------------------------------------------------------- /ProjectSettings/TagManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexander91/timelineActionExample/33b21b20b9589e28da0f7a51802a87e86b49d576/ProjectSettings/TagManager.asset -------------------------------------------------------------------------------- /ProjectSettings/TimeManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexander91/timelineActionExample/33b21b20b9589e28da0f7a51802a87e86b49d576/ProjectSettings/TimeManager.asset -------------------------------------------------------------------------------- /ProjectSettings/UnityAdsSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexander91/timelineActionExample/33b21b20b9589e28da0f7a51802a87e86b49d576/ProjectSettings/UnityAdsSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/UnityAnalyticsManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexander91/timelineActionExample/33b21b20b9589e28da0f7a51802a87e86b49d576/ProjectSettings/UnityAnalyticsManager.asset --------------------------------------------------------------------------------