// I've seen a lot of ugly methods in Unity source code, but this is just.. OMG // The method is identical to the original, only non-delayed fields are replaced with their delayed versions where possible. // For SerializedPropertyType.Integer, there is also a ternary expression instead of a single LongField because a version of DelayedLongField doesn't exist. public static bool DefaultPropertyFieldDelayed(Rect position, SerializedProperty property, GUIContent label) { label = EditorGUI.BeginPropertyInternal(position, label, property); SerializedPropertyType type = property.propertyType; bool childrenAreExpanded = false; // Should we inline? All one-line vars as well as Vector2, Vector3, Rect and Bounds properties are inlined. if (!EditorGUI.HasVisibleChildFields(property)) { switch (type) { case SerializedPropertyType.Integer: { EditorGUI.BeginChangeCheck(); long newValue = property.longValue > Int32.MaxValue ? EditorGUI.LongField(position, label, property.longValue) : EditorGUI.DelayedIntField(position, label, property.intValue); if (EditorGUI.EndChangeCheck()) { property.longValue = newValue; } break; } case SerializedPropertyType.Float: { EditorGUI.BeginChangeCheck(); // Necessary to check for float type to get correct string formatting for float and double. bool isFloat = property.type == "float"; double newValue = isFloat ? EditorGUI.DelayedFloatField(position, label, property.floatValue) : EditorGUI.DelayedDoubleField(position, label, property.doubleValue); if (EditorGUI.EndChangeCheck()) { property.doubleValue = newValue; } break; } case SerializedPropertyType.String: { EditorGUI.BeginChangeCheck(); string newValue = EditorGUI.DelayedTextField(position, label, property.stringValue); if (EditorGUI.EndChangeCheck()) { property.stringValue = newValue; } break; } case SerializedPropertyType.Boolean: { EditorGUI.BeginChangeCheck(); bool newValue = EditorGUI.Toggle(position, label, property.boolValue); if (EditorGUI.EndChangeCheck()) { property.boolValue = newValue; } break; } case SerializedPropertyType.Color: { EditorGUI.BeginChangeCheck(); Color newColor = EditorGUI.ColorField(position, label, property.colorValue); if (EditorGUI.EndChangeCheck()) { property.colorValue = newColor; } break; } case SerializedPropertyType.ArraySize: { EditorGUI.BeginChangeCheck(); int newValue = EditorGUI.ArraySizeField(position, label, property.intValue, EditorStyles.numberField); if (EditorGUI.EndChangeCheck()) { property.intValue = newValue; } break; } case SerializedPropertyType.FixedBufferSize: { EditorGUI.DelayedIntField(position, label, property.intValue); break; } case SerializedPropertyType.Enum: { EditorGUI.EnumPopup(position, property, label); break; } case SerializedPropertyType.ObjectReference: { EditorGUI.ObjectFieldInternal(position, property, null, label, EditorStyles.objectField); break; } case SerializedPropertyType.LayerMask: { EditorGUI.LayerMaskField(position, property, label); break; } case SerializedPropertyType.Character: { char[] value = { (char)property.intValue }; bool wasChanged = GUI.changed; GUI.changed = false; string newValue = EditorGUI.DelayedTextField(position, label, new string(value)); if (GUI.changed) { if (newValue.Length == 1) { property.intValue = newValue[0]; } // Value didn't get changed after all else { GUI.changed = false; } } GUI.changed |= wasChanged; break; } case SerializedPropertyType.AnimationCurve: { int id = GUIUtility.GetControlID(EditorGUI.s_CurveHash, FocusType.Keyboard, position); EditorGUI.DoCurveField(EditorGUI.PrefixLabel(position, id, label), id, null, EditorGUI.kCurveColor, new Rect(), property); break; } case SerializedPropertyType.Gradient: { int id = GUIUtility.GetControlID(EditorGUI.s_CurveHash, FocusType.Keyboard, position); EditorGUI.DoGradientField(EditorGUI.PrefixLabel(position, id, label), id, null, property, false, ColorSpace.Gamma); break; } case SerializedPropertyType.Vector3: { EditorGUI.Vector3Field(position, property, label); break; } case SerializedPropertyType.Vector4: { EditorGUI.Vector4Field(position, property, label); break; } case SerializedPropertyType.Vector2: { EditorGUI.Vector2Field(position, property, label); break; } case SerializedPropertyType.Vector2Int: { EditorGUI.Vector2IntField(position, property, label); break; } case SerializedPropertyType.Vector3Int: { EditorGUI.Vector3IntField(position, property, label); break; } case SerializedPropertyType.Rect: { EditorGUI.RectField(position, property, label); break; } case SerializedPropertyType.RectInt: { EditorGUI.RectIntField(position, property, label); break; } case SerializedPropertyType.Bounds: { EditorGUI.BoundsField(position, property, label); break; } case SerializedPropertyType.BoundsInt: { EditorGUI.BoundsIntField(position, property, label); break; } default: { int genericID = GUIUtility.GetControlID(EditorGUI.s_GenericField, FocusType.Keyboard, position); EditorGUI.PrefixLabel(position, genericID, label); break; } } } // Handle Foldout else { Event tempEvent = new Event(Event.current); // Handle the actual foldout first, since that's the one that supports keyboard control. // This makes it work more consistent with PrefixLabel. childrenAreExpanded = property.isExpanded; bool newChildrenAreExpanded = childrenAreExpanded; using (new EditorGUI.DisabledScope(!property.editable)) { GUIStyle foldoutStyle = (DragAndDrop.activeControlID == -10) ? EditorStyles.foldoutPreDrop : EditorStyles.foldout; newChildrenAreExpanded = EditorGUI.Foldout(position, childrenAreExpanded, EditorGUI.s_PropertyFieldTempContent, true, foldoutStyle); } if (childrenAreExpanded && property.isArray && property.arraySize > property.serializedObject.maxArraySizeForMultiEditing && property.serializedObject.isEditingMultipleObjects) { Rect boxRect = position; boxRect.xMin += EditorGUIUtility.labelWidth - EditorGUI.indent; EditorGUI.s_ArrayMultiInfoContent.text = EditorGUI.s_ArrayMultiInfoContent.tooltip = string.Format(EditorGUI.s_ArrayMultiInfoFormatString, property.serializedObject.maxArraySizeForMultiEditing); EditorGUI.LabelField(boxRect, GUIContent.none, EditorGUI.s_ArrayMultiInfoContent, EditorStyles.helpBox); } if (newChildrenAreExpanded != childrenAreExpanded) { // Recursive set expanded if (Event.current.alt) { EditorGUI.SetExpandedRecurse(property, newChildrenAreExpanded); } // Expand one element only else { property.isExpanded = newChildrenAreExpanded; } } childrenAreExpanded = newChildrenAreExpanded; // Check for drag & drop events here, to add objects to an array by dragging to the foldout. // The event may have already been used by the Foldout control above, but we want to also use it here, // so we use the event copy we made prior to calling the Foldout method. // We need to use last s_LastControlID here to ensure we do not break duplicate functionality (fix for case 598389) // If we called GetControlID here s_LastControlID would be incremented and would not longer be in sync with GUIUtililty.keyboardFocus that // is used for duplicating (See DoPropertyFieldKeyboardHandling) int id = EditorGUIUtility.s_LastControlID; switch (tempEvent.type) { case EventType.DragExited: if (GUI.enabled) { HandleUtility.Repaint(); } break; case EventType.DragUpdated: case EventType.DragPerform: if (position.Contains(tempEvent.mousePosition) && GUI.enabled) { Object[] references = DragAndDrop.objectReferences; // Check each single object, so we can add multiple objects in a single drag. Object[] oArray = new Object[1]; bool didAcceptDrag = false; foreach (Object o in references) { oArray[0] = o; Object validatedObject = EditorGUI.ValidateObjectFieldAssignment(oArray, null, property, EditorGUI.ObjectFieldValidatorOptions.None); if (validatedObject != null) { DragAndDrop.visualMode = DragAndDropVisualMode.Copy; if (tempEvent.type == EventType.DragPerform) { property.AppendFoldoutPPtrValue(validatedObject); didAcceptDrag = true; DragAndDrop.activeControlID = 0; } else { DragAndDrop.activeControlID = id; } } } if (didAcceptDrag) { GUI.changed = true; DragAndDrop.AcceptDrag(); } } break; } } EditorGUI.EndProperty(); return(childrenAreExpanded); }
public static bool DefaultPropertyField(Rect position, RuntimeSerializedProperty property, GUIContent label) { label = BeginProperty(position, label, property); System.Type propertyType = property.PropertyType; bool childrenAreExpanded = false; // Should we inline? All one-line vars as well as Vector2, Vector3, Rect and Bounds properties are inlined. if (!HasVisibleChildFields(property)) { if (propertyType == RuntimeSerializedPropertyType.Bool) { EditorGUI.BeginChangeCheck(); bool boolValue = EditorGUI.Toggle(position, label, property.BoolValue); if (EditorGUI.EndChangeCheck()) { property.BoolValue = boolValue; } } else if (propertyType == RuntimeSerializedPropertyType.Byte) { EditorGUI.BeginChangeCheck(); int intValue = EditorGUI.IntField(position, label, property.ByteValue); if (intValue >= byte.MaxValue) { intValue = byte.MaxValue; } else if (intValue <= byte.MinValue) { intValue = byte.MinValue; } if (EditorGUI.EndChangeCheck()) { property.ByteValue = (byte)intValue; } } else if (propertyType == RuntimeSerializedPropertyType.Char) { char[] value = new char[] { property.CharValue }; bool changed = GUI.changed; GUI.changed = false; string text = EditorGUI.TextField(position, label, new string(value)); if (GUI.changed) { if (text.Length == 1) { property.CharValue = (char)text[0]; } else { GUI.changed = false; } } GUI.changed |= changed; } else if (propertyType == RuntimeSerializedPropertyType.Short) { EditorGUI.BeginChangeCheck(); int intValue = EditorGUI.IntField(position, label, property.ShortValue); if (intValue >= short.MaxValue) { intValue = short.MaxValue; } else if (intValue <= short.MinValue) { intValue = short.MinValue; } if (EditorGUI.EndChangeCheck()) { property.ShortValue = (short)intValue; } } else if (propertyType == RuntimeSerializedPropertyType.Integer) { EditorGUI.BeginChangeCheck(); int intValue = EditorGUI.IntField(position, label, property.IntValue); if (EditorGUI.EndChangeCheck()) { property.IntValue = intValue; } } else if (propertyType == RuntimeSerializedPropertyType.Long) { EditorGUI.BeginChangeCheck(); long longValue = EditorGUI.LongField(position, label, property.LongValue); if (EditorGUI.EndChangeCheck()) { property.LongValue = longValue; } } else if (propertyType == RuntimeSerializedPropertyType.sByte) { EditorGUI.BeginChangeCheck(); int intValue = EditorGUI.IntField(position, label, property.sByteValue); if (intValue >= sbyte.MaxValue) { intValue = sbyte.MaxValue; } else if (intValue <= sbyte.MinValue) { intValue = sbyte.MinValue; } if (EditorGUI.EndChangeCheck()) { property.sByteValue = (sbyte)intValue; } } else if (propertyType == RuntimeSerializedPropertyType.uShort) { EditorGUI.BeginChangeCheck(); int intValue = EditorGUI.IntField(position, label, property.uShortValue); if (intValue >= ushort.MaxValue) { intValue = ushort.MaxValue; } else if (intValue <= ushort.MinValue) { intValue = ushort.MinValue; } if (EditorGUI.EndChangeCheck()) { property.uShortValue = (ushort)intValue; } } else if (propertyType == RuntimeSerializedPropertyType.uInteger) { EditorGUI.BeginChangeCheck(); long longValue = EditorGUI.LongField(position, label, property.uIntValue); if (longValue >= uint.MaxValue) { longValue = uint.MaxValue; } else if (longValue <= uint.MinValue) { longValue = uint.MinValue; } if (EditorGUI.EndChangeCheck()) { property.uIntValue = (uint)longValue; } } else if (propertyType == RuntimeSerializedPropertyType.uLong) { EditorGUI.BeginChangeCheck(); string stringValue = EditorGUI.TextField(position, label, property.uLongValue.ToString()); if (EditorGUI.EndChangeCheck()) { ulong ulongValue = property.uLongValue; if (ulong.TryParse(stringValue, out ulongValue)) { property.uLongValue = ulongValue; } } } else if (propertyType == RuntimeSerializedPropertyType.Float) { EditorGUI.BeginChangeCheck(); float floatValue = EditorGUI.FloatField(position, label, property.FloatValue); if (EditorGUI.EndChangeCheck()) { property.FloatValue = floatValue; } } else if (propertyType == RuntimeSerializedPropertyType.Double) { EditorGUI.BeginChangeCheck(); double doubleValue = EditorGUI.DoubleField(position, label, property.DoubleValue); if (EditorGUI.EndChangeCheck()) { property.DoubleValue = doubleValue; } } else if (propertyType == RuntimeSerializedPropertyType.String) { EditorGUI.BeginChangeCheck(); string stringValue = EditorGUI.TextField(position, label, property.StringValue); if (EditorGUI.EndChangeCheck()) { property.StringValue = stringValue; } } else if (propertyType == RuntimeSerializedPropertyType.Color) { EditorGUI.BeginChangeCheck(); Color colorValue = EditorGUI.ColorField(position, label, property.ColorValue); if (EditorGUI.EndChangeCheck()) { property.ColorValue = colorValue; } } else if (propertyType.IsSameOrSubclassOf(RuntimeSerializedPropertyType.Object)) { GUIStyle style = new GUIStyle(); style.richText = true; EditorGUI.LabelField(position, "<color=red>Reference type is not supported!</color>", style); } else if (propertyType == RuntimeSerializedPropertyType.LayerMask) { EditorGUI.BeginChangeCheck(); LayerMask layerMaskValue = property.LayerMaskValue; string[] displayedOptions = RuntimeSerializedProperty.GetLayerMaskNames(0); int num = EditorGUI.MaskField(position, label, layerMaskValue.value, displayedOptions); if (EditorGUI.EndChangeCheck()) { property.LayerMaskValue = num; } } else if (propertyType.IsEnum) { EditorGUI.BeginChangeCheck(); System.Enum enumValue = EditorGUI.EnumPopup(position, label, property.EnumValue); if (EditorGUI.EndChangeCheck()) { property.EnumValue = enumValue; } } else if (propertyType == RuntimeSerializedPropertyType.Vector2) { EditorGUI.BeginChangeCheck(); Vector2 vector2Value = EditorGUI.Vector2Field(position, label, property.Vector2Value); if (EditorGUI.EndChangeCheck()) { property.Vector2Value = vector2Value; } } else if (propertyType == RuntimeSerializedPropertyType.Vector3) { EditorGUI.BeginChangeCheck(); Vector3 vector3Value = EditorGUI.Vector3Field(position, label, property.Vector3Value); if (EditorGUI.EndChangeCheck()) { property.Vector3Value = vector3Value; } } else if (propertyType == RuntimeSerializedPropertyType.Vector4) { EditorGUI.BeginChangeCheck(); Vector4 vector4Value = EditorGUI.Vector4Field(position, label, property.Vector4Value); if (EditorGUI.EndChangeCheck()) { property.Vector4Value = vector4Value; } } else if (propertyType == RuntimeSerializedPropertyType.Rect) { EditorGUI.BeginChangeCheck(); Rect rectValue = EditorGUI.RectField(position, label, property.RectValue); if (EditorGUI.EndChangeCheck()) { property.RectValue = rectValue; } } else if (propertyType == RuntimeSerializedPropertyType.ArraySize) { EditorGUI.BeginChangeCheck(); int intValue = EasyGUI.ArraySizeField(position, label, property.ArraySize, EditorStyles.numberField); if (EditorGUI.EndChangeCheck()) { property.ArraySize = intValue; } } else if (propertyType == RuntimeSerializedPropertyType.AnimationCurve) { EditorGUI.BeginChangeCheck(); if (property.AnimationCurveValue == null) { property.AnimationCurveValue = new AnimationCurve(new Keyframe[] { new Keyframe(0, 1), new Keyframe(1, 1) }); } AnimationCurve animationCurveValue = EditorGUI.CurveField(position, label, property.AnimationCurveValue); if (EditorGUI.EndChangeCheck()) { property.AnimationCurveValue = animationCurveValue; } } else if (propertyType == RuntimeSerializedPropertyType.Bounds) { EditorGUI.BeginChangeCheck(); Bounds boundsValue = EditorGUI.BoundsField(position, label, property.BoundsValue); if (EditorGUI.EndChangeCheck()) { property.BoundsValue = boundsValue; } } else if (propertyType == RuntimeSerializedPropertyType.Gradient) { EditorGUI.BeginChangeCheck(); Gradient gradientValue = EasyGUI.GradientField(label, position, property.GradientValue); if (EditorGUI.EndChangeCheck()) { property.GradientValue = gradientValue; } } else if (propertyType == RuntimeSerializedPropertyType.FixedBufferSize) { EditorGUI.IntField(position, label, property.IntValue); } else if (propertyType == RuntimeSerializedPropertyType.Vector2Int) { EditorGUI.BeginChangeCheck(); Vector2Int vector2IntValue = EditorGUI.Vector2IntField(position, label, property.Vector2IntValue); if (EditorGUI.EndChangeCheck()) { property.Vector2IntValue = vector2IntValue; } } else if (propertyType == RuntimeSerializedPropertyType.Vector3Int) { EditorGUI.BeginChangeCheck(); Vector3Int vector3IntValue = EditorGUI.Vector3IntField(position, label, property.Vector3IntValue); if (EditorGUI.EndChangeCheck()) { property.Vector3IntValue = vector3IntValue; } } else if (propertyType == RuntimeSerializedPropertyType.RectInt) { EditorGUI.BeginChangeCheck(); RectInt rectIntValue = EditorGUI.RectIntField(position, label, property.RectIntValue); if (EditorGUI.EndChangeCheck()) { property.RectIntValue = rectIntValue; } } else if (propertyType == RuntimeSerializedPropertyType.BoundsInt) { EditorGUI.BeginChangeCheck(); BoundsInt boundsIntValue = EditorGUI.BoundsIntField(position, label, property.BoundsIntValue); if (EditorGUI.EndChangeCheck()) { property.BoundsIntValue = boundsIntValue; } } else { int num = GUIUtility.GetControlID(s_GenericField, FocusType.Keyboard, position); EditorGUI.PrefixLabel(position, num, label); } } // Handle Foldout else { Event tempEvent = new Event(Event.current); // Handle the actual foldout first, since that's the one that supports keyboard control. // This makes it work more consistent with PrefixLabel. childrenAreExpanded = property.IsExpanded; bool newChildrenAreExpanded = childrenAreExpanded; using (new EditorGUI.DisabledScope(!property.Editable)) { GUIStyle foldoutStyle = (DragAndDrop.activeControlID != -10) ? EditorStyles.foldout : EditorStyles.foldoutPreDrop; newChildrenAreExpanded = EditorGUI.Foldout(position, childrenAreExpanded, s_PropertyFieldTempContent, true, foldoutStyle); } if (childrenAreExpanded && property.IsArray && property.ArraySize > property.RuntimeSerializedObject.SerializedObject.maxArraySizeForMultiEditing && property.RuntimeSerializedObject.SerializedObject.isEditingMultipleObjects) { Rect boxRect = position; boxRect.xMin += EditorGUIUtility.labelWidth - EasyGUI.Indent; s_ArrayMultiInfoContent.text = s_ArrayMultiInfoContent.tooltip = string.Format(s_ArrayMultiInfoFormatString, property.RuntimeSerializedObject.SerializedObject.maxArraySizeForMultiEditing); EditorGUI.LabelField(boxRect, GUIContent.none, s_ArrayMultiInfoContent, EditorStyles.helpBox); } if (newChildrenAreExpanded != childrenAreExpanded) { // Recursive set expanded if (Event.current.alt) { SetExpandedRecurse(property, newChildrenAreExpanded); } // Expand one element only else { property.IsExpanded = newChildrenAreExpanded; } } childrenAreExpanded = newChildrenAreExpanded; // Check for drag & drop events here, to add objects to an array by dragging to the foldout. // The event may have already been used by the Foldout control above, but we want to also use it here, // so we use the event copy we made prior to calling the Foldout method. // We need to use last s_LastControlID here to ensure we do not break duplicate functionality (fix for case 598389) // If we called GetControlID here s_LastControlID would be incremented and would not longer be in sync with GUIUtililty.keyboardFocus that // is used for duplicating (See DoPropertyFieldKeyboardHandling) int id = EditorGUIUtilityHelper.s_LastControlID; switch (tempEvent.type) { case EventType.DragExited: if (GUI.enabled) { HandleUtility.Repaint(); } break; case EventType.DragUpdated: case EventType.DragPerform: if (position.Contains(tempEvent.mousePosition) && GUI.enabled) { Object[] references = DragAndDrop.objectReferences; // Check each single object, so we can add multiple objects in a single drag. Object[] oArray = new Object[1]; bool didAcceptDrag = false; foreach (Object o in references) { oArray[0] = o; Object validatedObject = ValidateObjectFieldAssignment(oArray, null, property, EasyGUI.ObjectFieldValidatorOptions.None); if (validatedObject != null) { DragAndDrop.visualMode = DragAndDropVisualMode.Copy; if (tempEvent.type == EventType.DragPerform) { property.AppendFoldoutPPtrValue(validatedObject); didAcceptDrag = true; DragAndDrop.activeControlID = 0; } else { DragAndDrop.activeControlID = id; } } } if (didAcceptDrag) { GUI.changed = true; DragAndDrop.AcceptDrag(); } } break; } } EndProperty(); return(childrenAreExpanded); }
public override void OnGUI(Rect position, ReflectedProperty property, GUIContent label = null) { property.Value = EditorGUI.BoundsIntField(position, label, (BoundsInt)property.Value); }
public static void PropertyField(Rect position, SerializedProperty property, GUIContent label, bool includeChildren = false) { if (includeChildren || property.propertyType == SerializedPropertyType.Generic) { property.isExpanded = EditorGUILayout.Foldout(property.isExpanded, property.displayName); if (includeChildren && property.isExpanded) { foreach (SerializedProperty childProperty in property) { PropertyField(position, childProperty, new GUIContent(property.displayName), false); } } return; } switch (property.propertyType) { case SerializedPropertyType.AnimationCurve: property.animationCurveValue = EditorGUI.CurveField(position, label, property.animationCurveValue); break; case SerializedPropertyType.ArraySize: property.intValue = EditorGUI.DelayedIntField(position, label, property.intValue); break; case SerializedPropertyType.Boolean: property.boolValue = EditorGUI.Toggle(position, label, property.boolValue); break; case SerializedPropertyType.Bounds: property.boundsValue = EditorGUI.BoundsField(position, label, property.boundsValue); break; case SerializedPropertyType.BoundsInt: property.boundsIntValue = EditorGUI.BoundsIntField(position, label, property.boundsIntValue); break; case SerializedPropertyType.Character: string newValue = EditorGUI.TextField(position, label, new string(new char[] { (char)property.intValue })); property.intValue = newValue.Length > 0 ? newValue[0] : '\0'; break; case SerializedPropertyType.Color: property.colorValue = EditorGUI.ColorField(position, label, property.colorValue); break; case SerializedPropertyType.Enum: GUIContent[] displayNames = property.enumDisplayNames.Select(name => new GUIContent(name)).ToArray(); property.enumValueIndex = EditorGUI.Popup(position, label, property.enumValueIndex, displayNames); break; case SerializedPropertyType.ExposedReference: property.exposedReferenceValue = EditorGUI.ObjectField(position, label, property.objectReferenceValue, ReflectionExtensions.GetType(property), true); break; case SerializedPropertyType.Float: property.floatValue = EditorGUI.FloatField(position, label, property.floatValue); break; case SerializedPropertyType.Integer: property.intValue = EditorGUI.IntField(position, label, property.intValue); break; case SerializedPropertyType.LayerMask: MethodInfo method = typeof(EditorGUI).GetMethods(BindingFlags.NonPublic | BindingFlags.Static).First(t => t.Name == "LayerMaskField"); method.Invoke(null, new object[] { position, property, label }); break; case SerializedPropertyType.ObjectReference: property.objectReferenceValue = EditorGUI.ObjectField(position, label, property.objectReferenceValue, ReflectionExtensions.GetType(property), true); break; case SerializedPropertyType.Quaternion: Quaternion quaternion = property.quaternionValue; Vector4 quaternionValues = new Vector4(quaternion.x, quaternion.y, quaternion.z, quaternion.w); quaternionValues = EditorGUI.Vector4Field(position, label, quaternionValues); property.quaternionValue = new Quaternion(quaternionValues.x, quaternionValues.y, quaternionValues.z, quaternionValues.w); break; case SerializedPropertyType.Rect: property.rectValue = EditorGUI.RectField(position, label, property.rectValue); break; case SerializedPropertyType.RectInt: property.rectIntValue = EditorGUI.RectIntField(position, label, property.rectIntValue); break; case SerializedPropertyType.String: property.stringValue = EditorGUI.TextField(position, label, property.stringValue); break; case SerializedPropertyType.Vector2: property.vector2Value = EditorGUI.Vector2Field(position, label, property.vector2Value); break; case SerializedPropertyType.Vector2Int: property.vector2IntValue = EditorGUI.Vector2IntField(position, label, property.vector2IntValue); break; case SerializedPropertyType.Vector3: property.vector3Value = EditorGUI.Vector3Field(position, label, property.vector3Value); break; case SerializedPropertyType.Vector3Int: property.vector3IntValue = EditorGUI.Vector3IntField(position, label, property.vector3IntValue); break; case SerializedPropertyType.Vector4: property.vector4Value = EditorGUI.Vector4Field(position, label, property.vector4Value); break; /* * case SerializedPropertyType.Gradient: * var method = typeof(EditorGUI).GetMethods(BindingFlags.NonPublic | BindingFlags.Static).First(t => t.Name == "GradientField"); * var change = m.Invoke(null, new object[] { rect, gradient }); * method = typeof(EditorGUI).GetMethods(BindingFlags.NonPublic | BindingFlags.Static).First(t => t.Name == "DefaultPropertyField"); * method.Invoke(null, new object[] { position, property, label }); * break; */ default: Debug.LogError("SerializedPropertyType: " + property.propertyType + " not handled"); break; } }
public override void Draw(CutsceneEditor editor, CutscenePlayer player, Cutscene cutscene, Rect rect, int tokenIndex, GUIContent name, BoundsInt value, Type valueType, FieldInfo fieldInfo, Setter setter) { setter(EditorGUI.BoundsIntField(rect, name, value)); }
public static T FieldReturnDoNotSet <T>(this SerializedProperty property, GUIContent label, Rect area) { if (typeof(T) == typeof(float)) { return((T)(object)EditorGUI.FloatField(area, label, property.floatValue)); } if (typeof(T) == typeof(long)) { return((T)(object)EditorGUI.LongField(area, label, property.longValue)); } if (typeof(T) == typeof(uint)) { return((T)(object)(uint)EditorGUI.LongField(area, label, property.longValue)); } if (typeof(T) == typeof(int)) { return((T)(object)EditorGUI.IntField(area, label, property.intValue)); } if (typeof(T) == typeof(Vector2)) { return((T)(object)EditorGUI.Vector2Field(area, label, property.vector2Value)); } if (typeof(T) == typeof(Vector3)) { return((T)(object)EditorGUI.Vector3Field(area, label, property.vector3Value)); } if (typeof(T) == typeof(Vector2Int)) { return((T)(object)EditorGUI.Vector2IntField(area, label, property.vector2IntValue)); } if (typeof(T) == typeof(Vector3Int)) { return((T)(object)EditorGUI.Vector3IntField(area, label, property.vector3IntValue)); } if (typeof(T) == typeof(byte)) { return((T)(object)(byte)EditorGUI.IntField(area, label, property.intValue)); } if (typeof(T) == typeof(bool)) { return((T)(object)EditorGUI.ToggleLeft(area, label, property.boolValue)); } if (typeof(T) == typeof(string)) { return((T)(object)EditorGUI.TextField(area, label, property.stringValue)); } if (typeof(T) == typeof(Color)) { return((T)(object)EditorGUI.ColorField(area, label, property.colorValue)); } if (typeof(T) == typeof(AnimationCurve)) { return((T)(object)EditorGUI.CurveField(area, label, property.animationCurveValue)); } if (typeof(T) == typeof(Bounds)) { return((T)(object)EditorGUI.BoundsField(area, label, property.boundsValue)); } if (typeof(T) == typeof(BoundsInt)) { return((T)(object)EditorGUI.BoundsIntField(area, label, property.boundsIntValue)); } if (typeof(T) == typeof(double)) { return((T)(object)EditorGUI.DoubleField(area, label, property.doubleValue)); } if (typeof(T) == typeof(Vector4)) { return((T)(object)EditorGUI.Vector4Field(area, label, property.vector4Value)); } if (typeof(T) == typeof(Quaternion)) { return((T)(object)Quaternion.Euler((Vector3)(object)EditorGUI.Vector3Field(area, label, (property.quaternionValue).eulerAngles))); } if (typeof(T) == typeof(Rect)) { return((T)(object)EditorGUI.RectField(area, label, property.rectValue)); } if (typeof(T) == typeof(RectInt)) { return((T)(object)EditorGUI.RectIntField(area, label, property.rectIntValue)); } if (typeof(T) == typeof(Object)) { return((T)(object)EditorGUI.ObjectField(area, label, property.objectReferenceValue, typeof(T), true)); } Debug.LogError($"Field not implemented for type {typeof( T )}"); return(default(T)); }
public static T FieldOf <T>(this Rect area, GUIContent label, T value) { if (typeof(T) == typeof(float)) { return((T)(object)EditorGUI.FloatField(area, label, (float)(object)value)); } if (typeof(T) == typeof(long)) { return((T)(object)EditorGUI.LongField(area, label, (long)(object)value)); } if (typeof(T) == typeof(uint)) { return((T)(object)(uint)EditorGUI.LongField(area, label, (uint)(object)value)); } if (typeof(T) == typeof(int)) { return((T)(object)EditorGUI.IntField(area, label, (int)(object)value)); } if (typeof(T) == typeof(Vector2)) { return((T)(object)EditorGUI.Vector2Field(area, label, (Vector2)(object)value)); } if (typeof(T) == typeof(Vector3)) { return((T)(object)EditorGUI.Vector3Field(area, label, (Vector3)(object)value)); } if (typeof(T) == typeof(Vector2Int)) { return((T)(object)EditorGUI.Vector2IntField(area, label, (Vector2Int)(object)value)); } if (typeof(T) == typeof(Vector3Int)) { return((T)(object)EditorGUI.Vector3IntField(area, label, (Vector3Int)(object)value)); } if (typeof(T) == typeof(byte)) { return((T)(object)(byte)EditorGUI.IntField(area, label, (byte)(object)value)); } if (typeof(T) == typeof(bool)) { return((T)(object)EditorGUI.ToggleLeft(area, label, (bool)(object)value)); } if (typeof(T) == typeof(string)) { return((T)(object)EditorGUI.TextField(area, label, (string)(object)value)); } if (typeof(T) == typeof(Color)) { return((T)(object)EditorGUI.ColorField(area, label, (Color)(object)value)); } if (typeof(T) == typeof(AnimationCurve)) { return((T)(object)EditorGUI.CurveField(area, label, (AnimationCurve)(object)value)); } if (typeof(T) == typeof(Bounds)) { return((T)(object)EditorGUI.BoundsField(area, label, (Bounds)(object)value)); } if (typeof(T) == typeof(BoundsInt)) { return((T)(object)EditorGUI.BoundsIntField(area, label, (BoundsInt)(object)value)); } if (typeof(T) == typeof(double)) { return((T)(object)EditorGUI.DoubleField(area, label, (double)(object)value)); } if (typeof(T) == typeof(Vector4)) { return((T)(object)EditorGUI.Vector4Field(area, label, (Vector4)(object)value)); } if (typeof(T) == typeof(Quaternion)) { return((T)(object)Quaternion.Euler((Vector3)(object)EditorGUI.Vector3Field(area, label, ((Quaternion)(object)value).eulerAngles))); } if (typeof(T) == typeof(Rect)) { return((T)(object)EditorGUI.RectField(area, label, (Rect)(object)value)); } if (typeof(T) == typeof(RectInt)) { return((T)(object)EditorGUI.RectIntField(area, label, (RectInt)(object)value)); } if (typeof(T) == typeof(Object)) { return((T)(object)EditorGUI.ObjectField(area, label, (Object)(object)value, typeof(T), true)); } Debug.LogError($"Field not implemented for type {typeof( T )}"); return(default(T)); }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { EditorGUI.PropertyField(position, property, label, true); if (property.objectReferenceValue == null) { return; } position.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; position.x += 15f; position.width -= 15f; foldout = EditorGUI.Foldout(new Rect(position.x, position.y, position.width, EditorGUIUtility.singleLineHeight), foldout, ""); EditorGUI.LabelField(position, "Preview"); if (!foldout) { return; } position.y += EditorGUIUtility.singleLineHeight; System.Type type = property.objectReferenceValue.GetType(); if (type == typeof(Sprite)) { Texture texture = (property.objectReferenceValue as Sprite).texture; EditorGUI.LabelField(position, new GUIContent(texture)); position.y += EditorGUIUtility.standardVerticalSpacing; } else if (type == typeof(Texture)) { Texture texture = (property.objectReferenceValue as Texture); EditorGUI.LabelField(position, new GUIContent(texture)); position.y += EditorGUIUtility.standardVerticalSpacing; } else if (type.IsSubclassOf(typeof(ScriptableObject))) { position.y += EditorGUIUtility.standardVerticalSpacing; EditorGUI.BeginDisabledGroup(true); position.height = EditorGUIUtility.singleLineHeight; var fields = type.GetFields(); foreach (var field in fields) { Object obj = property.objectReferenceValue; object value = field.GetValue(obj); System.Type baseType = (field.FieldType.BaseType != typeof(System.ValueType)) ? field.FieldType.BaseType : field.FieldType; switch (baseType.Name) { case "SByte": EditorGUI.IntField(position, field.Name, (sbyte)value); break; case "Char": EditorGUI.TextField(position, field.Name, ((char)value).ToString()); break; case "Int16": EditorGUI.IntField(position, field.Name, (short)value); break; case "Int32": EditorGUI.IntField(position, field.Name, (int)value); break; case "Int64": EditorGUI.LongField(position, field.Name, (long)value); break; case "Byte": EditorGUI.IntField(position, field.Name, (byte)value); break; case "UInt16": EditorGUI.IntField(position, field.Name, (ushort)value); break; case "UInt32": EditorGUI.LongField(position, field.Name, (uint)value); break; case "float": EditorGUI.FloatField(position, field.Name, (float)value); break; case "Single": EditorGUI.FloatField(position, field.Name, (float)((System.Single)value)); break; case "Boolean": EditorGUI.Toggle(position, field.Name, (bool)value); break; case "Enum": EditorGUI.EnumFlagsField(position, field.Name, (System.Enum)value); break; case "Vector2": EditorGUI.Vector2Field(position, field.Name, (Vector2)value); break; case "Vector2Int": EditorGUI.Vector2IntField(position, field.Name, (Vector2Int)value); break; case "Vector3": EditorGUI.Vector3Field(position, field.Name, (Vector3)value); break; case "Vector3Int": EditorGUI.Vector3IntField(position, field.Name, (Vector3Int)value); break; case "Vector4": EditorGUI.Vector4Field(position, field.Name, (Vector4)value); break; case "Rect": EditorGUI.RectField(position, field.Name, (Rect)value); break; case "RectInt": EditorGUI.RectIntField(position, field.Name, (RectInt)value); break; case "Bounds": EditorGUI.BoundsField(position, field.Name, (Bounds)value); break; case "BoundsInt": EditorGUI.BoundsIntField(position, field.Name, (BoundsInt)value); break; case "Color": EditorGUI.ColorField(position, field.Name, (Color)value); break; case "Gradient": EditorGUI.GradientField(position, field.Name, (Gradient)value); break; case "AnimationCurve": EditorGUI.CurveField(position, field.Name, (AnimationCurve)value); break; case "Object": EditorGUI.ObjectField(position, field.Name, (Object)value, field.FieldType, true); if (field.FieldType == typeof(Sprite)) { position.y += EditorGUIUtility.singleLineHeight; Texture texture = (value as Sprite).texture; EditorGUI.LabelField(position, new GUIContent(texture)); position.y += EditorGUIUtility.standardVerticalSpacing; } else if (field.FieldType == typeof(Texture)) { position.y += EditorGUIUtility.singleLineHeight; Texture texture = (value as Texture); EditorGUI.LabelField(position, new GUIContent(texture)); position.y += EditorGUIUtility.standardVerticalSpacing; } break; case "Range": Range range = (Range)value; RangeDrawer.Draw(position, range, new GUIContent(field.Name)); break; default: EditorGUI.LabelField(position, field.Name); position.x += EditorGUIUtility.labelWidth; EditorGUI.HelpBox(position, "Cannot draw property field type: " + field.FieldType, MessageType.Error); position.x -= EditorGUIUtility.labelWidth; break; } position.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; } EditorGUI.EndDisabledGroup(); } else { position.y += EditorGUIUtility.standardVerticalSpacing; position.yMax -= EditorGUIUtility.singleLineHeight * 1.5f; EditorGUI.HelpBox(position, "Use Preview only with type Sprite, Texture or ScriptableObject.", MessageType.Error); } }
private static VariableValue DrawIntBounds(Rect rect, VariableValue value) { var result = EditorGUI.BoundsIntField(rect, GUIContent.none, value.IntBounds); return(VariableValue.Create(result)); }
public override void Draw(Rect rect, GUIContent name, BoundsInt value, Type valueType, FieldInfo fieldInfo, Setter setter) { setter(EditorGUI.BoundsIntField(rect, name, value)); }
private void InitVarsList() { reorderableList = new ReorderableList(serializedObject, pLuaInitialVars, true, true, true, true); reorderableList.elementHeight = 66; reorderableList.drawElementCallback = (rect, index, isActive, isFocused) => { var ptargetElement = pLuaInitialVars.GetArrayElementAtIndex(index); if (ptargetElement != null) { var pName = ptargetElement.FindPropertyRelative("Name"); var pType = ptargetElement.FindPropertyRelative("Type"); rect.x += 15; rect.height = 18; rect.width -= 30; var eType = (LuaVarObjectType)pType.enumValueIndex; SerializedProperty pVal = null; EditorGUI.PropertyField(rect, pName); rect.y += 20; EditorGUI.PropertyField(rect, pType); rect.y += 20; switch (eType) { case LuaVarObjectType.None: break; case LuaVarObjectType.Vector2: pVal = ptargetElement.FindPropertyRelative("vector2"); pVal.vector2Value = EditorGUI.Vector2Field(rect, "vector2", pVal.vector2Value); break; case LuaVarObjectType.Vector2Int: pVal = ptargetElement.FindPropertyRelative("vector2Int"); pVal.vector2IntValue = EditorGUI.Vector2IntField(rect, "vector2Int", pVal.vector2IntValue); break; case LuaVarObjectType.Vector3: pVal = ptargetElement.FindPropertyRelative("vector3"); pVal.vector3Value = EditorGUI.Vector3Field(rect, "vector3", pVal.vector3Value); break; case LuaVarObjectType.Vector3Int: pVal = ptargetElement.FindPropertyRelative("vector3Int"); pVal.vector3IntValue = EditorGUI.Vector3IntField(rect, "vector3Int", pVal.vector3IntValue); break; case LuaVarObjectType.Vector4: pVal = ptargetElement.FindPropertyRelative("vector4"); pVal.vector4Value = EditorGUI.Vector4Field(rect, "vector4", pVal.vector4Value); break; case LuaVarObjectType.Rect: pVal = ptargetElement.FindPropertyRelative("vector4"); pVal.vector4Value = EditorGUI.Vector4Field(rect, "vector4", pVal.vector4Value); break; case LuaVarObjectType.RectInt: pVal = ptargetElement.FindPropertyRelative("vector4"); pVal.vector4Value = EditorGUI.Vector4Field(rect, "vector4", pVal.vector4Value); break; case LuaVarObjectType.Gradient: pVal = ptargetElement.FindPropertyRelative("gradient"); EditorGUI.PropertyField(rect, pVal); break; case LuaVarObjectType.Layer: pVal = ptargetElement.FindPropertyRelative("layer"); pVal.intValue = EditorGUI.LayerField(rect, "layer", pVal.intValue); break; case LuaVarObjectType.Curve: pVal = ptargetElement.FindPropertyRelative("curve"); pVal.animationCurveValue = EditorGUI.CurveField(rect, "curve", pVal.animationCurveValue); break; case LuaVarObjectType.Color: pVal = ptargetElement.FindPropertyRelative("color"); pVal.colorValue = EditorGUI.ColorField(rect, "color", pVal.colorValue); break; case LuaVarObjectType.BoundsInt: pVal = ptargetElement.FindPropertyRelative("boundsInt"); pVal.boundsIntValue = EditorGUI.BoundsIntField(rect, "boundsInt", pVal.boundsIntValue); break; case LuaVarObjectType.Bounds: pVal = ptargetElement.FindPropertyRelative("bounds"); pVal.boundsValue = EditorGUI.BoundsField(rect, "bounds", pVal.boundsValue); break; case LuaVarObjectType.Object: pVal = ptargetElement.FindPropertyRelative("objectVal"); EditorGUI.ObjectField(rect, pVal); break; case LuaVarObjectType.GameObject: pVal = ptargetElement.FindPropertyRelative("gameObjectVal"); EditorGUI.ObjectField(rect, pVal); break; case LuaVarObjectType.Long: pVal = ptargetElement.FindPropertyRelative("longVal"); pVal.longValue = EditorGUI.LongField(rect, "longVal", pVal.longValue); break; case LuaVarObjectType.Int: pVal = ptargetElement.FindPropertyRelative("intVal"); pVal.intValue = EditorGUI.IntField(rect, "intVal", pVal.intValue); break; case LuaVarObjectType.String: pVal = ptargetElement.FindPropertyRelative("stringVal"); pVal.stringValue = EditorGUI.TextField(rect, "stringVal", pVal.stringValue); break; case LuaVarObjectType.Double: pVal = ptargetElement.FindPropertyRelative("doubleVal"); pVal.doubleValue = EditorGUI.DoubleField(rect, "doubleVal", pVal.doubleValue); break; case LuaVarObjectType.Bool: pVal = ptargetElement.FindPropertyRelative("boolVal"); pVal.boolValue = EditorGUI.Toggle(rect, "boolVal", pVal.boolValue); break; } rect.y += 20; if (isFocused && EditorApplication.isPlaying) { float w2 = rect.width / 2; rect.width -= w2; if (GUI.Button(rect, "UpdateVarFromLua")) { myScript.UpdateVarFromLua(myScript.LuaInitialVars[index]); } rect.x += w2; if (GUI.Button(rect, "UpdateVarToLua")) { myScript.UpdateVarToLua(myScript.LuaInitialVars[index]); } } } }; reorderableList.drawElementBackgroundCallback = (rect, index, isActive, isFocused) => { if (styleHighlight == null) { styleHighlight = GUI.skin.FindStyle("MeTransitionSelectHead"); } if (isFocused == false) { return; } rect.height = 66; GUI.Box(rect, GUIContent.none, styleHighlight); }; reorderableList.drawHeaderCallback = (rect) => EditorGUI.LabelField(rect, pLuaInitialVars.displayName); }
private void _drawValue(ref Rect rect, ValueS valueS) { rect.size = new Vector2(rect.width - (70 + 30 + 10 + 30) // subtract EditValue and Refresh and Remove Button , rect.height); //todo draw Value if (valueS.IsUnity) { var offset = new Vector2(15, 0); rect.position -= offset; //subtract offset rect.size += new Vector2(70, 0); // no Edit Value Button Object obj; EditorGUI.BeginChangeCheck(); { obj = EditorGUI.ObjectField(rect, valueS.UValue, valueS.ValueType, false); } if (EditorGUI.EndChangeCheck()) { valueS.SetValue(obj); Save(); } } else { //todo non Unity Type var value = valueS.GetValue(); if (value == null) { valueS.SetValue(Activator.CreateInstance(valueS.ValueType)); Save(); } _drawNonUnityValue <int>(ref rect, valueS, (pos, x) => EditorGUI.DelayedIntField(pos, (int)x.GetValue())); _drawNonUnityValue <float>(ref rect, valueS, (pos, x) => EditorGUI.DelayedFloatField(pos, (float)x.GetValue())); _drawNonUnityValue <double>(ref rect, valueS, (pos, x) => EditorGUI.DelayedDoubleField(pos, (double)x.GetValue())); _drawNonUnityValue <long>(ref rect, valueS, (pos, x) => EditorGUI.LongField(pos, (long)x.GetValue())); _drawNonUnityValue <string>(ref rect, valueS, (pos, x) => EditorGUI.DelayedTextField(pos, (string)x.GetValue())); _drawNonUnityValue <Vector2>(ref rect, valueS, (pos, x) => EditorGUI.Vector2Field(pos, "", (Vector2)x.GetValue())); _drawNonUnityValue <Vector2Int>(ref rect, valueS, (pos, x) => EditorGUI.Vector2IntField(pos, "", (Vector2Int)x.GetValue())); _drawNonUnityValue <Vector3>(ref rect, valueS, (pos, x) => EditorGUI.Vector3Field(pos, "", (Vector3)x.GetValue())); _drawNonUnityValue <Vector3Int>(ref rect, valueS, (pos, x) => EditorGUI.Vector3IntField(pos, "", (Vector3Int)x.GetValue())); _drawNonUnityValue <Vector4>(ref rect, valueS, (pos, x) => EditorGUI.Vector4Field(pos, "", (Vector4)x.GetValue())); _drawNonUnityValue <Color>(ref rect, valueS, (pos, x) => EditorGUI.ColorField(pos, (Color)x.GetValue())); _drawNonUnityValue <AnimationCurve>(ref rect, valueS, (pos, x) => EditorGUI.CurveField(pos, (AnimationCurve)x.GetValue())); _drawNonUnityValue <Bounds>(ref rect, valueS, (pos, x) => EditorGUI.BoundsField(pos, (Bounds)x.GetValue())); _drawNonUnityValue <BoundsInt>(ref rect, valueS, (pos, x) => EditorGUI.BoundsIntField(pos, (BoundsInt)x.GetValue())); _drawNonUnityValue <Rect>(ref rect, valueS, (pos, x) => EditorGUI.RectField(pos, (Rect)x.GetValue())); _drawNonUnityValue <RectInt>(ref rect, valueS, (pos, x) => EditorGUI.RectIntField(pos, (RectInt)x.GetValue())); _drawNonUnityValue <Enum>(ref rect, valueS, (pos, x) => EditorGUI.EnumFlagsField(pos, (Enum)x.GetValue())); _drawNonUnityValue <Gradient>(ref rect, valueS, (pos, x) => EditorGUI.GradientField(pos, (Gradient)x.GetValue())); rect.size = new Vector2(70, 26); if (GUI.Button(rect, "Edit Value")) { _valueEditPopup.ValueS = valueS; var pos = rect; PopupWindow.Show(pos, _valueEditPopup); } } rect.position += new Vector2(rect.size.x + 10, 0); }
/// <summary> /// Makes the appropriate fields for the specified object type. /// </summary> /// <returns> Changed value of the object. </returns> public static object GenericObjectField(Rect position, object value) { object changedValue = null; switch (value) { case bool boolValue: changedValue = EditorGUI.Toggle(position, boolValue); break; case int intValue: changedValue = EditorGUI.IntField(position, intValue); break; case long longValue: changedValue = EditorGUI.LongField(position, longValue); break; case byte byteValue: changedValue = (byte)Mathf.Clamp(EditorGUI.IntField(position, byteValue), byte.MinValue, byte.MaxValue); break; case float floatValue: changedValue = EditorGUI.FloatField(position, floatValue); break; case double doubleValue: changedValue = EditorGUI.DoubleField(position, doubleValue); break; case string stringValue: changedValue = EditorGUI.TextField(position, stringValue); break; case Vector2 vector2Value: changedValue = EditorGUI.Vector2Field(position, GUIContent.none, vector2Value); break; case Vector3 vector3Value: changedValue = EditorGUI.Vector3Field(position, GUIContent.none, vector3Value); break; case Vector4 vector4Value: changedValue = EditorGUI.Vector4Field(position, GUIContent.none, vector4Value); break; case Vector2Int vector2IntValue: changedValue = EditorGUI.Vector2IntField(position, GUIContent.none, vector2IntValue); break; case Vector3Int vector3IntValue: changedValue = EditorGUI.Vector3IntField(position, GUIContent.none, vector3IntValue); break; case Quaternion quaternionValue: Vector3 vector3 = EditorGUI.Vector3Field(position, GUIContent.none, quaternionValue.eulerAngles); changedValue = Quaternion.Euler(vector3); break; case Rect rectValue: changedValue = EditorGUI.RectField(position, rectValue); break; case RectInt rectIntValue: changedValue = EditorGUI.RectIntField(position, rectIntValue); break; case Bounds boundsValue: changedValue = EditorGUI.BoundsField(position, boundsValue); break; case BoundsInt boundsIntValue: changedValue = EditorGUI.BoundsIntField(position, boundsIntValue); break; case Color colorValue: changedValue = EditorGUI.ColorField(position, colorValue); break; case Gradient gradientValue: changedValue = EditorGUI.GradientField(position, gradientValue); break; case Enum enumValue: if (Attribute.IsDefined(enumValue.GetType(), typeof(FlagsAttribute))) { changedValue = EditorGUI.EnumFlagsField(position, enumValue); } else { changedValue = EditorGUI.EnumPopup(position, enumValue); } break; case AnimationCurve animationCurveValue: changedValue = EditorGUI.CurveField(position, animationCurveValue); break; case LayerMask layerMaskValue: changedValue = (LayerMask)EditorGUI.MaskField(position, layerMaskValue, InternalEditorUtility.layers); break; } return(changedValue); }
// Draws the correct field for the parameter. private void DrawParameterField(ParameterInfo parameter) { Rect position = _parameterRects[parameter.Position]; Type type = parameter.ParameterType; string name = ObjectNames.NicifyVariableName(parameter.Name); int index = parameter.Position; if (type == typeof(AnimationCurve)) { _targetEventEntry.ParameterValues[index] = EditorGUI.CurveField(position, name, (AnimationCurve)_targetEventEntry.ParameterValues[index]); } else if (type == typeof(bool)) { _targetEventEntry.ParameterValues[index] = EditorGUI.Toggle(position, name, (bool)_targetEventEntry.ParameterValues[index]); } else if (type == typeof(BoundsInt)) { _targetEventEntry.ParameterValues[index] = EditorGUI.BoundsIntField(position, name, (BoundsInt)_targetEventEntry.ParameterValues[index]); } else if (type == typeof(Bounds)) { _targetEventEntry.ParameterValues[index] = EditorGUI.BoundsField(position, name, (Bounds)_targetEventEntry.ParameterValues[index]); } else if (type == typeof(Color)) { _targetEventEntry.ParameterValues[index] = EditorGUI.ColorField(position, name, (Color)_targetEventEntry.ParameterValues[index]); } else if (type == typeof(double)) { _targetEventEntry.ParameterValues[index] = EditorGUI.DoubleField(position, name, (double)_targetEventEntry.ParameterValues[index]); } else if (type == typeof(float)) { _targetEventEntry.ParameterValues[index] = EditorGUI.FloatField(position, name, (float)_targetEventEntry.ParameterValues[index]); } else if (type == typeof(int)) { _targetEventEntry.ParameterValues[index] = EditorGUI.IntField(position, name, (int)_targetEventEntry.ParameterValues[index]); } else if (type == typeof(long)) { _targetEventEntry.ParameterValues[index] = EditorGUI.LongField(position, name, (long)_targetEventEntry.ParameterValues[index]); } else if (type == typeof(Quaternion)) { _targetEventEntry.ParameterValues[index] = EditorGUI.Vector4Field(position, name, (Vector4)_targetEventEntry.ParameterValues[index]); } else if (type == typeof(RectInt)) { _targetEventEntry.ParameterValues[index] = EditorGUI.RectIntField(position, name, (RectInt)_targetEventEntry.ParameterValues[index]); } else if (type == typeof(Rect)) { _targetEventEntry.ParameterValues[index] = EditorGUI.RectField(position, name, (Rect)_targetEventEntry.ParameterValues[index]); } else if (type == typeof(string)) { _targetEventEntry.ParameterValues[index] = EditorGUI.TextField(position, name, (string)_targetEventEntry.ParameterValues[index]); } else if (type == typeof(Vector2Int)) { _targetEventEntry.ParameterValues[index] = EditorGUI.Vector2IntField(position, name, (Vector2Int)_targetEventEntry.ParameterValues[index]); } else if (type == typeof(Vector2)) { _targetEventEntry.ParameterValues[index] = EditorGUI.Vector2Field(position, name, (Vector2)_targetEventEntry.ParameterValues[index]); } else if (type == typeof(Vector3Int)) { _targetEventEntry.ParameterValues[index] = EditorGUI.Vector3IntField(position, name, (Vector3Int)_targetEventEntry.ParameterValues[index]); } else if (type == typeof(Vector3)) { _targetEventEntry.ParameterValues[index] = EditorGUI.Vector3Field(position, name, (Vector3)_targetEventEntry.ParameterValues[index]); } else if (type == typeof(Vector4)) { _targetEventEntry.ParameterValues[index] = EditorGUI.Vector4Field(position, name, (Vector4)_targetEventEntry.ParameterValues[index]); } else if (type.IsEnum) { _targetEventEntry.ParameterValues[index] = EditorGUI.EnumPopup(position, name, (Enum)_targetEventEntry.ParameterValues[index]); } else if (type == typeof(Object)) { _targetEventEntry.ParameterValues[index] = EditorGUI.ObjectField(position, name, (Object)_targetEventEntry.ParameterValues[index], type, true); } else if (type.BaseType == typeof(Component)) { _targetEventEntry.ParameterValues[index] = EditorGUI.ObjectField(position, name, (Object)_targetEventEntry.ParameterValues[index], type, true); } }