Exemple #1
0
        static void AddMarkerMenuCommands(GenericMenu menu, IEnumerable <Type> markerTypes, Func <Type, IMarker> addMarkerCommand, bool enabled)
        {
            foreach (var markerType in markerTypes)
            {
                var commandName = string.Format(Styles.addItemTemplate, TypeUtility.GetDisplayName(markerType));
                AddCommandToMenu(menu, commandName, () => addMarkerCommand(markerType), enabled);

                if (!typeof(ScriptableObject).IsAssignableFrom(markerType))
                {
                    continue;
                }

                Action <Object> onObjectChanged = obj =>
                {
                    if (obj == null)
                    {
                        return;
                    }
                    var marker = addMarkerCommand(markerType);

                    foreach (var field in ObjectReferenceField.FindObjectReferences(markerType))
                    {
                        if (field.IsAssignable(obj))
                        {
                            field.Assign(marker as ScriptableObject, obj, TimelineWindow.instance.state.editSequence.director);
                            break;
                        }
                    }
                };

                AddItemFromAssetCommands(menu, Styles.addItemFromAssetTemplate, markerType, onObjectChanged, enabled);
            }
        }
Exemple #2
0
        private static UnityEngine.Object GetUnderlyingAsset(WindowState state, TimelineClip clip)
        {
            var asset = clip.asset as ScriptableObject;

            if (asset == null)
            {
                return(null);
            }

            var fields = ObjectReferenceField.FindObjectReferences(asset.GetType());

            if (fields.Length == 0)
            {
                return(GetExternalPlayableAsset(clip));
            }

            // Find the first non-null field
            foreach (var field in fields)
            {
                // skip scene refs in asset mode
                if (state.editSequence.director == null && field.isSceneReference)
                {
                    continue;
                }
                var obj = field.Find(asset, state.editSequence.director);
                if (obj != null)
                {
                    return(obj);
                }
            }

            return(GetExternalPlayableAsset(clip));
        }
Exemple #3
0
        public static IMarker CreateMarkerOnTrack(Type markerType, Object assignableObject, TrackAsset parentTrack, double candidateTime)
        {
            WindowState state = null;

            if (TimelineWindow.instance != null)
            {
                state = TimelineWindow.instance.state;
            }

            var newMarker = parentTrack.CreateMarker(markerType, candidateTime); //Throws if marker is not an object

            if (assignableObject != null)
            {
                var director = state != null ? state.editSequence.director : null;
                foreach (var field in ObjectReferenceField.FindObjectReferences(markerType))
                {
                    if (field.IsAssignable(assignableObject))
                    {
                        field.Assign(newMarker as ScriptableObject, assignableObject, director);
                        break;
                    }
                }
            }

            try
            {
                CustomTimelineEditorCache.GetMarkerEditor(newMarker).OnCreate(newMarker, null);
            }
            catch (Exception e)
            {
                Debug.LogException(e);
            }

            return(newMarker);
        }
Exemple #4
0
        /// <summary>
        /// Shared code for adding a clip to a track
        /// </summary>
        static void AddClipOnTrack(TimelineClip newClip, TrackAsset parentTrack, double candidateTime, Object assignableObject, WindowState state)
        {
            var playableAsset = newClip.asset as IPlayableAsset;

            newClip.parentTrack = null;
            newClip.timeScale   = 1.0;
            newClip.mixInCurve  = AnimationCurve.EaseInOut(0, 0, 1, 1);
            newClip.mixOutCurve = AnimationCurve.EaseInOut(0, 1, 1, 0);

            var playableDirector = state != null ? state.editSequence.director : null;

            if (assignableObject != null)
            {
                foreach (var field in ObjectReferenceField.FindObjectReferences(playableAsset.GetType()))
                {
                    if (field.IsAssignable(assignableObject))
                    {
                        newClip.displayName = assignableObject.name;
                        field.Assign(newClip.asset as PlayableAsset, assignableObject, playableDirector);
                        break;
                    }
                }
            }

            // get the clip editor
            try
            {
                CustomTimelineEditorCache.GetClipEditor(newClip).OnCreate(newClip, parentTrack, null);
            }
            catch (Exception e)
            {
                Debug.LogException(e);
            }


            // reset the duration as the newly assigned values may have changed the default
            if (playableAsset != null)
            {
                var candidateDuration = playableAsset.duration;

                if (!double.IsInfinity(candidateDuration) && candidateDuration > 0)
                {
                    newClip.duration = Math.Min(Math.Max(candidateDuration, TimelineClip.kMinDuration), TimelineClip.kMaxTimeValue);
                }
            }

            var newClipsByTracks = new[] { new ItemsPerTrack(parentTrack, new[] { newClip.ToItem() }) };

            FinalizeInsertItemsUsingCurrentEditMode(state, newClipsByTracks, candidateTime);

            if (state != null)
            {
                state.Refresh();
            }
        }
Exemple #5
0
 public static void CreateClipsFromObjects(Type assetType, TrackAsset targetTrack, double candidateTime, IEnumerable <Object> objects)
 {
     foreach (var obj in objects)
     {
         if (ObjectReferenceField.FindObjectReferences(assetType).Any(f => f.IsAssignable(obj)))
         {
             var clip = CreateClipOnTrack(assetType, obj, targetTrack, candidateTime);
             candidateTime += clip.duration;
         }
     }
 }
        /// <summary>
        /// Get the list of playable assets that can handle an object for a particular track
        /// </summary>
        /// <param name="trackType">The type of the track</param>
        /// <param name="obj">The object to handle</param>
        /// <returns></returns>
        public static IEnumerable <Type> GetAssetTypesForObject(Type trackType, Object obj)
        {
            if (obj == null)
            {
                return(Enumerable.Empty <Type>());
            }

            return(GetPlayableAssetsHandledByTrack(trackType).Where(
                       c => ObjectReferenceField.FindObjectReferences(c).Any(o => o.IsAssignable(obj))
                       ));
        }
        public static IEnumerable <ObjectReference> ObjectReferencesForType(Type type)
        {
            var objectReferences = ObjectReferenceField.FindObjectReferences(type);
            var uniqueTypes      = objectReferences.Select(objRef => objRef.type).Distinct();

            foreach (var refType in uniqueTypes)
            {
                var isSceneReference = objectReferences.Any(objRef => objRef.type == refType && objRef.isSceneReference);
                yield return(new ObjectReference {
                    type = refType, isSceneReference = isSceneReference
                });
            }
        }
Exemple #8
0
        public static void CreateMarkersFromObjects(Type assetType, TrackAsset targetTrack, double candidateTime, IEnumerable <Object> objects)
        {
            var mList = new List <ITimelineItem>();

            foreach (var obj in objects)
            {
                if (ObjectReferenceField.FindObjectReferences(assetType).Any(f => f.IsAssignable(obj)))
                {
                    var marker = CreateMarkerOnTrack(assetType, obj, targetTrack, candidateTime);
                    mList.Add(marker.ToItem());
                }
            }

            var state = TimelineWindow.instance.state;

            for (var i = 1; i < mList.Count; ++i)
            {
                var delta = ItemsUtils.TimeGapBetweenItems(mList[i - 1], mList[i], state);
                mList[i].start += delta;
            }

            FinalizeInsertItemsUsingCurrentEditMode(state, new[] { new ItemsPerTrack(targetTrack, mList) }, candidateTime);
            state.Refresh();
        }
 /// <summary>
 ///  Get the list of markers that have fields for the object
 /// </summary>
 public static IEnumerable <Type> MarkerTypesWithFieldForObject(Object obj)
 {
     return(GetMarkerTypes().Where(
                c => ObjectReferenceField.FindObjectReferences(c).Any(o => o.IsAssignable(obj))
                ));
 }
 /// <summary>
 /// True if the given track has a clip type that handles the given object
 /// </summary>
 public static bool TrackHasClipForObject(Type trackType, Object obj)
 {
     return(GetPlayableAssetsHandledByTrack(trackType)
            .Any(c => ObjectReferenceField.FindObjectReferences(c).Any(o => o.IsAssignable(obj))));
 }