private static bool InternalAddParameter(TimelineClip clip, string parameterName, ref EditorCurveBinding binding, out SerializedProperty property)
        {
            property = null;
            bool result;

            if (clip.IsParameterAnimated(parameterName))
            {
                result = false;
            }
            else
            {
                SerializedObject serializedObject = AnimatedParameterExtensions.GetSerializedObject(clip);
                if (serializedObject == null)
                {
                    result = false;
                }
                else
                {
                    property = serializedObject.FindProperty(parameterName);
                    if (property == null || !AnimatedParameterExtensions.IsAnimatable(property.get_propertyType()))
                    {
                        result = false;
                    }
                    else
                    {
                        AnimatedParameterExtensions.CreateCurvesIfRequired(clip, null);
                        binding = clip.GetCurveBinding(parameterName);
                        result  = true;
                    }
                }
            }
            return(result);
        }
        private static string GetAnimatedParameterBindingName(TimelineClip clip, string parameterName)
        {
            string result;

            if (clip == null || clip.asset == null || clip.asset is IPlayableBehaviour)
            {
                result = parameterName;
            }
            else
            {
                IEnumerable <FieldInfo> scriptPlayableFields = AnimatedParameterExtensions.GetScriptPlayableFields(clip.asset as IPlayableAsset);
                foreach (FieldInfo current in scriptPlayableFields)
                {
                    if (parameterName.StartsWith(current.Name))
                    {
                        if (parameterName.Length > current.Name.Length && parameterName[current.Name.Length] == '.')
                        {
                            result = parameterName.Substring(current.Name.Length + 1);
                            return(result);
                        }
                    }
                }
                result = parameterName;
            }
            return(result);
        }
Ejemplo n.º 3
0
        void AddSerializedPlayableModifications(IPlayableAsset asset, AnimationClip clip)
        {
            var obj = asset as Object;

            if (obj == null)
            {
                return;
            }

            var driver = WindowState.previewDriver;

            if (driver == null || !AnimationMode.InAnimationMode(driver))
            {
                return;
            }

            var bindings = AnimationClipCurveCache.Instance.GetCurveInfo(clip).bindings;
            var fields   = AnimatedParameterExtensions.GetScriptPlayableFields(asset).ToList();

            // go through each binding and offset using the field name
            //  so the modification system can find the particle object using the asset as a root
            foreach (var b in bindings)
            {
                foreach (var f in fields)
                {
                    DrivenPropertyManager.RegisterProperty(driver, obj, f.Name + "." + b.propertyName);
                }
            }
        }
Ejemplo n.º 4
0
        public static TimelineClip Clone(TimelineClip clip, PlayableDirector directorInstance)
        {
            EditorClip   editorClip = EditorItemFactory.GetEditorClip(clip);
            TimelineClip clip2      = Object.Instantiate <EditorClip>(editorClip).clip;

            SelectionManager.Remove(clip2);
            clip2.parentTrack = null;
            clip2.ClearAnimatedParameterCurves();
            if (clip.curves != null)
            {
                AnimatedParameterExtensions.CreateCurvesIfRequired(clip2, clip.parentTrack);
                EditorUtility.CopySerialized(clip.curves, clip2.curves);
            }
            ScriptableObject scriptableObject = clip2.asset as ScriptableObject;

            if (scriptableObject != null && clip2.asset is IPlayableAsset)
            {
                ScriptableObject scriptableObject2 = TimelineHelpers.CloneReferencedPlayableAsset(scriptableObject, directorInstance);
                TimelineHelpers.SaveCloneToOriginalAsset(scriptableObject, scriptableObject2);
                clip2.asset = scriptableObject2;
                AnimationPlayableAsset animationPlayableAsset = scriptableObject2 as AnimationPlayableAsset;
                if (clip2.recordable && animationPlayableAsset != null && animationPlayableAsset.clip != null)
                {
                    clip2.displayName = animationPlayableAsset.clip.get_name();
                }
            }
            return(clip2);
        }
        // Given a track, return the animation clip
        internal static AnimationClip FindRecordingAnimationClipAtTime(this TrackAsset trackAsset, double time)
        {
            if (trackAsset == null)
                return null;

            AnimationTrack animTrack = trackAsset as AnimationTrack;
            if (animTrack != null && !animTrack.inClipMode)
            {
                return animTrack.infiniteClip;
            }

            TimelineClip displayBackground = null;
            trackAsset.FindRecordingClipAtTime(time, out displayBackground);
            if (displayBackground != null)
            {
                if (displayBackground.recordable)
                {
                    AnimationPlayableAsset asset = displayBackground.asset as AnimationPlayableAsset;
                    if (asset != null)
                        return asset.clip;
                }
                else if (animTrack == null)
                {
                    AnimatedParameterExtensions.CreateCurvesIfRequired(displayBackground);
                    return displayBackground.curves;
                }
            }

            return null;
        }
        public static bool IsParameterAnimatable(this TimelineClip clip, string parameterName)
        {
            bool result;

            if (clip.asset == null || Attribute.IsDefined(clip.asset.GetType(), typeof(NotKeyableAttribute)))
            {
                result = false;
            }
            else if (!clip.HasScriptPlayable())
            {
                result = false;
            }
            else
            {
                SerializedObject serializedObject = AnimatedParameterExtensions.GetSerializedObject(clip);
                if (serializedObject == null)
                {
                    result = false;
                }
                else
                {
                    bool flag = clip.asset is IPlayableBehaviour;
                    SerializedProperty serializedProperty = serializedObject.FindProperty(parameterName);
                    result = (serializedProperty != null && AnimatedParameterExtensions.IsAnimatable(serializedProperty.get_propertyType()) && AnimatedParameterExtensions.IsKeyable(clip.asset.GetType(), parameterName) && (flag || clip.IsAnimatablePath(serializedProperty.get_propertyPath())));
                }
            }
            return(result);
        }
Ejemplo n.º 7
0
        public void AddFromComponent(GameObject obj, Component component)
        {
            if (Application.isPlaying)
            {
                return;
            }

            if (obj == null || component == null)
            {
                return;
            }

            var serializedObject        = new SerializedObject(component);
            SerializedProperty property = serializedObject.GetIterator();

            while (property.NextVisible(true))
            {
                if (property.hasVisibleChildren || !AnimatedParameterExtensions.IsAnimatable(property.propertyType))
                {
                    continue;
                }

                AddPropertyModification(component, property.propertyPath);
            }
        }
Ejemplo n.º 8
0
        // Helper that finds the animation clip we are recording and the relative time to that clip
        static bool GetClipAndRelativeTime(UnityEngine.Object target, WindowState state,
                                           out AnimationClip outClip, out double keyTime, out bool keyInRange)
        {
            const float floatToDoubleError = 0.00001f;

            outClip    = null;
            keyTime    = 0;
            keyInRange = false;

            double        startTime = 0;
            double        timeScale = 1;
            AnimationClip clip      = null;

            IPlayableAsset playableAsset = target as IPlayableAsset;
            Component      component     = target as Component;

            // Handle recordable playable assets
            if (playableAsset != null)
            {
                var timelineClip = FindClipWithAsset(state.editSequence.asset, playableAsset, state.editSequence.director);
                if (timelineClip != null && state.IsArmedForRecord(timelineClip.parentTrack))
                {
                    AnimatedParameterExtensions.CreateCurvesIfRequired(timelineClip);
                    clip      = timelineClip.curves;
                    startTime = timelineClip.start;
                    timeScale = timelineClip.timeScale;
                }
            }
            // Handle recording components, including infinite clip
            else if (component != null)
            {
                var asset = GetTrackForGameObject(component.gameObject, state);
                if (asset != null)
                {
                    clip = GetRecordingClip(asset, state, out startTime, out timeScale);
                }
            }

            if (clip == null)
            {
                return(false);
            }

            keyTime    = (state.editSequence.time - startTime) * timeScale;
            outClip    = clip;
            keyInRange = keyTime >= 0 && keyTime <= (clip.length * timeScale + floatToDoubleError);

            return(true);
        }
        internal static bool HasScriptPlayable(this TimelineClip clip)
        {
            bool result;

            if (clip.asset == null)
            {
                result = false;
            }
            else
            {
                IPlayableBehaviour playableBehaviour = clip.asset as IPlayableBehaviour;
                result = (playableBehaviour != null || AnimatedParameterExtensions.GetScriptPlayableFields(clip.asset as IPlayableAsset).Any <FieldInfo>());
            }
            return(result);
        }
Ejemplo n.º 10
0
        public static bool CanRecord(SerializedProperty property, WindowState state)
        {
            if (IsPlayableAssetProperty(property))
            {
                return(AnimatedParameterExtensions.IsAnimatable(property.propertyType));
            }

            if (GetRecordingTrack(property, state) == null)
            {
                return(false);
            }

            s_TempPropertyModifications.Clear();
            GatherModifications(property, s_TempPropertyModifications);
            return(s_TempPropertyModifications.Any());
        }
Ejemplo n.º 11
0
        internal static TimelineClip Clone(TimelineClip clip, PlayableDirector director, PlayableAsset newOwner)
        {
            var editorClip = EditorClipFactory.GetEditorClip(clip);
            // Workaround for Clips not being unity object, assign it to a editor clip wrapper, clone it, and pull the clip back out
            var newClip = Object.Instantiate(editorClip).clip;

            // perform fix ups for what Instantiate cannot properly detect
            SelectionManager.Remove(newClip);
            newClip.parentTrack = null;
            newClip.curves      = null; // instantiate might copy the reference, we need to clear it

            // curves are explicitly owned by the clip
            if (clip.curves != null)
            {
                AnimatedParameterExtensions.CreateCurvesIfRequired(newClip, newOwner);
                EditorUtility.CopySerialized(clip.curves, newClip.curves);
            }

            ScriptableObject playableAsset = newClip.asset as ScriptableObject;

            if (playableAsset != null && newClip.asset is IPlayableAsset)
            {
                var clone = CloneReferencedPlayableAsset(playableAsset, director);
                SaveCloneToAsset(clone, newOwner);

                newClip.asset = clone;

                // special case to make the name match the recordable clips, but only if they match on the original clip
                var originalRecordedAsset = clip.asset as AnimationPlayableAsset;
                if (clip.recordable && originalRecordedAsset != null && originalRecordedAsset.clip != null)
                {
                    AnimationPlayableAsset clonedAnimationAsset = clone as AnimationPlayableAsset;
                    if (clonedAnimationAsset != null && clonedAnimationAsset.clip != null)
                    {
                        clonedAnimationAsset.clip = CloneAnimationClip(originalRecordedAsset.clip, newOwner);
                        if (clip.displayName == originalRecordedAsset.clip.name && newClip.recordable)
                        {
                            clonedAnimationAsset.name = clonedAnimationAsset.clip.name;
                            newClip.displayName       = clonedAnimationAsset.name;
                        }
                    }
                }
            }

            return(newClip);
        }
 public void AddFromComponent(GameObject obj, Component component)
 {
     if (!Application.get_isPlaying())
     {
         if (!(obj == null) && !(component == null))
         {
             SerializedObject   serializedObject = new SerializedObject(component);
             SerializedProperty iterator         = serializedObject.GetIterator();
             while (iterator.NextVisible(true))
             {
                 if (!iterator.get_hasVisibleChildren() && AnimatedParameterExtensions.IsAnimatable(iterator.get_propertyType()))
                 {
                     PropertyCollector.AddPropertyModification(component, iterator.get_propertyPath());
                 }
             }
         }
     }
 }
        public static bool AddAnimatedParameter(this TimelineClip clip, string parameterName)
        {
            EditorCurveBinding sourceBinding = default(EditorCurveBinding);
            SerializedProperty prop;
            bool result;

            if (!AnimatedParameterExtensions.InternalAddParameter(clip, parameterName, ref sourceBinding, out prop))
            {
                result = false;
            }
            else
            {
                float num = (float)clip.duration;
                CurveEditUtility.AddKey(clip.curves, sourceBinding, prop, 0.0);
                CurveEditUtility.AddKey(clip.curves, sourceBinding, prop, (double)num);
                result = true;
            }
            return(result);
        }
        public static bool IsParameterAnimated(this TimelineClip clip, string parameterName)
        {
            bool result;

            if (clip == null)
            {
                result = false;
            }
            else if (clip.curves == null)
            {
                result = false;
            }
            else
            {
                EditorCurveBinding   binding  = clip.GetCurveBinding(parameterName);
                EditorCurveBinding[] bindings = AnimationClipCurveCache.Instance.GetCurveInfo(clip.curves).bindings;
                result = bindings.Any((EditorCurveBinding x) => AnimatedParameterExtensions.MatchBinding(x, binding.propertyName));
            }
            return(result);
        }
Ejemplo n.º 15
0
        internal static AnimationClip FindRecordingAnimationClipAtTime(this TrackAsset trackAsset, double time)
        {
            AnimationClip result;

            if (trackAsset == null)
            {
                result = null;
            }
            else
            {
                AnimationTrack animationTrack = trackAsset as AnimationTrack;
                if (animationTrack != null && !animationTrack.inClipMode)
                {
                    result = animationTrack.animClip;
                }
                else
                {
                    TimelineClip timelineClip = trackAsset.FindRecordingClipAtTime(time);
                    if (timelineClip != null)
                    {
                        AnimationPlayableAsset animationPlayableAsset = timelineClip.asset as AnimationPlayableAsset;
                        if (animationPlayableAsset != null)
                        {
                            result = animationPlayableAsset.clip;
                        }
                        else
                        {
                            AnimatedParameterExtensions.CreateCurvesIfRequired(timelineClip, null);
                            result = timelineClip.curves;
                        }
                    }
                    else
                    {
                        result = null;
                    }
                }
            }
            return(result);
        }
        public static bool AddAnimatedParameterValueAt(this TimelineClip clip, string parameterName, float value, float time)
        {
            bool result;

            if (!clip.IsParameterAnimatable(parameterName))
            {
                result = false;
            }
            else
            {
                AnimatedParameterExtensions.CreateCurvesIfRequired(clip, null);
                EditorCurveBinding curveBinding       = clip.GetCurveBinding(parameterName);
                AnimationCurve     animationCurve     = AnimationUtility.GetEditorCurve(clip.curves, curveBinding) ?? new AnimationCurve();
                SerializedObject   serializedObject   = AnimatedParameterExtensions.GetSerializedObject(clip);
                SerializedProperty serializedProperty = serializedObject.FindProperty(parameterName);
                bool stepped = serializedProperty.get_propertyType() == 1 || serializedProperty.get_propertyType() == null || serializedProperty.get_propertyType() == 7;
                CurveEditUtility.AddKeyFrameToCurve(animationCurve, time, clip.curves.get_frameRate(), value, stepped);
                AnimationUtility.SetEditorCurve(clip.curves, curveBinding, animationCurve);
                result = true;
            }
            return(result);
        }
        private void AddSerializedPlayableModifications(IPlayableAsset asset, AnimationClip clip)
        {
            Object @object = asset as Object;

            if (!(@object == null))
            {
                AnimationModeDriver previewDriver = TimelineWindow.TimelineState.previewDriver;
                if (!(previewDriver == null) && AnimationMode.InAnimationMode(previewDriver))
                {
                    EditorCurveBinding[] bindings = AnimationClipCurveCache.Instance.GetCurveInfo(clip).bindings;
                    List <FieldInfo>     list     = AnimatedParameterExtensions.GetScriptPlayableFields(asset).ToList <FieldInfo>();
                    EditorCurveBinding[] array    = bindings;
                    for (int i = 0; i < array.Length; i++)
                    {
                        EditorCurveBinding editorCurveBinding = array[i];
                        foreach (FieldInfo current in list)
                        {
                            DrivenPropertyManager.RegisterProperty(previewDriver, @object, current.Name + "." + editorCurveBinding.propertyName);
                        }
                    }
                }
            }
        }
        public static bool HasAnyAnimatableParameters(this TimelineClip clip)
        {
            bool result;

            if (clip.asset == null || Attribute.IsDefined(clip.asset.GetType(), typeof(NotKeyableAttribute)))
            {
                result = false;
            }
            else if (!clip.HasScriptPlayable())
            {
                result = false;
            }
            else
            {
                SerializedObject serializedObject = AnimatedParameterExtensions.GetSerializedObject(clip);
                if (serializedObject == null)
                {
                    result = false;
                }
                else
                {
                    SerializedProperty iterator = serializedObject.GetIterator();
                    bool flag  = true;
                    bool flag2 = clip.asset is IPlayableBehaviour;
                    bool flag3 = false;
                    while (iterator.NextVisible(flag))
                    {
                        if (AnimatedParameterExtensions.IsAnimatable(iterator.get_propertyType()) && AnimatedParameterExtensions.IsKeyable(clip.asset.GetType(), iterator.get_propertyPath()))
                        {
                            flag3 |= (flag2 || clip.IsAnimatablePath(iterator.get_propertyPath()));
                        }
                    }
                    result = flag3;
                }
            }
            return(result);
        }
        public static EditorCurveBinding GetCurveBinding(this TimelineClip clip, string parameterName)
        {
            string animatedParameterBindingName = AnimatedParameterExtensions.GetAnimatedParameterBindingName(clip, parameterName);

            return(EditorCurveBinding.FloatCurve(string.Empty, AnimatedParameterExtensions.GetAnimationType(clip), animatedParameterBindingName));
        }
 internal static bool IsAnimatablePath(this TimelineClip clip, string path)
 {
     return(!(clip.asset == null) && AnimatedParameterExtensions.GetScriptPlayableFields(clip.asset as IPlayableAsset).Any((FieldInfo f) => path.StartsWith(f.Name) && path.Length > f.Name.Length && path[f.Name.Length] == '.'));
 }