#pragma warning disable 612, 618 //for handles. will fix protected void DoParameterPositionHandle(AnimatedParameter animParam, TransformSpace space) { UnityEditor.EditorGUI.BeginChangeCheck(); var originalPos = (Vector3)animParam.GetCurrentValue(); var pos = TransformPoint(originalPos, space); var newPos = UnityEditor.Handles.PositionHandle(pos, Quaternion.identity); newPos = InverseTransformPoint(newPos, space); UnityEditor.Handles.SphereCap(-10, pos, Quaternion.identity, 0.1f); if (UnityEditor.EditorGUI.EndChangeCheck()) { UnityEditor.Undo.RecordObject(this, "Position Change"); if (RootTimeWithinRange()) { if (!Event.current.shift) { animParam.SetCurrentValue(newPos); } else { animParam.OffsetValue(newPos - originalPos); } } else { animParam.SetCurrentValue(newPos); animParam.OffsetValue(newPos - originalPos); } UnityEditor.EditorUtility.SetDirty(this); } }
///Used when the Animated Parameter is a property and we don't have a SerializedProperty. public static void DoParameterField(string name, AnimatedParameter animParam, float time) { if (animParam == null) { GUILayout.Label("null parameter"); //this should never happen but it did return; } if (animParam.targetObject == null || animParam.targetObject.Equals(null)) { GUILayout.Label("Target is Null"); return; } if (!animParam.enabled) { GUILayout.Label(name); return; } try { var type = animParam.animatedType; var animParamAtt = animParam.animatableAttribute; var value = animParam.GetCurrentValue(); var newValue = value; EditorGUI.BeginChangeCheck(); if (type == typeof(bool)) { name = name == null? "Value" : name; newValue = EditorGUILayout.Toggle(name, (bool)value); } if (type == typeof(float)) { if (animParamAtt != null && animParamAtt.min != null && animParamAtt.max != null) { name = name == null? string.Empty : name; var min = animParamAtt.min.Value; var max = animParamAtt.max.Value; newValue = EditorGUILayout.Slider(name, (float)value, min, max); } else { name = name == null? "Value" : name; newValue = EditorGUILayout.FloatField(name, (float)value); } } if (type == typeof(int)) { if (animParamAtt != null && animParamAtt.min != null && animParamAtt.max != null) { name = name == null? string.Empty : name; var min = animParamAtt.min.Value; var max = animParamAtt.max.Value; newValue = EditorGUILayout.IntSlider(name, (int)value, (int)min, (int)max); } else { name = name == null? "Value" : name; newValue = EditorGUILayout.IntField(name, (int)value); } } if (type == typeof(Vector2)) { name = name == null? string.Empty : name; newValue = EditorGUILayout.Vector2Field(name, (Vector2)value); } if (type == typeof(Vector3)) { name = name == null? string.Empty : name; newValue = EditorGUILayout.Vector3Field(name, (Vector3)value); } if (type == typeof(Color)) { name = name == null? string.Empty : name; GUI.backgroundColor = Color.white; //to avoid tinting newValue = EditorGUILayout.ColorField(new GUIContent(name), (Color)value, true, true, true, new ColorPickerHDRConfig(0f, float.MaxValue, 0f, float.MaxValue)); } if (EditorGUI.EndChangeCheck() && newValue != value) { animParam.SetCurrentValue(newValue); if (Prefs.autoKey || (animParam.isExternal && !animParam.HasAnyKey())) { animParam.TryAutoKey(time); } } } catch (System.Exception exc) { GUILayout.Label(string.Format("<color=#f25c5c>{0}</color> (<size=8>{1}</size>)", name, exc.Message)); } }