void OnApplicationQuit() { List <TrackAsset> tracks = TimelineAsset.GetOutputTracks().ToList(); for (int i = tracks.Count - 1; i >= 0; i--) { TimelineAsset.DeleteTrack(tracks[i]); } }
public static IEnumerator LoadTimelineResources(TimelineAsset timelineAsset) { if (!(null == timelineAsset)) { int outputTrackCount = timelineAsset.get_outputTrackCount(); if (outputTrackCount != 0) { List <IEnumerator> loadRoutine = ListPool <IEnumerator> .Get(outputTrackCount); foreach (TrackAsset outputTrack in timelineAsset.GetOutputTracks()) { foreach (TimelineClip clip in outputTrack.GetClips()) { ITimelineResourcesProvider timelineResourcesProvider = clip.get_asset() as ITimelineResourcesProvider; if (timelineResourcesProvider != null) { loadRoutine.Add(timelineResourcesProvider.LoadResources()); } } } yield return(EnumeratorUtility.ParallelRecursiveImmediateSafeExecution(loadRoutine.ToArray())); ListPool <IEnumerator> .Release(loadRoutine); } } }
public void SampleSceneValidityPass() { string sampleScenePath = "Assets/Scenes/defaultSample.unity"; Assert.IsTrue(File.Exists(sampleScenePath)); EditorSceneManager.OpenScene(sampleScenePath); PlayableDirector[] pds = Object.FindObjectsOfType <PlayableDirector>(); foreach (PlayableDirector pd in pds) { PlayableAsset playableAsset = pd.playableAsset; if (!(playableAsset is TimelineAsset)) { continue; } TimelineAsset timelineAsset = playableAsset as TimelineAsset; foreach (TrackAsset trackAsset in timelineAsset.GetOutputTracks()) { //Make sure the Image is bound to the trackAsset Assert.IsNotNull(pd.GetGenericBinding(trackAsset)); } } }
/// <summary> /// 查找指定名称的TrackAsset /// </summary> /// <param name="_timeline">时间线</param> /// <param name="_trackAssetName">TrackAsset名称</param> /// <returns>TrackAsset</returns> public static TrackAsset FindTrackAsset(this TimelineAsset _timeline, string _trackAssetName) { TrackAsset trackAsset = null; if (_timeline != null) { IEnumerator outTracks = _timeline.GetOutputTracks().GetEnumerator(); while (outTracks.MoveNext()) { TrackAsset ta = (TrackAsset)outTracks.Current; if (ta.name.Equals(_trackAssetName)) { trackAsset = ta; break; } } } #if UNITY_EDITOR if (trackAsset == null) { Debug.LogErrorFormat("Can't find TrackAsset for【{0}】.", _trackAssetName); } #endif return(trackAsset); }
public static TrackAsset GetTrackOfType <T>(this TimelineAsset timeline) where T : TrackAsset, new() { var tracks = timeline.GetOutputTracks(); var trackOfType = tracks.FirstOrDefault(t => t is T); return(trackOfType); }
public static string ExportTimeline(TimelineAsset timeline, bool prettyPrint = false) { List <TrackAsset> tracks = new List <TrackAsset>(timeline.GetOutputTracks()); SequenceCollection sequenceCollection = new SequenceCollection(); foreach (TrackAsset track in tracks) { if (track is CrazyflieTrack) { CrazyflieTrack crazyflieTrack = track as CrazyflieTrack; SequenceTrack sequenceTrack = new SequenceTrack(); IEnumerable <IMarker> markers = crazyflieTrack.GetMarkers(); Tuple <List <ColorKeyframe>, List <Waypoint> > processedKeyframes = ProcessKeyframes(sequenceTrack, markers); List <ColorKeyframe> sortedColorKeyframes = processedKeyframes.Item1; List <Waypoint> sortedWaypoints = processedKeyframes.Item2; sequenceTrack.LedTimings = ColorExporter.Process(sortedColorKeyframes); sequenceTrack.CompressedTrajectory = TrajectoryExporter.Process(sortedWaypoints); sequenceTrack.StartPosition = GetStart(sortedWaypoints); sequenceTrack.StartColor = GetStart(sortedColorKeyframes); sequenceTrack.Name = crazyflieTrack.name; sequenceCollection.Tracks.Add(sequenceTrack); } } sequenceCollection.Length = (float)timeline.duration; sequenceCollection.DroneCount = sequenceCollection.Tracks.Count; string jsonText = JsonUtility.ToJson(sequenceCollection, prettyPrint); return(jsonText); }
public void PlayOpenBox(ActorManager attacker, ActorManager victim) { if (IsPlaying) { return; } pd.playableAsset = Instantiate(openBox); TimelineAsset timeline = (TimelineAsset)pd.playableAsset; foreach (var track in timeline.GetOutputTracks()) { Object obj = null; switch (track.name) { case "Attacker Animation": obj = attacker.actorController.anim; break; case "Attacker Script": obj = attacker; foreach (var clip in track.GetClips()) { MySuperPlayableClip myClip = clip.asset as MySuperPlayableClip; myClip.actorManager.exposedName = System.Guid.NewGuid().ToString(); pd.SetReferenceValue(myClip.actorManager.exposedName, attacker); } break; case "Box Animation": obj = victim.actorController.anim; break; case "Box Script": foreach (var clip in track.GetClips()) { MySuperPlayableClip myClip = clip.asset as MySuperPlayableClip; myClip.actorManager.exposedName = System.Guid.NewGuid().ToString(); pd.SetReferenceValue(myClip.actorManager.exposedName, victim); } break; } if (obj != null) { pd.SetGenericBinding(track, obj); } } // 强行执行一次插值 , 把值初始一次 pd.Evaluate(); pd.Play(); }
public void OnProcessScene(UnityEngine.SceneManagement.Scene scene) { string path = EditorUserBuildSettings.GetBuildLocation(EditorUserBuildSettings.activeBuildTarget); int last_slash = path.LastIndexOf('/'); string pointCloudDirectory = path.Substring(0, last_slash + 1); foreach (var gameObject in scene.GetRootGameObjects()) { PlayableDirector director = gameObject.GetComponent <PlayableDirector>(); if (director != null) { if (director.playableAsset != null) { TimelineAsset timeline = (TimelineAsset)director.playableAsset; foreach (var track in timeline.GetOutputTracks()) { foreach (var clip in track.GetClips()) { if (clip.asset.GetType() == typeof(PointCloudClip)) { uint clip_start_frame = (uint)clip.clipIn * 30; uint clip_duration_in_frames = (uint)clip.duration * 30; uint clip_end_frame = clip_start_frame + clip_duration_in_frames; string[] files = new string[0]; PointCloudClip pcc = (PointCloudClip)clip.asset; if (Directory.Exists(pcc.template.PointCloudDirectory.Substring(1))) { files = Directory.GetFiles(pcc.template.PointCloudDirectory.Substring(1)); } foreach (var file in files) { Directory.CreateDirectory(pointCloudDirectory + pcc.template.PointCloudDirectory); int last_dot_in_filename = file.LastIndexOf('.'); int last_slash_in_filename = file.LastIndexOf('\\'); int no_length = last_dot_in_filename - last_slash_in_filename - 1; uint file_no = UInt32.Parse(file.Substring(last_slash_in_filename + 1, no_length)); if (file_no >= clip_start_frame && file_no <= clip_end_frame) { if (!File.Exists(pointCloudDirectory + '/' + file)) { File.Copy(file, pointCloudDirectory + '/' + file); } } } } } } } } } }
static void UpdateTrackAsset() { foreach (var t in m_timelineAsset.GetOutputTracks()) { if (t.name.Contains("Signal")) { m_trackAsset = t as SignalTrack; break; } } }
public static void DeleteAllTracks(this TimelineAsset timeline) { var tracks = timeline.GetOutputTracks(); foreach (var t in tracks) { timeline.DeleteTrack(t); } EditorUtility.SetDirty(timeline); }
public static void DeleteTracksOfType <T>(this TimelineAsset timeline) { var tracks = timeline.GetOutputTracks(); var routeTracks = tracks.Where(t => t is T); foreach (var t in routeTracks) { timeline.DeleteTrack(t); } EditorUtility.SetDirty(timeline); }
public void Import() { EditorSceneManager.NewScene(NewSceneSetup.DefaultGameObjects); string fullPath = "Packages/com.unity.streaming-image-sequence/Tests/Data/AeConvert.jstimeline"; Assert.IsTrue(File.Exists(fullPath)); string destFolder = "TestRunner"; JstimelineImporter.ImportTimeline(fullPath, destFolder); //Check if the generated director is valid PlayableDirector[] directors = Object.FindObjectsOfType <PlayableDirector>(); Assert.AreEqual(1, directors.Length); PlayableDirector pd = directors[0]; TimelineAsset timelineAsset = pd.playableAsset as TimelineAsset; Assert.IsNotNull(timelineAsset); Assert.AreEqual(timelineAsset.outputTrackCount, 1); foreach (TrackAsset trackAsset in timelineAsset.GetOutputTracks()) { StreamingImageSequenceTrack imageSequenceTrack = trackAsset as StreamingImageSequenceTrack; Assert.IsNotNull(imageSequenceTrack); foreach (TimelineClip clip in imageSequenceTrack.GetClips()) { Assert.IsNotNull(clip.asset); StreamingImageSequencePlayableAsset playableAsset = clip.asset as StreamingImageSequencePlayableAsset; Assert.IsNotNull(playableAsset); Assert.AreEqual(10, playableAsset.GetImageFileNames().Count); } //Make sure a StreamingImageSequenceRenderer is bound to the trackAsset StreamingImageSequenceRenderer r = pd.GetGenericBinding(trackAsset) as StreamingImageSequenceRenderer; Assert.IsNotNull(r); } //Delete created assets string destAssetsFolder = "Assets/" + destFolder; string[] createdAssets = AssetDatabase.FindAssets("", new[] { destAssetsFolder }); Assert.Greater(createdAssets.Length, 0); foreach (string guid in createdAssets) { string assetPath = AssetDatabase.GUIDToAssetPath(guid); AssetDatabase.DeleteAsset(assetPath); } Directory.Delete(destAssetsFolder); }
public static void UnloadTimelineResources(TimelineAsset timelineAsset) { if (!(null == timelineAsset)) { foreach (TrackAsset outputTrack in timelineAsset.GetOutputTracks()) { foreach (TimelineClip clip in outputTrack.GetClips()) { (clip.get_asset() as ITimelineResourcesProvider)?.UnloadResources(); } } } }
static T GetOrCreateTrack <T>(TimelineAsset tl, string name) where T : TrackAsset { foreach (var t in tl.GetOutputTracks()) { if (t.name == name) { return(t as T); } } Debug.LogFormat("CreateTrack: {0}", name); return(tl.CreateTrack(typeof(T), null, name) as T); }
public void PlayTimeLine(string timelineName, ActorManager attacker, ActorManager victimer) { if (pd.playableAsset != null) { return; } if (timelineName == "FrontStab") { pd.playableAsset = Instantiate(frontstab); TimelineAsset timeline = (TimelineAsset)pd.playableAsset; foreach (var track in timeline.GetOutputTracks()) { if (track.name == "AttackAnimation") { pd.SetGenericBinding(track, attacker.ac._animator); } else if (track.name == "VicTimAnimation") { pd.SetGenericBinding(track, victimer.ac._animator); } else if (track.name == "AttackScript") { pd.SetGenericBinding(track, attacker); foreach (var clip in track.GetClips()) { MyPlayableBehaviousClip myclip = (MyPlayableBehaviousClip)clip.asset; MyPlayableBehaviousBehaviour mybehav = myclip.template; mybehav.MyFloat = 777; pd.SetReferenceValue(myclip.MyActorManager.exposedName, attacker); } } else if (track.name == "VicTimScript") { pd.SetGenericBinding(track, victimer); foreach (var clip in track.GetClips()) { MyPlayableBehaviousClip myclip = (MyPlayableBehaviousClip)clip.asset; MyPlayableBehaviousBehaviour mybehav = myclip.template; mybehav.MyFloat = 666; pd.SetReferenceValue(myclip.MyActorManager.exposedName, victimer); } } } pd.Play(); } }
public static TrackAsset GetOrAddTrackOfType <T>(this TimelineAsset timeline, string nameOfNewTrack) where T : TrackAsset, new() { var tracks = timeline.GetOutputTracks(); var trackOfType = tracks.FirstOrDefault(t => t is T); if (trackOfType != null) { return(trackOfType); } trackOfType = timeline.CreateTrack <T>(null, nameOfNewTrack); EditorUtility.SetDirty(timeline); return(trackOfType); }
public void PlayIngame() { AudioTrack audioTrack; //Timeline playable graph asset needs to be rebuilt to change contributing tracks timelineAsset = (TimelineAsset)ingameTimeline.playableAsset; Reset(); //pick ingame atmos track index: int atmosIndex = pickRandomItem(ingameAtmosTrackIndices); //pick ingame lead track index: int leadIndex = pickRandomItem(ingameLeadTrackIndices); //pick ingame rhythm track index: int rhythmIndex = pickRandomItem(ingameRhythmTrackIndices); //iterate over tracks and set output to playing or muted int count = 0; foreach (var track in timelineAsset.GetOutputTracks()) { audioTrack = track as AudioTrack; if (audioTrack == null) { //Debug.Log("Null track at count:" + count.ToString()); continue; } else { //Debug.Log("Audio track " + count.ToString() + " clip:" + audioTrack.name); } if (count == atmosIndex || count == leadIndex || count == rhythmIndex) { ingameTimeline.SetGenericBinding(audioTrack, playingOutput); } else { ingameTimeline.SetGenericBinding(audioTrack, mutedOutput); } count++; } ingameTimeline.time = 0.0f; ingameTimeline.RebuildGraph(); ingameTimeline.Play(); }
/// <summary> /// 获得指定的TrackAsset组 /// </summary> /// <typeparam name="T">TrackAsset类型</typeparam> /// <param name="_timeline">时间线</param> /// <returns>TrackAsset组</returns> public static List <T> FindTrackAsset <T>(this TimelineAsset _timeline) where T : TrackAsset { List <T> result = new List <T>(); IEnumerator <TrackAsset> node = _timeline.GetOutputTracks().GetEnumerator(); while (node.MoveNext()) { if (node.Current != null && node.Current is T) { result.Add((T)node.Current); } } ; return(result); }
public void GenerateDumpData(TimelineAsset timelineAsset) { CreateAt = DateTime.Now.ToString(DateTimeFormat); trackDumpList = new List <TimelineTrackDump>(); foreach (var track in timelineAsset.GetOutputTracks()) { var trackDump = new TimelineTrackDump(); //Todo 親子関係を考慮したデータ作成 trackDump.parentIndex = -1; trackDump.TrackName = track.name; trackDump.SetTrackType(track); trackDump.clipDumpList = track.GetClips().Select(x => new TimelineClipDump(x)).ToList(); trackDumpList.Add(trackDump); } }
public static TrackAsset GetTrackAsset(this TimelineAsset self, string trackName) { foreach (var output_track in self.GetOutputTracks()) { if (output_track.name.Equals(trackName)) { return(output_track); } TrackAsset successFoundTrackAsset = GetSubTrackAsset(output_track, trackName); if (successFoundTrackAsset != null) { return(successFoundTrackAsset); } } return(null); }
public static void GatherTimelineResourcesLoadRoutines(TimelineAsset timelineAsset, List <IEnumerator> list) { if (!(null == timelineAsset)) { foreach (TrackAsset outputTrack in timelineAsset.GetOutputTracks()) { foreach (TimelineClip clip in outputTrack.GetClips()) { ITimelineResourcesProvider timelineResourcesProvider = clip.get_asset() as ITimelineResourcesProvider; if (timelineResourcesProvider != null) { IEnumerator item = timelineResourcesProvider.LoadResources(); list.Add(item); } } } } }
public override void OnPlayableCreate(Playable playable) { m_Director = (playable.GetGraph().GetResolver() as PlayableDirector); TimelineAsset timelineAsset = m_Director.playableAsset as TimelineAsset; var trackAssets = timelineAsset.GetOutputTracks(); foreach (var track in trackAssets) { if (track is DialogueTrack) { m_TrackAsset = track; var binding = m_Director.GetGenericBinding(track) as DialogueCanvasController; m_DialogueCanvas = binding; break; } } }
internal void PullLever(ActorManager attack, ActorManager victim) { pd.playableAsset = Instantiate(pullLever); TimelineAsset timeline = (TimelineAsset)pd.playableAsset; foreach (var track in timeline.GetOutputTracks()) { if (track.name == "Player Script") { pd.SetGenericBinding(track, attack); foreach (var clip in track.GetClips()) { AmPlayableClip amClip = (AmPlayableClip)clip.asset; AmPlayableBehaviour amBehaviour = amClip.template; amClip.am.exposedName = System.Guid.NewGuid().ToString(); pd.SetReferenceValue(amClip.am.exposedName, attack); } } else if (track.name == "Lever Script") { pd.SetGenericBinding(track, victim); foreach (var clip in track.GetClips()) { AmPlayableClip amClip = (AmPlayableClip)clip.asset; AmPlayableBehaviour amBehaviour = amClip.template; amClip.am.exposedName = System.Guid.NewGuid().ToString(); pd.SetReferenceValue(amClip.am.exposedName, victim); } } else if (track.name == "Player Animation") { pd.SetGenericBinding(track, attack.ac.anim); } else if (track.name == "Lever Animation") { pd.SetGenericBinding(track, victim.ac.anim); } } pd.Evaluate(); pd.Play(); }
public void MuteTracks(int numAssigmentsCompleted) { PlayableDirector director = GetComponent <PlayableDirector>(); TimelineAsset timeline = director.playableAsset as TimelineAsset; double currentTime = director.time; int i = 1; List <string> trackNamesToMute = new List <string>(numAssigmentsCompleted == 4 ? trackNamesToMuteGood : trackNamesToMuteBad); foreach (string trackName in trackNamesToMuteFlags) { if (numAssigmentsCompleted < i) { trackNamesToMute.Add(trackName); } i++; } i = 0; foreach (TrackAsset track in timeline.GetOutputTracks()) { bool mute = trackNamesToMute.IndexOf(track.name) >= 0; if (track.muted != mute) { track.muted = mute; Debug.Log($"{this} {(mute ? "muting" : "unmuting")} track {track}", this); if (track is ActivationTrack) { GameObject binding = director.GetGenericBinding(track) as GameObject; if (binding) { if (mute && binding.activeSelf) // by muting this track we also want to deactivate the thing this track was activating { Debug.Log($"{this} muting track {track}: deactivating {binding}", this); binding.SetActive(false); } } } } i++; } director.RebuildGraph(); director.time = currentTime; }
protected TimelineClip FindTimelineClip(SpineAnimationStateClip targetClip) { string[] guids = AssetDatabase.FindAssets("t:TimelineAsset"); foreach (string guid in guids) { TimelineAsset timeline = (TimelineAsset)AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(guid), typeof(TimelineAsset)); foreach (var track in timeline.GetOutputTracks()) { foreach (var clip in track.GetClips()) { if (clip.asset.GetType() == typeof(SpineAnimationStateClip) && object.ReferenceEquals(clip.asset, targetClip)) { return(clip); } } } } return(null); }
public static TimelineAsset CloneTrackAsset(this TimelineAsset self, string trackName) { string path = self.GetAssetPath(); TimelineAsset clone = ScriptableObject.CreateInstance <TimelineAsset>(); foreach (var outputTrack in self.GetOutputTracks()) { if (outputTrack.name.Equals(trackName)) { // TrackAsset cloneTrackAsset= clone.CreateTrack(outputTrack.GetType(), null, outputTrack.name); // string animClipName = "animClip"; // cloneTrackAsset.SetPropertyValue(animClipName, outputTrack.GetPropertyValue<AnimationClip>(animClipName)); // // foreach (var clip in outputTrack.GetClips()) // { // TimelineClip cloneClip= cloneTrackAsset.CreateDefaultClip(); // foreach (var fieldInfo in clone.GetType().GetFields()) // { // cloneClip.SetFieldValue(fieldInfo.Name, clip.GetFieldValue(fieldInfo.Name)); // cloneClip.parentTrack = cloneTrackAsset; // } // } TrackAsset cloneTrackAsset = clone.CreateTrack(outputTrack.GetType(), null, outputTrack.name); foreach (var info in outputTrack.GetType().GetProperties()) { if (info.GetSetMethod(true) != null || info.GetSetMethod() != null) { cloneTrackAsset.SetPropertyValue(info.Name, outputTrack.GetPropertyValue(info.Name)); } } string animClipName = StringConst.String_animClip; cloneTrackAsset.SetPropertyValue(animClipName, outputTrack.GetPropertyValue <AnimationClip>(animClipName)); } } return(clone); }
void SetupBindings <TComponent, TTrack>(TComponent component) where TComponent : Component where TTrack : UnityEngine.Object { if (component == null) { return; } foreach (var state in StateMachine.StateController.States) { TimelineAsset timeline = state.Data.Timeline; if (timeline == null) { continue; } foreach (var track in timeline.GetOutputTracks().OfType <TTrack>()) { Director.SetGenericBinding(track, component.gameObject); } } }
public override void Enter() { base.Enter(); _player = GameObject.FindGameObjectWithTag("Player").transform; _timer = 5f; _rotationalSpeed = 5f; _flipped = false; _flipPosition = Position(); AnimationClip[] clips = _animator.runtimeAnimatorController.animationClips; foreach (AnimationClip clip in clips) { if (clip.name.Contains("backflip")) { _flippedTime = clip.length; } } // for triggering trash talk dialogue if (_sm.playableDirector.state == PlayState.Playing) { return; } _sm.playableDirector.playableAsset = _sm.trashTalkDialogues[Random.Range(0, _sm.trashTalkDialogues.Length)]; TimelineAsset timelineAsset = _sm.playableDirector.playableAsset as TimelineAsset; foreach (var track in timelineAsset.GetOutputTracks()) { AudioTrack animTrack = track as AudioTrack; if (animTrack == null) { continue; } _sm.playableDirector.SetGenericBinding(animTrack, _sm.enemyAudioSource); break; } _sm.playableDirector.Play(); }
public void Play(EventType eventType, IActorManager player, IActorManager opponent) { pd.playableAsset = GetTimelineAsset(eventType); TimelineAsset timeline = (TimelineAsset)pd.playableAsset; foreach (var track in timeline.GetOutputTracks()) { if (track.name == "Player Animation") { pd.SetGenericBinding(track, player.GetAnimator()); } else if (track.name == "Opponent Animation") { pd.SetGenericBinding(track, opponent.GetAnimator()); } else if (track.name == "Player Script") { pd.SetGenericBinding(track, player); foreach (var clip in track.GetClips()) { LockAnimatorClip lockClip = (LockAnimatorClip)clip.asset; lockClip.am.exposedName = System.Guid.NewGuid().ToString(); pd.SetReferenceValue(lockClip.am.exposedName, player); } } else if (track.name == "Opponent Script") { pd.SetGenericBinding(track, opponent); foreach (var clip in track.GetClips()) { LockAnimatorClip lockClip = (LockAnimatorClip)clip.asset; lockClip.am.exposedName = System.Guid.NewGuid().ToString(); pd.SetReferenceValue(lockClip.am.exposedName, opponent); } } } pd.Evaluate(); pd.Play(); }
void OnValidate() { if (timeline != null) { List <double> times = new List <double>(); foreach (var track in timeline.GetOutputTracks()) { var markers = track.GetMarkers(); foreach (var marker in markers) { if (marker is Script_TimelineControlMarker) { times.Add(marker.time); } } } // Sort from smallest to largest values. times.Sort((a, b) => a.CompareTo(b)); pauseTimes = times; } }