public static bool AddAnimatedParameterValueAt(this ICurvesOwner curvesOwner, string parameterName, float value, float time) { if (!curvesOwner.IsParameterAnimatable(parameterName)) { return(false); } if (curvesOwner.curves == null) { curvesOwner.CreateCurves(curvesOwner.GetUniqueRecordedClipName()); } var binding = curvesOwner.GetCurveBinding(parameterName); var curve = AnimationUtility.GetEditorCurve(curvesOwner.curves, binding) ?? new AnimationCurve(); var serializedObject = AnimatedParameterUtility.GetSerializedPlayableAsset(curvesOwner.asset); var property = serializedObject.FindProperty(parameterName); bool isStepped = property.propertyType == SerializedPropertyType.Boolean || property.propertyType == SerializedPropertyType.Integer || property.propertyType == SerializedPropertyType.Enum; TimelineUndo.PushUndo(curvesOwner.curves, "Set Key"); CurveEditUtility.AddKeyFrameToCurve(curve, time, curvesOwner.curves.frameRate, value, isStepped); AnimationUtility.SetEditorCurve(curvesOwner.curves, binding, curve); return(true); }
void CreateProxyCurve(SerializedProperty prop, AnimationClip clip, UnityObject owner, string propertyName) { var binding = AnimatedParameterUtility.GetCurveBinding(owner, propertyName); var originalCurve = m_OriginalOwner.hasCurves ? AnimationUtility.GetEditorCurve(m_OriginalOwner.curves, binding) : null; if (originalCurve != null) { AnimationUtility.SetEditorCurve(clip, binding, originalCurve); } else { var curve = new AnimationCurve(); CurveEditUtility.AddKeyFrameToCurve( curve, 0.0f, clip.frameRate, CurveEditUtility.GetKeyValue(prop), prop.propertyType == SerializedPropertyType.Boolean); AnimationUtility.SetEditorCurve(clip, binding, curve); } m_PropertiesMap[binding] = prop; }
public static bool AddAnimatedParameterValueAt(this TimelineClip clip, string parameterName, float value, float time) { if (!IsParameterAnimatable(clip, parameterName)) { return(false); } // strip the prefix for embedded parameters CreateCurvesIfRequired(clip); EditorCurveBinding binding = GetCurveBinding(clip, parameterName); var curve = AnimationUtility.GetEditorCurve(clip.curves, binding) ?? new AnimationCurve(); var serializedObject = GetSerializedObject(clip); var property = serializedObject.FindProperty(parameterName); bool isStepped = property.propertyType == SerializedPropertyType.Boolean || property.propertyType == SerializedPropertyType.Integer || property.propertyType == SerializedPropertyType.Enum; CurveEditUtility.AddKeyFrameToCurve(curve, time, clip.curves.frameRate, value, isStepped); AnimationUtility.SetEditorCurve(clip.curves, binding, curve); return(true); }
void SetProxyCurve(SerializedProperty prop, EditorCurveBinding binding) { var curve = new AnimationCurve(); CurveEditUtility.AddKeyFrameToCurve( curve, 0.0f, m_ProxyCurves.frameRate, CurveEditUtility.GetKeyValue(prop), prop.propertyType == SerializedPropertyType.Boolean); AnimationUtility.SetEditorCurve(m_ProxyCurves, binding, curve); }
private static void AddRotationKey(AnimationClip clip, EditorCurveBinding sourceBind, SerializedProperty prop, double time) { if (prop.get_propertyType() == 17) { List <AnimationCurve> list = new List <AnimationCurve>(); List <EditorCurveBinding> list2 = new List <EditorCurveBinding>(); AnimationClipCurveInfo curveInfo = AnimationClipCurveCache.Instance.GetCurveInfo(clip); for (int i = 0; i < curveInfo.bindings.Length; i++) { if (sourceBind.get_type() == curveInfo.bindings[i].get_type()) { if (curveInfo.bindings[i].propertyName.Contains("localEuler")) { list2.Add(curveInfo.bindings[i]); list.Add(curveInfo.curves[i]); } } } Vector3 localEulerAngles = ((Transform)prop.get_serializedObject().get_targetObject()).get_localEulerAngles(); if (list2.Count == 0) { string propertyGroupName = AnimationWindowUtility.GetPropertyGroupName(sourceBind.propertyName); list2.Add(EditorCurveBinding.FloatCurve(sourceBind.path, sourceBind.get_type(), propertyGroupName + ".x")); list2.Add(EditorCurveBinding.FloatCurve(sourceBind.path, sourceBind.get_type(), propertyGroupName + ".y")); list2.Add(EditorCurveBinding.FloatCurve(sourceBind.path, sourceBind.get_type(), propertyGroupName + ".z")); AnimationCurve animationCurve = new AnimationCurve(); AnimationCurve animationCurve2 = new AnimationCurve(); AnimationCurve animationCurve3 = new AnimationCurve(); CurveEditUtility.AddKeyFrameToCurve(animationCurve, (float)time, clip.get_frameRate(), localEulerAngles.x, false); CurveEditUtility.AddKeyFrameToCurve(animationCurve2, (float)time, clip.get_frameRate(), localEulerAngles.y, false); CurveEditUtility.AddKeyFrameToCurve(animationCurve3, (float)time, clip.get_frameRate(), localEulerAngles.z, false); list.Add(animationCurve); list.Add(animationCurve2); list.Add(animationCurve3); } for (int j = 0; j < list2.Count; j++) { char c = list2[j].propertyName.Last <char>(); float value = localEulerAngles.x; if (c == 'y') { value = localEulerAngles.y; } else if (c == 'z') { value = localEulerAngles.z; } CurveEditUtility.AddKeyFrameToCurve(list[j], (float)time, clip.get_frameRate(), value, false); } CurveEditUtility.UpdateEditorCurves(clip, list2, list); } }
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 static void AddFloatKey(AnimationClip clip, EditorCurveBinding sourceBind, SerializedProperty prop, double time) { List <AnimationCurve> list = new List <AnimationCurve>(); List <EditorCurveBinding> list2 = new List <EditorCurveBinding>(); bool flag = false; AnimationClipCurveInfo curveInfo = AnimationClipCurveCache.Instance.GetCurveInfo(clip); for (int i = 0; i < curveInfo.bindings.Length; i++) { EditorCurveBinding item = curveInfo.bindings[i]; if (item.get_type() == sourceBind.get_type()) { SerializedProperty serializedProperty = null; AnimationCurve animationCurve = curveInfo.curves[i]; if (prop.get_propertyPath().Equals(item.propertyName)) { serializedProperty = prop; } else if (item.propertyName.Contains(prop.get_propertyPath())) { serializedProperty = prop.get_serializedObject().FindProperty(item.propertyName); } if (serializedProperty != null) { float keyValue = CurveEditUtility.GetKeyValue(serializedProperty); if (!float.IsNaN(keyValue)) { flag = true; CurveEditUtility.AddKeyFrameToCurve(animationCurve, (float)time, clip.get_frameRate(), keyValue, serializedProperty.get_propertyType() == 1); list.Add(animationCurve); list2.Add(item); } } } } if (!flag) { string propertyGroupName = AnimationWindowUtility.GetPropertyGroupName(sourceBind.propertyName); if (!prop.get_hasChildren()) { float keyValue2 = CurveEditUtility.GetKeyValue(prop); if (!float.IsNaN(keyValue2)) { list2.Add(EditorCurveBinding.FloatCurve(sourceBind.path, sourceBind.get_type(), sourceBind.propertyName)); AnimationCurve animationCurve2 = new AnimationCurve(); CurveEditUtility.AddKeyFrameToCurve(animationCurve2, (float)time, clip.get_frameRate(), keyValue2, prop.get_propertyType() == 1); list.Add(animationCurve2); } } else if (prop.get_propertyType() == 4) { list2.Add(EditorCurveBinding.FloatCurve(sourceBind.path, sourceBind.get_type(), propertyGroupName + ".r")); list2.Add(EditorCurveBinding.FloatCurve(sourceBind.path, sourceBind.get_type(), propertyGroupName + ".g")); list2.Add(EditorCurveBinding.FloatCurve(sourceBind.path, sourceBind.get_type(), propertyGroupName + ".b")); list2.Add(EditorCurveBinding.FloatCurve(sourceBind.path, sourceBind.get_type(), propertyGroupName + ".a")); Color colorValue = prop.get_colorValue(); for (int j = 0; j < 4; j++) { AnimationCurve animationCurve3 = new AnimationCurve(); CurveEditUtility.AddKeyFrameToCurve(animationCurve3, (float)time, clip.get_frameRate(), colorValue.get_Item(j), prop.get_propertyType() == 1); list.Add(animationCurve3); } } else { prop = prop.Copy(); IEnumerator enumerator = prop.GetEnumerator(); try { while (enumerator.MoveNext()) { SerializedProperty serializedProperty2 = (SerializedProperty)enumerator.Current; list2.Add(EditorCurveBinding.FloatCurve(sourceBind.path, sourceBind.get_type(), serializedProperty2.get_propertyPath())); AnimationCurve animationCurve4 = new AnimationCurve(); CurveEditUtility.AddKeyFrameToCurve(animationCurve4, (float)time, clip.get_frameRate(), CurveEditUtility.GetKeyValue(serializedProperty2), serializedProperty2.get_propertyType() == 1); list.Add(animationCurve4); } } finally { IDisposable disposable; if ((disposable = (enumerator as IDisposable)) != null) { disposable.Dispose(); } } } } CurveEditUtility.UpdateEditorCurves(clip, list2, list); }