Beispiel #1
0
 public static bool Delete(TimelineAsset timeline, TimelineClip clip)
 {
     return(timeline.DeleteClip(clip));
 }
 public Clipboard()
 {
     rootTimeline = CreateTimeline();
 }
Beispiel #3
0
        public DragAndDropVisualMode HandleObjectDrop(TreeViewItem parentItem, TreeViewItem targetItem, bool perform, TreeViewDragging.DropPosition dropPos)
        {
            DragAndDropVisualMode result;

            if (!perform)
            {
                List <Object> list = new List <Object>();
                if (DragAndDrop.get_objectReferences().Any <Object>())
                {
                    list.AddRange(DragAndDrop.get_objectReferences());
                    using (List <Object> .Enumerator enumerator = list.GetEnumerator())
                    {
                        while (enumerator.MoveNext())
                        {
                            Object      o = enumerator.Current;
                            TrackType[] trackTypeHandle = TimelineHelpers.GetTrackTypeHandle(o.GetType());
                            if (!trackTypeHandle.Any <TrackType>() || trackTypeHandle.Any((TrackType t) => !TimelineDragging.ValidateObjectDrop(o)))
                            {
                                result = 0;
                                return(result);
                            }
                        }
                    }
                    result = 1;
                }
                else if (DragAndDrop.get_paths().Any <string>())
                {
                    TimelineGroupGUI timelineGroupGUI = targetItem as TimelineGroupGUI;
                    if (timelineGroupGUI == null)
                    {
                        result = 1;
                    }
                    else if (timelineGroupGUI.track == null)
                    {
                        result = 0;
                    }
                    else
                    {
                        TrackType tt    = TimelineHelpers.TrackTypeFromType(timelineGroupGUI.track.GetType());
                        string[]  paths = DragAndDrop.get_paths();
                        for (int i = 0; i < paths.Length; i++)
                        {
                            string text = paths[i];
                            list.AddRange(AssetDatabase.LoadAllAssetsAtPath(text));
                        }
                        bool flag = (from o in list
                                     where o != null
                                     select o).Any((Object o) => TimelineHelpers.IsTypeSupportedByTrack(tt, o.GetType()));
                        result = ((!flag) ? 0 : 1);
                    }
                }
                else
                {
                    result = 0;
                }
            }
            else
            {
                List <Object> list2 = new List <Object>();
                list2.AddRange(DragAndDrop.get_objectReferences());
                TrackAsset       trackAsset        = null;
                TimelineGroupGUI timelineGroupGUI2 = (TimelineGroupGUI)targetItem;
                if (targetItem != null && timelineGroupGUI2.track != null)
                {
                    trackAsset = timelineGroupGUI2.track;
                }
                Vector2 mousePosition = Event.get_current().get_mousePosition();
                foreach (Object current in list2)
                {
                    if (!(current == null))
                    {
                        if (current is TimelineAsset)
                        {
                            if (TimelineHelpers.IsCircularRef(this.m_Timeline, current as TimelineAsset))
                            {
                                Debug.LogError("Cannot add " + current.get_name() + " to the sequence because it would cause a circular reference");
                                continue;
                            }
                            TimelineAsset timelineAsset = current as TimelineAsset;
                            foreach (TrackAsset current2 in timelineAsset.tracks)
                            {
                                if (current2.mediaType == TimelineAsset.MediaType.Group)
                                {
                                    this.m_Timeline.AddTrackInternal(current2);
                                }
                            }
                            this.m_Window.state.Refresh();
                            EditorUtility.SetDirty(this.m_Timeline);
                        }
                        else if (current is TrackAsset)
                        {
                            this.m_Timeline.AddTrackInternal((TrackAsset)current);
                        }
                        else
                        {
                            TrackType   trackType        = null;
                            TrackAsset  trackAsset2      = null;
                            TrackType[] trackTypeHandle2 = TimelineHelpers.GetTrackTypeHandle(current.GetType());
                            if (trackAsset != null)
                            {
                                TrackType[] array = trackTypeHandle2;
                                for (int j = 0; j < array.Length; j++)
                                {
                                    TrackType trackType2 = array[j];
                                    if (trackAsset.GetType() == trackType2.trackType)
                                    {
                                        trackType = trackType2;
                                        break;
                                    }
                                }
                            }
                            if (trackType == null)
                            {
                                if (trackTypeHandle2.Length == 1)
                                {
                                    trackType = trackTypeHandle2[0];
                                }
                                else if (trackTypeHandle2.Length > 1)
                                {
                                    trackType = this.ResolveTypeAmbiguity(trackTypeHandle2);
                                }
                            }
                            if (trackType == null)
                            {
                                continue;
                            }
                            if (!TimelineDragging.ValidateObjectDrop(current))
                            {
                                continue;
                            }
                            if (trackAsset != null && trackAsset.GetType() == trackType.trackType)
                            {
                                trackAsset2 = trackAsset;
                            }
                            if (trackAsset2 == null)
                            {
                                trackAsset2 = this.m_Window.AddTrack(trackType.trackType, null, string.Empty);
                            }
                            if (trackAsset2 == null)
                            {
                                result = 0;
                                return(result);
                            }
                            Object @object = TimelineDragging.TransformObjectBeingDroppedAccordingToTrackRules(trackAsset2, current);
                            if (@object == null)
                            {
                                continue;
                            }
                            TimelineUndo.PushUndo(trackAsset2, "Create Clip");
                            AnimationTrack animationTrack = trackAsset2 as AnimationTrack;
                            if (animationTrack != null)
                            {
                                animationTrack.ConvertToClipMode();
                            }
                            TimelineClip timelineClip = TimelineHelpers.CreateClipOnTrack(@object, trackAsset2, this.m_Window.state, mousePosition);
                            if (timelineClip != null)
                            {
                                float num = this.m_Window.state.TimeToPixel(1.0) - this.m_Window.state.TimeToPixel(0.0);
                                mousePosition.x += (float)timelineClip.duration * num;
                                if (timelineClip.asset is ScriptableObject)
                                {
                                    string assetPath = AssetDatabase.GetAssetPath(timelineClip.asset);
                                    if (assetPath.Length == 0)
                                    {
                                        TimelineCreateUtilities.SaveAssetIntoObject(timelineClip.asset, trackAsset2);
                                    }
                                }
                                TimelineDragging.FrameClips(this.m_Window.state);
                                trackAsset2.SetCollapsed(false);
                            }
                        }
                        this.m_Window.state.Refresh();
                        EditorUtility.SetDirty(this.m_Timeline);
                    }
                }
                result = 1;
            }
            return(result);
        }
 static bool HandleTrackAndItemCreation(IEnumerable<UnityEngine.Object> objectsBeingDropped, double candidateTime, TypeResolver typeResolver, TimelineAsset timeline, TrackAsset parent, IEnumerable<Type> validTrackTypes, TrackAsset insertBefore = null)
 {
     Action<Type> onResolved = t =>
     {
         var newTrack = TimelineHelpers.CreateTrack(timeline, t, parent, string.Empty);
         if (insertBefore != null)
         {
             if (parent != null)
                 parent.MoveLastTrackBefore(insertBefore);
             else
                 timeline.MoveLastTrackBefore(insertBefore);
         }
         HandleItemCreation(objectsBeingDropped, newTrack, candidateTime, typeResolver, validTrackTypes.Count() == 1); // menu is popped if ambiguous clip choice and unambiguous track choice
     };
     return typeResolver(validTrackTypes, t => onResolved(t), k_SelectTrackWithClip); // Did it create a track
 }
        public static DragAndDropVisualMode HandleClipPanePlayableAssetDragAndDrop(IEnumerable<IPlayableAsset> assetsBeingDropped, TrackAsset targetTrack, bool perform, TimelineAsset timeline, TrackAsset parent, PlayableDirector director, double candidateTime, TypeResolver typeResolver)
        {
            // get the list of supported track types
            var assetTypes = assetsBeingDropped.Select(x => x.GetType()).Distinct();
            IEnumerable<Type> supportedTypes = null;
            if (targetTrack == null)
            {
                supportedTypes = TypeUtility.AllTrackTypes().Where(t => TypeUtility.GetPlayableAssetsHandledByTrack(t).Intersect(assetTypes).Any()).ToList();
            }
            else
            {
                supportedTypes = Enumerable.Empty<Type>();
                var trackAssetTypes = TypeUtility.GetPlayableAssetsHandledByTrack(targetTrack.GetType());
                if (trackAssetTypes.Intersect(assetTypes).Any())
                    supportedTypes = new[] {targetTrack.GetType()};
            }

            if (!supportedTypes.Any())
                return DragAndDropVisualMode.Rejected;

            if (perform)
            {
                Action<Type> onResolved = (t) =>
                {
                    if (targetTrack == null)
                        targetTrack = TimelineHelpers.CreateTrack(timeline, t, parent, string.Empty);

                    var clipTypes = TypeUtility.GetPlayableAssetsHandledByTrack(targetTrack.GetType());
                    foreach (var asset in assetsBeingDropped)
                    {
                        if (clipTypes.Contains(asset.GetType()))
                            TimelineHelpers.CreateClipOnTrackFromPlayableAsset(asset, targetTrack, candidateTime);
                    }
                };

                typeResolver(supportedTypes, onResolved, k_SelectTrackWithClip);
            }


            return DragAndDropVisualMode.Copy;
        }
Beispiel #6
0
        static void ActionButtonGUI(UnityEngine.Object target)
        {
            if (target == null)
            {
                EditorGUI.BeginDisabledGroup(true);
                GUILayout.Button("(No Object)");
                EditorGUI.EndDisabledGroup();
                return;
            }


            Type t = target.GetType();

            if (t == typeof(GameObject))
            {
                GameObject go = target as GameObject;

                if (GUILayout.Button("  Select  ", DiscoverWindow.Styles.buttonLeft))
                {
                    Selection.activeObject = go;
                }

                if (PrefabUtility.GetPrefabAssetType(go) == PrefabAssetType.NotAPrefab)
                {
                    if (GUILayout.Button("  Go to  ", DiscoverWindow.Styles.buttonRight))
                    {
                        Selection.activeObject = go;
                        SceneView.lastActiveSceneView.FrameSelected();
                    }
                }
                else
                {
                    if (GUILayout.Button("  Open  ", DiscoverWindow.Styles.buttonRight))
                    {
                        AssetDatabase.OpenAsset(go);
                    }
                }
            }
            else if (t == typeof(Discover))
            {
                if (GUILayout.Button("Discover"))
                {
                    var discover = target as Discover;
                    Selection.activeGameObject = discover.gameObject;
                    DiscoverWindow.SelectDiscover(discover);
                }
            }
            else if (t == typeof(VisualEffectAsset))
            {
                if (GUILayout.Button("Open VFX Graph"))
                {
                    VisualEffectAsset graph = target as VisualEffectAsset;
                    AssetDatabase.OpenAsset(graph);
                }
            }
            else if (t == typeof(Animation))
            {
                if (GUILayout.Button("Open Animation"))
                {
                    Animation animation = target as Animation;
                    AssetDatabase.OpenAsset(animation);
                }
            }
            else if (t == typeof(TimelineAsset))
            {
                if (GUILayout.Button("Open Timeline"))
                {
                    TimelineAsset timeline = target as TimelineAsset;
                    AssetDatabase.OpenAsset(timeline);
                }
            }
            else if (t == typeof(PlayableDirector))
            {
                if (GUILayout.Button("Open Director"))
                {
                    PlayableDirector director = target as PlayableDirector;

                    AssetDatabase.OpenAsset(director.playableAsset);
                    Selection.activeObject = director.gameObject;
                }
            }
            else if (t == typeof(Shader))
            {
                if (GUILayout.Button("Open Shader"))
                {
                    Shader shader = target as Shader;
                    AssetDatabase.OpenAsset(shader);
                }
            }
            else
            {
                if (GUILayout.Button("Select"))
                {
                    Selection.activeObject = target;
                }
            }
        }
        public static DragAndDropVisualMode HandleHierarchyPaneDragAndDrop(IEnumerable<UnityObject> objectsBeingDropped, TrackAsset targetTrack, bool perform, TimelineAsset timeline, PlayableDirector director, TypeResolver typeResolver, TrackAsset insertBefore = null)
        {
            if (timeline == null)
                return DragAndDropVisualMode.Rejected;

            // if we are over a target track, defer to track binding system (implemented in TrackGUIs), unless we are a groupTrack
            if (targetTrack != null && (targetTrack as GroupTrack) == null)
                return DragAndDropVisualMode.None;

            if (targetTrack != null && targetTrack.lockedInHierarchy)
                return DragAndDropVisualMode.Rejected;

            var tracksWithBinding = objectsBeingDropped.SelectMany(TypeUtility.GetTracksCreatableFromObject).Distinct();
            if (!tracksWithBinding.Any())
                return DragAndDropVisualMode.None;

            if (perform)
            {
                System.Action<Type> onResolve = trackType =>
                {
                    foreach (var obj in objectsBeingDropped)
                    {
                        if (!obj.IsPrefab() && TypeUtility.IsTrackCreatableFromObject(obj, trackType))
                        {
                            var newTrack = TimelineHelpers.CreateTrack(timeline, trackType, targetTrack, string.Empty);
                            if (insertBefore != null)
                            {
                                if (targetTrack != null)
                                    targetTrack.MoveLastTrackBefore(insertBefore);
                                else
                                    timeline.MoveLastTrackBefore(insertBefore);
                            }

                            TimelineHelpers.Bind(newTrack, obj, director);
                        }
                    }
                    TimelineEditor.Refresh(RefreshReason.ContentsAddedOrRemoved);
                };
                typeResolver(tracksWithBinding, onResolve, k_SelectTrackWithBinding);
            }

            return DragAndDropVisualMode.Copy;
        }
 internal static IEnumerable <TrackAsset> RemoveTimelineMarkerTrackFromList(this IEnumerable <TrackAsset> tracks, TimelineAsset asset)
 {
     return(tracks.Where(t => t != asset.markerTrack));
 }
 internal static bool ContainsTimelineMarkerTrack(this IEnumerable <TrackAsset> tracks, TimelineAsset asset)
 {
     return(tracks.Contains(asset.markerTrack));
 }
 public void PlayCutscene(TimelineAsset timeline)
 {
     director.Play(timeline);
     Invoke(nameof(PlayNext), (float)timeline.duration);
 }
Beispiel #11
0
    public void PlayFrontStab(string timelineName, ActorManager attcker, ActorManager victim)
    {
        if (timelineName == "frontStab")
        {
            pd.playableAsset = Instantiate(frontStab);

            TimelineAsset timeline = (TimelineAsset)pd.playableAsset;

            foreach (var track in timeline.GetOutputTracks())
            {
                if (track.name == "Attacker Scipt")
                {
                    pd.SetGenericBinding(track, attacker);
                    foreach (var clip in track.GetClips())
                    {
                        MyPlayableClip      myclip  = (MyPlayableClip)clip.asset;
                        MyPlayableBehaviour mybehav = myclip.template;
                        myclip.am.exposedName = System.Guid.NewGuid().ToString();
                        pd.SetReferenceValue(myclip.am.exposedName, attacker);
                    }
                }
                else if (track.name == "Victim Scipt")
                {
                    pd.SetGenericBinding(track, victim);
                    foreach (var clip in track.GetClips())
                    {
                        MyPlayableClip      myclip  = (MyPlayableClip)clip.asset;
                        MyPlayableBehaviour mybehav = myclip.template;
                        myclip.am.exposedName = System.Guid.NewGuid().ToString();
                        pd.SetReferenceValue(myclip.am.exposedName, victim);
                    }
                }
                else if (track.name == "Attacker Animator")
                {
                    pd.SetGenericBinding(track, attacker.ac.anim);
                }
                else if (track.name == "Victim Animator")
                {
                    pd.SetGenericBinding(track, victim.ac.anim);
                }
            }
            pd.Evaluate();
            pd.Play();
        }

        else if (timelineName == "openBox")
        {
            pd.playableAsset = Instantiate(openBox);

            TimelineAsset timeline = (TimelineAsset)pd.playableAsset;

            foreach (var track in timeline.GetOutputTracks())
            {
                if (track.name == "Player Scipt")
                {
                    pd.SetGenericBinding(track, attacker);
                    foreach (var clip in track.GetClips())
                    {
                        MyPlayableClip      myclip  = (MyPlayableClip)clip.asset;
                        MyPlayableBehaviour mybehav = myclip.template;
                        myclip.am.exposedName = System.Guid.NewGuid().ToString();
                        pd.SetReferenceValue(myclip.am.exposedName, attacker);
                    }
                }
                else if (track.name == "Box Scipt")
                {
                    pd.SetGenericBinding(track, victim);
                    foreach (var clip in track.GetClips())
                    {
                        MyPlayableClip      myclip  = (MyPlayableClip)clip.asset;
                        MyPlayableBehaviour mybehav = myclip.template;
                        myclip.am.exposedName = System.Guid.NewGuid().ToString();
                        pd.SetReferenceValue(myclip.am.exposedName, victim);
                    }
                }
                else if (track.name == "Player Animation")
                {
                    pd.SetGenericBinding(track, attacker.ac.anim);
                }
                else if (track.name == "Box Animation")
                {
                    pd.SetGenericBinding(track, victim.ac.anim);
                }
            }
            pd.Evaluate();
            pd.Play();
        }

        else if (timelineName == "leverUp")
        {
            pd.playableAsset = Instantiate(leverUp);

            TimelineAsset timeline = (TimelineAsset)pd.playableAsset;

            foreach (var track in timeline.GetOutputTracks())
            {
                if (track.name == "Player Scipt")
                {
                    pd.SetGenericBinding(track, attacker);
                    foreach (var clip in track.GetClips())
                    {
                        MyPlayableClip      myclip  = (MyPlayableClip)clip.asset;
                        MyPlayableBehaviour mybehav = myclip.template;
                        myclip.am.exposedName = System.Guid.NewGuid().ToString();
                        pd.SetReferenceValue(myclip.am.exposedName, attacker);
                    }
                }
                else if (track.name == "Lever Scipt")
                {
                    pd.SetGenericBinding(track, victim);
                    foreach (var clip in track.GetClips())
                    {
                        MyPlayableClip      myclip  = (MyPlayableClip)clip.asset;
                        MyPlayableBehaviour mybehav = myclip.template;
                        myclip.am.exposedName = System.Guid.NewGuid().ToString();
                        pd.SetReferenceValue(myclip.am.exposedName, victim);
                    }
                }
                else if (track.name == "Player Animation")
                {
                    pd.SetGenericBinding(track, attacker.ac.anim);
                }
                else if (track.name == "Lever Animation")
                {
                    pd.SetGenericBinding(track, victim.ac.anim);
                }
            }
            pd.Evaluate();
            pd.Play();
        }
    }
Beispiel #12
0
        private void OnGUI()
        {
            GUILayout.BeginVertical();
            //
            GUILayout.BeginHorizontal();
            //区域B 展示区域
            int  x         = 0;
            int  y         = 0;
            int  size      = 60;
            int  padding   = 10;
            int  maxCount  = 600 / (size + padding);
            int  count     = 0;
            Rect rect      = Rect.zero;
            Rect labelRect = Rect.zero;

            GUILayout.BeginArea(new Rect(padding, padding, 600, 600));
            GUILayout.BeginScrollView(new Vector2(300, 0),
                                      GUILayout.Width(600), GUILayout.ExpandHeight(true));

            var nodeInfos = BGMSwitchHelper.config.topics;

            if (nodeInfos != null)
            {
                foreach (var nodeInfo in nodeInfos)
                {
                    if (nodeInfo == null)
                    {
                        return;
                    }
                    rect = new Rect(x, y, size, size);
                    string topicname = nodeInfo.topicname;
                    if (GUI.Button(rect, topicname))
                    {
                        System.Random random = new System.Random();
                        int           rat    = random.Next(nodeInfo.items.Count);
                        Debug.Log("rat: " + rat);
                        string    id        = nodeInfo.items[rat].id;
                        AudioClip audioclip = Resources.Load <AudioClip>(id);

                        if (audioclip == null)
                        {
                            Debug.LogError("audioclip is null. path: " + id);
                        }
                        else
                        {
                            TimelineAsset     timelineAsset = BGMSwitchHelper.bgmPlayableDirector.playableAsset as TimelineAsset;
                            List <TrackAsset> lstTrackAsset = timelineAsset.GetRootTracks().ToList <TrackAsset>();
                            for (int i = 0; i < lstTrackAsset.Count; i++)
                            {
                                TrackAsset trackAsset = timelineAsset.GetRootTrack(i);
                                timelineAsset.DeleteTrack(trackAsset);
                            }
                            var track = timelineAsset.CreateTrack <AudioTrack>(null, "bgmTrack");
                            BGMSwitchHelper.bgmPlayableDirector.SetGenericBinding(track, BGMSwitchHelper.BMGMgrGo);


                            var clip = track.CreateClip(audioclip);
                            clip.displayName = audioclip.name;
                            AudioPlayableAsset clipasset = clip.asset as AudioPlayableAsset;
                            clipasset.loop = true;
                            AssetDatabase.SaveAssets();
                        }

                        Close();
                    }

                    x += size + padding;
                    count++;
                    if ((count + 1) % maxCount == 0)
                    {
                        x  = 0;
                        y += size + padding;
                    }
                }
            }

            GUILayout.EndScrollView();
            GUILayout.EndArea();
            GUILayout.EndHorizontal();

//             if (GUILayout.Button("Generate"))
//             {
//
//             }


            GUILayout.EndVertical();
        }
Beispiel #13
0
 public static TimelineClip GetClipForAsset(TimelineAsset timelineAsset, UnityEngine.Object playableAsset)
 {
     return(timelineAsset.GetRootTracks()
            .SelectMany(track => GetClipsInTrack(track, clip => clip.asset == playableAsset))
            .FirstOrDefault());
 }
Beispiel #14
0
 public void PlayCinematic(TimelineAsset t_timeline_to_play)
 {
     p_playabledirector.Play(t_timeline_to_play);
     Script_Game_Manager.Instance.SetTimePause();
     Script_Game_Manager.Instance.EnterInACinematic();
 }
        public void Execute()
        {
            executeTimeline = (TimelineAsset)ScriptableObject.CreateInstance("TimelineAsset");
            steerTrack      = executeTimeline.CreateTrack <PlayableTrack>(null, "steerTrack");
            lerpTrack       = executeTimeline.CreateTrack <PlayableTrack>(null, "lerpTrack");
            attachTrack     = executeTimeline.CreateTrack <PlayableTrack>(null, "attachTrack");
            ctrack          = executeTimeline.CreateTrack <ControlTrack>(null, "control_track");

            execute = false;
            var    planStringList  = planner.PlanSteps;
            double startTime       = 0;
            double accumulatedTime = 0;

            char[] charsToTrim = { '(', ')' };
            var    CIList      = new List <ClipInfo>();

            foreach (var step in planStringList)
            {
                var stepPart = step.Trim(charsToTrim).Split('-').First();
                if (stepPart.EndsWith(")"))
                {
                    stepPart = stepPart.TrimEnd(charsToTrim);
                }
                if (stepPart.Equals("initial") || stepPart.Equals("goal"))
                {
                    continue;
                }

                var stepItems = stepPart.Split(' ');

                // Find Action
                var goWithAction = GameObject.Find(stepItems.First());
                var action       = goWithAction.GetComponent <UnityActionOperator>();
                var terms        = new List <GameObject>();
                foreach (var term in stepItems.Skip(1))
                {
                    terms.Add(GameObject.Find(term));
                }

                // Follow Unity Instructions
                var instructions = action.UnityInstructions;


                accumulatedTime = 0;
                foreach (var instruction in instructions)
                {
                    var thisCI = ProcessInstruction(goWithAction, instruction, terms, startTime + accumulatedTime, 1);
                    CIList.Add(thisCI);
                    accumulatedTime += 1;
                }
                startTime = startTime + accumulatedTime;
            }
            //CIList[CIList.Count() - 1].duration = 1000;
            //thisCI.duration = 1000;
            //var CI = new ClipInfo(playableDirector, startTime, 1000, "filler");
            //var ctrackClip = ctrack.CreateDefaultClip();
            //AnimateClip(ctrackClip, new GameObject(), CI);

            playableDirector.playableAsset = executeTimeline;
            playableDirector.Play(executeTimeline);
        }
Beispiel #16
0
        internal static TrackAsset Duplicate(this TrackAsset track, PlayableDirector director,
                                             TimelineAsset destinationTimeline = null)
        {
            if (track == null)
            {
                return(null);
            }

            // if the destination is us, clear to avoid bad parenting (case 919421)
            if (destinationTimeline == track.timelineAsset)
            {
                destinationTimeline = null;
            }

            var timelineParent = track.parent as TimelineAsset;
            var trackParent    = track.parent as TrackAsset;

            if (timelineParent == null && trackParent == null)
            {
                Debug.LogWarning("Cannot duplicate track because it is not parented to known type");
                return(null);
            }

            // Determine who the final parent is. If we are pasting into another track, it's always the timeline.
            //  Otherwise it's the original parent
            PlayableAsset finalParent = destinationTimeline != null ? destinationTimeline : track.parent;

            // grab the list of tracks to generate a name from (923360) to get the list of names
            // no need to do this part recursively
            var finalTrackParent   = finalParent as TrackAsset;
            var finalTimelineAsset = finalParent as TimelineAsset;
            var otherTracks        = (finalTimelineAsset != null) ? finalTimelineAsset.trackObjects : finalTrackParent.subTracksObjects;

            // Important to create the new objects before pushing the original undo, or redo breaks the
            //  sequence
            var newTrack = TimelineHelpers.Clone(finalParent, track, director, finalParent);

            newTrack.name = TimelineCreateUtilities.GenerateUniqueActorName(otherTracks, newTrack.name);

            RecursiveSubtrackClone(track, newTrack, director, finalParent);
            TimelineUndo.RegisterCreatedObjectUndo(newTrack, "Duplicate");
            TimelineCreateUtilities.SaveAssetIntoObject(newTrack, finalParent);
            TimelineUndo.PushUndo(finalParent, "Duplicate");

            if (destinationTimeline != null) // other timeline
            {
                destinationTimeline.AddTrackInternal(newTrack);
            }
            else if (timelineParent != null) // this timeline, no parent
            {
                ReparentTracks(new List <TrackAsset> {
                    newTrack
                }, timelineParent, timelineParent.GetRootTracks().Last(), false);
            }
            else // this timeline, with parent
            {
                trackParent.AddChild(newTrack);
            }

            // Call the custom editor. this check prevents the call when copying to the clipboard
            if (destinationTimeline == null || destinationTimeline == TimelineEditor.inspectedAsset)
            {
                var customEditor = CustomTimelineEditorCache.GetTrackEditor(newTrack);
                try
                {
                    customEditor.OnCreate(newTrack, track);
                }
                catch (Exception e)
                {
                    Debug.LogException(e);
                }
            }

            return(newTrack);
        }
Beispiel #17
0
        public override void OnInspectorGUI()
        {
            var prefabProperty = serializedObject.FindProperty("_prefab");

            EditorGUILayout.PropertyField(prefabProperty);
            filter = EditorGUILayout.TextField("Filter", filter);
            var text = prefabProperty.objectReferenceValue != null ? "Update Animator Controller" : "Create Animation Controller";

            if (GUILayout.Button(text))
            {
                var directory  = Path.GetDirectoryName(AssetDatabase.GetAssetPath(target));
                var builder    = target as CharacterControllerBuilder;
                var prefab     = prefabProperty.objectReferenceValue as GameObject;
                var director   = prefab == null ? null : prefab.GetComponentInChildren <PlayableDirector>();
                var animator   = prefab == null ? null : prefab.GetComponentInChildren <Animator>();
                var animatorGo = animator == null ? null : animator.gameObject;
                foreach (var state in builder.Builder.States)
                {
                    TimelineAsset timeline = state.Data.Timeline;
                    if (state.Data.Timeline == null)
                    {
                        timeline = ScriptableObject.CreateInstance <TimelineAsset>();
                        AssetDatabase.CreateAsset(timeline, Path.Combine(directory, builder.name + "_" + state.Name + ".playable"));
                        state.Data.Timeline = timeline;
                    }
                    var baseAnimationTrack = GetOrCreateAnimationTrack($"base_animation_{state.Name}", timeline, track => {
                        foreach (var timelineClip in track.GetClips())
                        {
                            timeline.DeleteClip(timelineClip);
                        }
                    });
                    var hitboxAnimationTrack = GetOrCreateAnimationTrack($"hitbox_animation_{state.Name}", timeline);

                    if (director != null && animator != null)
                    {
                        director.SetGenericBinding(baseAnimationTrack, animatorGo);
                        director.SetGenericBinding(hitboxAnimationTrack, animatorGo);
                    }

                    if (state.Data.AnimationClip == null)
                    {
                        continue;
                    }

                    // Create base animation clip
                    var baseClip = baseAnimationTrack.CreateClip(state.Data.AnimationClip);
                    baseClip.displayName = state.Data.AnimationClip.name + "_Animation";

                    EditorUtility.SetDirty(timeline);
                    EditorUtility.SetDirty(baseAnimationTrack);
                    EditorUtility.SetDirty(hitboxAnimationTrack);
                }
                EditorUtility.SetDirty(prefab);
                EditorUtility.SetDirty(target);
                AssetDatabase.SaveAssets();
            }
            EditorGUILayout.Space();
            var data = serializedObject.FindProperty("_data");

            for (var i = 0; i < data.arraySize; i++)
            {
                var element = data.GetArrayElementAtIndex(i);
                var name    = element.FindPropertyRelative("Name").stringValue;
                if (!string.IsNullOrEmpty(filter) && !name.ToUpper().Contains(filter.ToUpper()))
                {
                    continue;
                }
                var elementData   = element.FindPropertyRelative("Data");
                var clip          = elementData.FindPropertyRelative("AnimationClip");
                var length        = elementData.FindPropertyRelative("Length");
                var animationClip = clip.objectReferenceValue as AnimationClip;
                EditorGUILayout.PropertyField(elementData, new GUIContent(name), true);
                var newClip = clip.objectReferenceValue as AnimationClip;
                if (animationClip != newClip && newClip != null)
                {
                    length.floatValue = newClip.length;
                }
            }
            if (GUI.changed)
            {
                serializedObject.ApplyModifiedProperties();
            }
        }
Beispiel #18
0
        // Reparents a list of tracks to a new parent
        //  the new parent cannot be null (has to be track asset or sequence)
        //  the insertAfter can be null (will not reorder)
        internal static bool ReparentTracks(List <TrackAsset> tracksToMove, PlayableAsset targetParent,
                                            TrackAsset insertMarker = null, bool insertBefore = false)
        {
            var targetParentTrack   = targetParent as TrackAsset;
            var targetSequenceTrack = targetParent as TimelineAsset;

            if (tracksToMove == null || tracksToMove.Count == 0 || (targetParentTrack == null && targetSequenceTrack == null))
            {
                return(false);
            }

            // invalid parent type on a track
            if (targetParentTrack != null && tracksToMove.Any(x => !TimelineCreateUtilities.ValidateParentTrack(targetParentTrack, x.GetType())))
            {
                return(false);
            }

            // no valid tracks means this is simply a rearrangement
            var validTracks = tracksToMove.Where(x => x.parent != targetParent).ToList();

            if (insertMarker == null && !validTracks.Any())
            {
                return(false);
            }

            var parents = validTracks.Select(x => x.parent).Where(x => x != null).Distinct().ToList();

            // push the current state of the tracks that will change
            foreach (var p in parents)
            {
                TimelineUndo.PushUndo(p, "Reparent");
            }
            foreach (var t in validTracks)
            {
                TimelineUndo.PushUndo(t, "Reparent");
            }
            TimelineUndo.PushUndo(targetParent, "Reparent");

            // need to reparent tracks first, before moving them.
            foreach (var t in validTracks)
            {
                if (t.parent != targetParent)
                {
                    TrackAsset    toMoveParent   = t.parent as TrackAsset;
                    TimelineAsset toMoveTimeline = t.parent as TimelineAsset;
                    if (toMoveTimeline != null)
                    {
                        toMoveTimeline.RemoveTrack(t);
                    }
                    else if (toMoveParent != null)
                    {
                        toMoveParent.RemoveSubTrack(t);
                    }

                    if (targetParentTrack != null)
                    {
                        targetParentTrack.AddChild(t);
                        targetParentTrack.SetCollapsed(false);
                    }
                    else
                    {
                        targetSequenceTrack.AddTrackInternal(t);
                    }
                }
            }


            if (insertMarker != null)
            {
                // re-ordering track. This is using internal APIs, so invalidation of the tracks must be done manually to avoid
                //  cache mismatches
                var children = targetParentTrack != null ? targetParentTrack.subTracksObjects : targetSequenceTrack.trackObjects;
                TimelineUtility.ReorderTracks(children, tracksToMove, insertMarker, insertBefore);
                if (targetParentTrack != null)
                {
                    targetParentTrack.Invalidate();
                }
                if (insertMarker.timelineAsset != null)
                {
                    insertMarker.timelineAsset.Invalidate();
                }
            }

            return(true);
        }
Beispiel #19
0
        static private void ConvertIt(GameObject orgGo)
        {
            var orgPlayableDirector = orgGo.GetComponent <PlayableDirector>() as PlayableDirector;

            Assert.IsTrue(orgPlayableDirector != null, "PlayableDirector component is not attached to this GameObject." + orgGo);
            if (orgPlayableDirector == null)
            {
                return;
            }
            var orgAsset = orgPlayableDirector.playableAsset;

            if (orgAsset == null)
            {
                return;
            }
            if (orgAsset.GetType() != typeof(TimelineAsset))
            {
                return;
            }
            Assert.IsTrue(AssetDatabase.Contains(orgAsset));
            orgList.Add(orgAsset);



            // store gameobjects

            var           orgBindings = orgAsset.outputs;
            List <Object> goList      = new List <Object>();

            foreach (PlayableBinding binding in orgBindings)
            {
                Object tmpObject = orgPlayableDirector.GetGenericBinding(binding.sourceObject) as Object;
                goList.Add(tmpObject);
            }


            // create new asset.
            var path       = AssetDatabase.GetAssetPath(orgAsset);
            var uniquePath = AssetDatabase.GenerateUniqueAssetPath(path);

            AssetDatabase.CopyAsset(path, uniquePath);
            AssetDatabase.Refresh();
            newAsset = AssetDatabase.LoadAssetAtPath(uniquePath, typeof(Object)) as TimelineAsset;

            if (newAsset == null)
            {
                return;
            }

            // improtant: clear all bindings to avoid leaving garbage.

            orgPlayableDirector.playableAsset = newAsset;
            orgBindings = newAsset.outputs;

            foreach (PlayableBinding binding in orgBindings)
            {
                var source = binding.sourceObject;
                orgPlayableDirector.SetGenericBinding(source, null);
            }

            orgPlayableDirector.playableAsset = orgAsset;
            // done cleaning.


            var cloneGo = GameObject.Instantiate(orgGo);
            var parent  = orgGo.transform.parent;

            cloneGo.transform.SetParent(parent);
            cloneGo.transform.SetSiblingIndex(parent == null ? 0 : parent.transform.childCount - 1);
            cloneGo.transform.localPosition = orgGo.transform.localPosition;
            cloneGo.transform.localRotation = orgGo.transform.localRotation;
            cloneGo.transform.localScale    = orgGo.transform.localScale;
            cloneGo.name = orgGo.name;
            cloneGo.name = GameObjectUtility.GetUniqueNameForSibling(parent, cloneGo.name);

            newPlayableDirector = cloneGo.GetComponent <PlayableDirector>() as PlayableDirector;
            if (newPlayableDirector == null)
            {
                return;
            }
            newPlayableDirector.playableAsset = newAsset;

            var newBindings = newAsset.outputs;

            int index = 0;

            foreach (PlayableBinding binding in newBindings)
            {
                newPlayableDirector.SetGenericBinding(binding.sourceObject, goList[index++]);
            }

            // start to modify tracks in the new playable asset.
            var rootTracks = UpdateManager.GetTrackList(newAsset);

            ProcessTracks(null, rootTracks, goList, 0);

            newPlayableDirector = null;
            newAsset            = null;
            Debug.Log("Done duplicate " + orgGo);
        }
 public CinemachineTrackManager(TimelineAsset _timeline)
 {
     timeline     = _timeline;
     currentTrack = timeline.CreateTrack <CinemachineTrack>(null, "film_track");
 }
        public static DragAndDropVisualMode HandleClipPaneObjectDragAndDrop(IEnumerable<UnityObject> objectsBeingDropped, TrackAsset targetTrack, bool perform, TimelineAsset timeline, TrackAsset parent, PlayableDirector director, double candidateTime, TypeResolver typeResolver, TrackAsset insertBefore = null)
        {
            if (timeline == null)
                return DragAndDropVisualMode.Rejected;

            // locked tracks always reject
            if (targetTrack != null && targetTrack.lockedInHierarchy)
                return DragAndDropVisualMode.Rejected;

            // treat group tracks as having no track
            if (targetTrack is GroupTrack)
            {
                parent = targetTrack;
                targetTrack = null;
            }

            // Special case for monoscripts, since they describe the type
            if (objectsBeingDropped.Any(o => o is MonoScript))
                return HandleClipPaneMonoScriptDragAndDrop(objectsBeingDropped.OfType<MonoScript>(), targetTrack, perform, timeline, parent, director, candidateTime);

            // no unity objects, or explicit exceptions
            if (!objectsBeingDropped.Any() || objectsBeingDropped.Any(o => !ValidateObjectDrop(o)))
                return DragAndDropVisualMode.Rejected;

            // reject scene references if we have no context
            if (director == null && objectsBeingDropped.Any(o => o.IsSceneObject()))
                return DragAndDropVisualMode.Rejected;

            var validTrackTypes = objectsBeingDropped.SelectMany(o => TypeUtility.GetTrackTypesForObject(o)).Distinct().ToList();
            // special case for playable assets
            if (objectsBeingDropped.Any(o => TypeUtility.IsConcretePlayableAsset(o.GetType())))
            {
                var playableAssets = objectsBeingDropped.OfType<IPlayableAsset>().Where(o => TypeUtility.IsConcretePlayableAsset(o.GetType()));
                return HandleClipPanePlayableAssetDragAndDrop(playableAssets, targetTrack, perform, timeline, parent, director, candidateTime, typeResolver);
            }

            var markerTypes = objectsBeingDropped.SelectMany(o => TypeUtility.MarkerTypesWithFieldForObject(o)).Distinct();

            // Markers support all tracks
            if (!markerTypes.Any())
            {
                // No tracks support this object
                if (!validTrackTypes.Any())
                    return DragAndDropVisualMode.Rejected;

                // no tracks for this object
                if (targetTrack != null && !validTrackTypes.Contains(targetTrack.GetType()))
                    return DragAndDropVisualMode.Rejected;
            }

            // there is no target track, dropping to empty space, or onto a group
            if (perform)
            {
                // choose track and then clip
                if (targetTrack == null)
                {
                    var createdTrack = HandleTrackAndItemCreation(objectsBeingDropped, candidateTime, typeResolver, timeline, parent, validTrackTypes, insertBefore);
                    if (!createdTrack)
                    {
                        timeline.CreateMarkerTrack();
                        HandleItemCreation(objectsBeingDropped, timeline.markerTrack, candidateTime, typeResolver, true); // menu is always popped if ambiguous choice
                    }
                }
                // just choose clip/marker
                else
                {
                    HandleItemCreation(objectsBeingDropped, targetTrack, candidateTime, typeResolver, true); // menu is always popped if ambiguous choice
                }
            }

            return DragAndDropVisualMode.Copy;
        }
 public PlayableTrackManager(TimelineAsset _timeline, string trackName)
 {
     name         = trackName;
     timeline     = _timeline;
     currentTrack = timeline.CreateTrack <PlayableTrack>(null, name + trackNum.ToString());
 }
        /// Handles drag and drop of a mono script.
        public static DragAndDropVisualMode HandleClipPaneMonoScriptDragAndDrop(IEnumerable<MonoScript> scriptsBeingDropped, TrackAsset targetTrack, bool perform, TimelineAsset timeline, TrackAsset parent, PlayableDirector director, double candidateTime)
        {
            var playableAssetTypes = scriptsBeingDropped.Select(s => s.GetClass()).Where(TypeUtility.IsConcretePlayableAsset).Distinct();
            if (!playableAssetTypes.Any())
                return DragAndDropVisualMode.Rejected;

            var targetTrackType = typeof(PlayableTrack);
            if (targetTrack != null)
                targetTrackType = targetTrack.GetType();

            var trackAssetsTypes = TypeUtility.GetPlayableAssetsHandledByTrack(targetTrackType);
            var supportedTypes = trackAssetsTypes.Intersect(playableAssetTypes);
            if (!supportedTypes.Any())
                return DragAndDropVisualMode.Rejected;

            if (perform)
            {
                if (targetTrack == null)
                    targetTrack = TimelineHelpers.CreateTrack(timeline, targetTrackType, parent, string.Empty);
                TimelineHelpers.CreateClipsFromTypes(supportedTypes, targetTrack, candidateTime);
            }

            return DragAndDropVisualMode.Copy;
        }
Beispiel #24
0
 public TimelineMarkerHeaderGUI(TimelineAsset asset, WindowState state)
 {
     m_TrackHash = -1;
     timeline    = asset;
     this.state  = state;
 }
        public IEnumerator Start()
        {
            if (parameters == null || parameters.Length == 0)
            {
                Stop();
                yield break;
            }
            var mode    = GetParameter(0).ToLower();
            var subject = GetSubject(1, Sequencer.Speaker);
            var nowait  = string.Equals(GetParameter(2), "nowait", System.StringComparison.OrdinalIgnoreCase) ||
                          string.Equals(GetParameter(3), "nowait", System.StringComparison.OrdinalIgnoreCase);

            nostop = string.Equals(GetParameter(2), "nostop", System.StringComparison.OrdinalIgnoreCase) ||
                     string.Equals(GetParameter(3), "nostop", System.StringComparison.OrdinalIgnoreCase);
            playableDirector = (subject != null) ? subject.GetComponent <PlayableDirector>() : null;

            // If no suitable PlayableDirector was found, look for a Timeline asset in Resources:
            timelineAsset = DialogueManager.LoadAsset(GetParameter(1), typeof(TimelineAsset)) as TimelineAsset;
            if (timelineAsset != null)
            {
                playableDirector = new GameObject(GetParameter(1), typeof(PlayableDirector)).GetComponent <PlayableDirector>();
                playableDirector.playableAsset = timelineAsset;
                mustDestroyPlayableDirector    = true;
            }

            if (playableDirector == null)
            {
                if (DialogueDebug.LogWarnings)
                {
                    Debug.LogWarning("Dialogue System: Sequencer: Timeline(" + GetParameters() +
                                     "): Can't find playable director '" + GetParameter(0) + "'.");
                }
            }
            else if (playableDirector.playableAsset == null)
            {
                if (DialogueDebug.LogWarnings)
                {
                    Debug.LogWarning("Dialogue System: Sequencer: Timeline(" + GetParameters() +
                                     "): No timeline asset is assigned to the Playable Director.", playableDirector);
                }
            }
            else
            {
                var isModeValid = (mode == "play" || mode == "pause" || mode == "resume" || mode == "stop");
                if (!isModeValid)
                {
                    if (DialogueDebug.LogWarnings)
                    {
                        Debug.LogWarning("Dialogue System: Sequencer: Timeline(" + GetParameters() +
                                         "): Invalid mode '" + mode + "'. Expected 'play', 'pause', 'resume', or 'stop'.");
                    }
                }
                else
                {
                    if (DialogueDebug.LogInfo)
                    {
                        Debug.Log("Dialogue System: Sequencer: Timeline(" + GetParameters() + ")");
                    }

                    // Check for rebindings:
                    timelineAsset = playableDirector.playableAsset as TimelineAsset;
                    if (timelineAsset != null)
                    {
                        for (int i = 2; i < Parameters.Length; i++)
                        {
                            var s = GetParameter(i);
                            if (s.Contains(":"))
                            {
                                var colonPos   = s.IndexOf(":");
                                var trackIndex = Tools.StringToInt(s.Substring(0, colonPos));
                                var bindName   = s.Substring(colonPos + 1);
                                var track      = timelineAsset.GetOutputTrack(trackIndex);
                                if (track != null)
                                {
                                    playableDirector.SetGenericBinding(track, Tools.GameObjectHardFind(bindName));
                                }
                            }
                        }
                    }

                    switch (mode)
                    {
                    case "play":
                        playableDirector.Play();
                        var endTime = nowait ? 0 : DialogueTime.time + playableDirector.playableAsset.duration;
                        while (DialogueTime.time < endTime)
                        {
                            yield return(null);
                        }
                        break;

                    case "pause":
                        playableDirector.Pause();
                        nostop = true;
                        break;

                    case "resume":
                        playableDirector.Resume();
                        var resumedEndTime = nowait ? 0 : DialogueTime.time + playableDirector.playableAsset.duration - playableDirector.time;
                        while (DialogueTime.time < resumedEndTime)
                        {
                            yield return(null);
                        }
                        break;

                    case "stop":
                        playableDirector.Stop();
                        nostop = false;
                        break;

                    default:
                        isModeValid = false;
                        break;
                    }
                }
            }
            Stop();
        }
 public StationaryFabulaClip(JSONNode json, TimelineAsset p_timeline, PlayableDirector p_director) : base(json, p_timeline, p_director)
 {
 }
 public void Clear()
 {
     m_ItemsData.Clear();
     m_trackData.Clear();
     rootTimeline = CreateTimeline();
 }
Beispiel #28
0
 internal static bool IsEditingTimelineAsset(TimelineAsset timelineAsset)
 {
     return(instance != null && instance.state != null && instance.state.editSequence.asset == timelineAsset);
 }
Beispiel #29
0
 public TimelineDragging(TreeViewController treeView, TimelineWindow window, TimelineAsset data) : base(treeView)
 {
     this.m_Timeline = data;
     this.m_Window   = window;
 }
Beispiel #30
0
 public void Play(TimelineAsset timeline)
 {
     director.time = 0;
     director.Play(timeline);
 }