/** * <summary>Serialises appropriate GameObject values into a string.</summary> * <returns>The data, serialised as a string</returns> */ public override string SaveData() { TimelineData timelineData = new TimelineData(); timelineData.objectID = constantID; timelineData.savePrevented = savePrevented; #if UNITY_2017_1_OR_NEWER PlayableDirector director = GetComponent <PlayableDirector>(); timelineData.isPlaying = (director.state == PlayState.Playing); timelineData.currentTime = director.time; #else ACDebug.LogWarning("The 'Remember Director' component is only compatible with Unity 5.6 onward.", this); #endif return(Serializer.SaveScriptData <TimelineData> (timelineData)); }
/** * <summary>Deserialises a string of data, and restores the GameObject to its previous state.</summary> * <param name = "stringData">The data, serialised as a string</param> * <param name = "restoringSaveFile">True if the game is currently loading a saved game file, as opposed to just switching scene</param> */ public override void LoadData(string stringData, bool restoringSaveFile = false) { TimelineData data = Serializer.LoadScriptData <TimelineData> (stringData); if (data == null) { return; } SavePrevented = data.savePrevented; if (savePrevented) { return; } PlayableDirector director = GetComponent <PlayableDirector>(); if (director != null && director.playableAsset != null) { TimelineAsset timeline = (TimelineAsset)director.playableAsset; if (timeline != null) { if (saveTimelineAsset) { TimelineAsset _timeline = AssetLoader.RetrieveAsset(timeline, data.timelineAssetID); if (_timeline != null) { director.playableAsset = _timeline; timeline = _timeline; } } if (saveBindings && !string.IsNullOrEmpty(data.trackObjectData)) { string[] bindingIDs = data.trackObjectData.Split(","[0]); for (int i = 0; i < bindingIDs.Length; i++) { int bindingID = 0; if (int.TryParse(bindingIDs[i], out bindingID)) { if (bindingID != 0) { var track = timeline.GetOutputTrack(i); if (track != null) { ConstantID savedObject = Serializer.returnComponent <ConstantID> (bindingID, gameObject); if (savedObject != null) { director.SetGenericBinding(track, savedObject.gameObject); } } } } } } } } director.time = data.currentTime; if (data.isPlaying) { director.Play(); } else { director.Stop(); } }