예제 #1
0
        static bool InternalAddParameter([NotNull] ICurvesOwner curvesOwner, string parameterName, ref EditorCurveBinding binding, out SerializedProperty property)
        {
            property = null;

            if (curvesOwner.IsParameterAnimated(parameterName))
            {
                return(false);
            }

            var serializedObject = AnimatedParameterUtility.GetSerializedPlayableAsset(curvesOwner.asset);

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

            property = serializedObject.FindProperty(parameterName);
            if (property == null || !AnimatedParameterUtility.IsTypeAnimatable(property.propertyType))
            {
                return(false);
            }

            if (curvesOwner.curves == null)
            {
                curvesOwner.CreateCurves(curvesOwner.GetUniqueRecordedClipName());
            }

            binding = curvesOwner.GetCurveBinding(parameterName);
            return(true);
        }
예제 #2
0
        public static bool RemoveAnimatedParameter(this ICurvesOwner curvesOwner, string parameterName)
        {
            if (!curvesOwner.IsParameterAnimated(parameterName) || curvesOwner.curves == null)
            {
                return(false);
            }

            var binding = curvesOwner.GetCurveBinding(parameterName);

            AnimationUtility.SetEditorCurve(curvesOwner.curves, binding, null);
            return(true);
        }
예제 #3
0
        // Set an animated parameter. Requires the field identifier 'position.x', but will add default curves to all fields
        public static bool SetAnimatedParameter(this ICurvesOwner curvesOwner, string parameterName, AnimationCurve curve)
        {
            // this will add a basic curve for all the related parameters
            if (!curvesOwner.IsParameterAnimated(parameterName) && !curvesOwner.AddAnimatedParameter(parameterName))
            {
                return(false);
            }

            var binding = curvesOwner.GetCurveBinding(parameterName);

            AnimationUtility.SetEditorCurve(curvesOwner.curves, binding, curve);
            return(true);
        }
예제 #4
0
        static bool ProcessPlayableAssetRecording(UndoPropertyModification mod, WindowState state, ICurvesOwner curvesOwner, bool allowAdd)
        {
            if (mod.currentValue == null)
            {
                return(false);
            }

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

            // only animate items with existing curves
            if (!allowAdd && !curvesOwner.IsParameterAnimated(mod.currentValue.propertyPath))
            {
                return(false);
            }

            var localTime    = state.editSequence.time;
            var timelineClip = curvesOwner as TimelineClip;

            if (timelineClip != null)
            {
                // don't use time global to local since it will possibly loop.
                localTime = timelineClip.ToLocalTimeUnbound(state.editSequence.time);
            }

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

            if (state.playing)
            {
                return(true); //absorb undo but don't record during playback
            }
            // grab the value from the current modification
            float fValue;

            if (!ExpressionEvaluator.Evaluate(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;
                if (!bool.TryParse(mod.currentValue.value, out bValue))
                {
                    Debug.Assert(false, "Invalid type in PlayableAsset recording");
                    return(false);
                }

                fValue = bValue ? 1 : 0;
            }

            var added = curvesOwner.AddAnimatedParameterValueAt(mod.currentValue.propertyPath, fValue, (float)localTime);

            if (added && AnimationMode.InAnimationMode())
            {
                EditorCurveBinding binding = curvesOwner.GetCurveBinding(mod.previousValue.propertyPath);
                AnimationMode.AddPropertyModification(binding, mod.previousValue, true);
                curvesOwner.targetTrack.SetShowInlineCurves(true);
                if (state.GetWindow() != null && state.GetWindow().treeView != null)
                {
                    state.GetWindow().treeView.CalculateRowRects();
                }
            }

            return(added);
        }