Beispiel #1
0
        public bool IsAnimatable(PropertyModification[] modifications)
        {
            // search playable assets
            for (int i = 0; i < modifications.Length; i++)
            {
                var iAsset = modifications[i].target as IPlayableAsset;
                if (iAsset != null)
                {
                    TimelineClip clip = TimelineRecording.FindClipWithAsset(state.editSequence.asset, iAsset, state.editSequence.director);
                    if (clip != null && clip.IsParameterAnimatable(modifications[i].propertyPath))
                    {
                        return(true);
                    }
                }
            }

            // search recordable game objects
            foreach (var gameObject in TimelineRecording.GetRecordableGameObjects(state))
            {
                for (int i = 0; i < modifications.Length; ++i)
                {
                    var modification = modifications[i];
                    if (AnimationWindowUtility.PropertyIsAnimatable(modification.target, modification.propertyPath, gameObject))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
        public bool IsAnimatable(PropertyModification[] modifications)
        {
            bool result;

            for (int i = 0; i < modifications.Length; i++)
            {
                IPlayableAsset playableAsset = modifications[i].target as IPlayableAsset;
                if (playableAsset != null)
                {
                    TimelineClip timelineClip = TimelineRecording.FindClipWithAsset(this.state.timeline, playableAsset, this.state.currentDirector);
                    if (timelineClip != null && timelineClip.IsParameterAnimatable(modifications[i].propertyPath))
                    {
                        result = true;
                        return(result);
                    }
                }
            }
            foreach (GameObject current in TimelineRecording.GetRecordableGameObjects(this.state))
            {
                for (int j = 0; j < modifications.Length; j++)
                {
                    PropertyModification propertyModification = modifications[j];
                    if (AnimationWindowUtility.PropertyIsAnimatable(propertyModification.target, propertyModification.propertyPath, current))
                    {
                        result = true;
                        return(result);
                    }
                }
            }
            result = false;
            return(result);
        }
        internal static bool ProcessPlayableAssetRecording(UndoPropertyModification mod, WindowState state, TimelineClip clip)
        {
            if (mod.currentValue == null)
            {
                return(false);
            }

            if (!clip.IsParameterAnimatable(mod.currentValue.propertyPath))
            {
                return(false);
            }

            // don't use time global to local since it will possibly loop.
            double localTime = clip.ToLocalTimeUnbound(state.editSequence.time);

            if (localTime < 0)
            {
                return(false);
            }

            // grab the value from the current modification
            float fValue = 0;

            if (!float.TryParse(mod.currentValue.value, out fValue))
            {
                // case 916913 -- 'Add Key' menu item will passes 'True' or 'False' (instead of 1, 0)
                // so we need a special case to parse the boolean string
                bool bValue = false;
                if (!bool.TryParse(mod.currentValue.value, out bValue))
                {
                    Debug.Assert(false, "Invalid type in PlayableAsset recording");
                    return(false);
                }

                fValue = bValue ? 1 : 0;
            }

            bool added = (clip.AddAnimatedParameterValueAt(mod.currentValue.propertyPath, fValue, (float)localTime));

            if (added && AnimationMode.InAnimationMode())
            {
                EditorCurveBinding binding = clip.GetCurveBinding(mod.previousValue.propertyPath);
                AnimationMode.AddPropertyModification(binding, mod.previousValue, true);
                clip.parentTrack.SetShowInlineCurves(true);
                if (state.GetWindow() != null && state.GetWindow().treeView != null)
                {
                    state.GetWindow().treeView.CalculateRowRects();
                }
            }
            return(added);
        }
        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);
        }