public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { EditorGUIUtility.LookLikeControls(); position.xMin += 4; position.xMax -= 4; switch (property.propertyType) { case SerializedPropertyType.Vector4: property.vector4Value = EditorGUI.Vector4Field(position, label.text, property.vector4Value); break; case SerializedPropertyType.Vector3: property.vector3Value = EditorGUI.Vector3Field(position, label.text, property.vector3Value); break; case SerializedPropertyType.Vector2: property.vector2Value = EditorGUI.Vector2Field(position, label.text, property.vector2Value); break; case SerializedPropertyType.Rect: property.rectValue = EditorGUI.RectField(position, label.text, property.rectValue); break; case SerializedPropertyType.Bounds: EditorGUI.LabelField(position, label.text); position.y += 20; property.boundsValue = EditorGUI.BoundsField(position, property.boundsValue); break; } }
private static void Initialize() { valueFieldActions = new Dictionary <Type, Func <Rect, GUIContent, object, object> >(); valueFieldActions.Add(typeof(bool), (rect, label, obj) => EditorGUI.Toggle(rect, label, (bool)obj)); valueFieldActions.Add(typeof(int), (rect, label, obj) => EditorGUI.IntField(rect, label, (int)obj)); valueFieldActions.Add(typeof(long), (rect, label, obj) => EditorGUI.LongField(rect, label, (long)obj)); valueFieldActions.Add(typeof(uint), (rect, label, obj) => { var value = EditorGUI.LongField(rect, label, (uint)obj); if (value < 0) { value = 0; } if (value > uint.MaxValue) { value = uint.MaxValue; } return((uint)value); }); valueFieldActions.Add(typeof(float), (rect, label, obj) => EditorGUI.FloatField(rect, label, (float)obj)); valueFieldActions.Add(typeof(double), (rect, label, obj) => EditorGUI.DoubleField(rect, label, (double)obj)); valueFieldActions.Add(typeof(string), (rect, label, obj) => EditorGUI.TextField(rect, label, (string)obj)); valueFieldActions.Add(typeof(Vector2), (rect, label, obj) => EditorGUI.Vector2Field(rect, label, (Vector2)obj)); valueFieldActions.Add(typeof(Vector3), (rect, label, obj) => EditorGUI.Vector3Field(rect, label, (Vector3)obj)); valueFieldActions.Add(typeof(Vector4), (rect, label, obj) => EditorGUI.Vector4Field(rect, label, (Vector4)obj)); valueFieldActions.Add(typeof(Vector2Int), (rect, label, obj) => EditorGUI.Vector2IntField(rect, label, (Vector2Int)obj)); valueFieldActions.Add(typeof(Vector3Int), (rect, label, obj) => EditorGUI.Vector3IntField(rect, label, (Vector3Int)obj)); valueFieldActions.Add(typeof(Color), (rect, label, obj) => EditorGUI.ColorField(rect, label, (Color)obj)); valueFieldActions.Add(typeof(AnimationCurve), (rect, label, obj) => EditorGUI.CurveField(rect, label, (AnimationCurve)obj)); valueFieldActions.Add(typeof(Bounds), (rect, label, obj) => EditorGUI.BoundsField(rect, label, (Bounds)obj)); valueFieldActions.Add(typeof(Gradient), (rect, label, obj) => EditorGUI.GradientField(rect, label, (Gradient)obj)); valueFieldActions.Add(typeof(Rect), (rect, label, obj) => EditorGUI.RectField(rect, label, (Rect)obj)); // Add more when needed }
public override void OnGUI(Rect rect, string name, ref object value) { base.OnGUI(rect, name, ref value); EditorGUI.BeginDisabledGroup(IsReadOnly); EditorGUI.HandlePrefixLabel(rect, GetControlRect(), new GUIContent(name)); value = EditorGUI.BoundsField(GetControlRect(32), (Bounds)value); EditorGUI.EndDisabledGroup(); }
/*====================================* * Input Field *====================================*/ public void BoundsField() { EditorGUI.BeginChangeCheck(); Bounds bounds = EditorGUI.BoundsField(rect, guiContent.text, serializedProperty.boundsValue); if (EditorGUI.EndChangeCheck()) { serializedProperty.boundsValue = bounds; } }
public override void DoOnGUI(Rect position, SerializedProperty property, GUIContent label) { EditorGUI.BeginChangeCheck(); switch (property.type) { case sVector4: case sVector4f: { float vx = GetProperty(property, "x").floatValue; float vy = GetProperty(property, "y").floatValue; float vz = GetProperty(property, "z").floatValue; float vw = GetProperty(property, "w").floatValue; Vector4 vector4 = EditorGUI.Vector4Field(position, label.text, new Vector4(vx, vy, vz, vw)); if (EditorGUI.EndChangeCheck()) { GetProperty(property, "x").floatValue = vector4.x; GetProperty(property, "y").floatValue = vector4.y; GetProperty(property, "z").floatValue = vector4.z; GetProperty(property, "w").floatValue = vector4.w; } break; } case sQuaternion: case sQuaternionf: { Quaternion quaternion = property.quaternionValue; Vector4 vector4 = EditorGUI.Vector4Field(position, label.text, new Vector4(quaternion.x, quaternion.y, quaternion.z, quaternion.w)); if (EditorGUI.EndChangeCheck()) { property.quaternionValue = new Quaternion(vector4.x, vector4.y, vector4.z, vector4.w); } break; } case sBounds: case sAABB: { Bounds bounds = EditorGUI.BoundsField(position, label, property.boundsValue); if (EditorGUI.EndChangeCheck()) { property.boundsValue = bounds; } break; } default: { EditorGUI.LabelField(position, label.text, "Type not implemented"); EditorGUI.EndChangeCheck(); break; } } }
private static object DrawProperty(Rect position, SerializedPropertyType propertyType, Type type, object value, GUIContent label) { switch (propertyType) { case SerializedPropertyType.Integer: return(EditorGUI.IntField(position, label, (int)value)); case SerializedPropertyType.Boolean: return(EditorGUI.Toggle(position, label, (bool)value)); case SerializedPropertyType.Float: return(EditorGUI.FloatField(position, label, (float)value)); case SerializedPropertyType.String: return(EditorGUI.TextField(position, label, (string)value)); case SerializedPropertyType.Color: return(EditorGUI.ColorField(position, label, (Color)value)); case SerializedPropertyType.ObjectReference: return(EditorGUI.ObjectField(position, label, (UnityEngine.Object)value, type, true)); case SerializedPropertyType.ExposedReference: return(EditorGUI.ObjectField(position, label, (UnityEngine.Object)value, type, true)); case SerializedPropertyType.LayerMask: return(EditorGUI.LayerField(position, label, (int)value)); case SerializedPropertyType.Enum: return(EditorGUI.EnumPopup(position, label, (Enum)value)); case SerializedPropertyType.Vector2: return(EditorGUI.Vector2Field(position, label, (Vector2)value)); case SerializedPropertyType.Vector3: return(EditorGUI.Vector3Field(position, label, (Vector3)value)); case SerializedPropertyType.Vector4: return(EditorGUI.Vector4Field(position, label, (Vector4)value)); case SerializedPropertyType.Rect: return(EditorGUI.RectField(position, label, (Rect)value)); case SerializedPropertyType.AnimationCurve: return(EditorGUI.CurveField(position, label, (AnimationCurve)value)); case SerializedPropertyType.Bounds: return(EditorGUI.BoundsField(position, label, (Bounds)value)); default: throw new NotImplementedException("Unimplemented propertyType " + propertyType + "."); } }
protected override void OnControlGUI(Rect position) { EditorGUI.BeginChangeCheck(); var newValue = EditorGUI.BoundsField(position, (Bounds)accessor.value); if (EditorGUI.EndChangeCheck()) { accessor.RecordUndo(); accessor.value = newValue; } }
protected override void OnGUI(Rect position, GUIContent label) { position = BeginBlock(metadata, position, label); var newValue = EditorGUI.BoundsField(position, (Bounds)metadata.value); if (EndBlock(metadata)) { metadata.RecordUndo(); metadata.value = newValue; } }
public override Bounds BoundsField(GUIContent content, Bounds value, Layout option) { var bounds = new ControlData(content, GUIStyles.None, option, ControlType.Bounds); Rect position; if (CanDrawControl(out position, bounds)) { return(EditorGUI.BoundsField(position, content, value)); } return(value); }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { Tooltip tooltipAttribute = attribute as Tooltip; if (property.propertyType == SerializedPropertyType.AnimationCurve) { property.animationCurveValue = EditorGUI.CurveField(position, new GUIContent(label.text, tooltipAttribute._tip), property.animationCurveValue); } if (property.propertyType == SerializedPropertyType.Boolean) { property.boolValue = EditorGUI.Toggle(position, new GUIContent(label.text, tooltipAttribute._tip), property.boolValue); } if (property.propertyType == SerializedPropertyType.Bounds) { property.boundsValue = EditorGUI.BoundsField(position, new GUIContent(label.text, tooltipAttribute._tip), property.boundsValue); } if (property.propertyType == SerializedPropertyType.Color) { property.colorValue = EditorGUI.ColorField(position, new GUIContent(label.text, tooltipAttribute._tip), property.colorValue); } if (property.propertyType == SerializedPropertyType.Float) { property.floatValue = EditorGUI.FloatField(position, new GUIContent(label.text, tooltipAttribute._tip), property.floatValue); } if (property.propertyType == SerializedPropertyType.Integer) { property.intValue = EditorGUI.IntField(position, new GUIContent(label.text, tooltipAttribute._tip), property.intValue); } if (property.propertyType == SerializedPropertyType.Rect) { property.rectValue = EditorGUI.RectField(position, new GUIContent(label.text, tooltipAttribute._tip), property.rectValue); } if (property.propertyType == SerializedPropertyType.String) { property.stringValue = EditorGUI.TextField(position, new GUIContent(label.text, tooltipAttribute._tip), property.stringValue); } }
//<summary> в этом методе мы рисуем и отображаем поля свойствы класса </summary> private object DoFiled(Type type, object value, Rect position, ref float size) { object result = null; switch (type.Name) { case "Int32": result = EditorGUI.IntField(position, (int)value); size = 22; break; case "Single": result = EditorGUI.FloatField(position, (float)value); size = 22; break; case "Double": result = EditorGUI.DoubleField(position, (double)value); size = 22; break; case "Boolean": result = EditorGUI.Toggle(position, (bool)value); size = 22; break; case "String": result = EditorGUI.TextField(position, (string)value); size = 22; break; case "Vector2": result = EditorGUI.Vector2Field(position, GUIContent.none, (Vector2)value); size = 22; break; case "Rect": result = EditorGUI.RectField(position, (Rect)value); size = 42; break; case "Bounds": result = EditorGUI.BoundsField(position, (Bounds)value); size = 42; break; } if (result == null) { size = 22; if (type.IsEnum) { result = EditorGUI.EnumPopup(position, (Enum)(object)value); } if (type.IsArray) { EditorGUI.LabelField(position, "Data array is not displayed"); } if (typeof(IList).IsAssignableFrom(type) && type.Name == "List`1") { IList list = value as IList; result = EditorGUI.IntField(position, list.Count); } } return(result); }
void OnGUI() { EditorGUI.BeginChangeCheck(); _bound = EditorGUI.BoundsField(new Rect(5, 5, 200, 34), _bound); if (EditorGUI.EndChangeCheck()) { ShowNotification(new GUIContent("Something changed.")); } _color = EditorGUI.ColorField(new Rect(5, 44, 200, 17), _color); EditorGUI.BeginChangeCheck(); _int = EditorGUI.IntSlider(new Rect(5, 66, 200, 17), _int, -5, 5); if (EditorGUI.EndChangeCheck()) { ShowNotification(new GUIContent("Something changed.")); } }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { EditorGUI.BeginProperty(position, label, property); var minx = property.FindPropertyRelative("minimum").FindPropertyRelative("x").intValue; var miny = property.FindPropertyRelative("minimum").FindPropertyRelative("y").intValue; var minz = property.FindPropertyRelative("minimum").FindPropertyRelative("z").intValue; var maxx = property.FindPropertyRelative("maximum").FindPropertyRelative("x").intValue; var maxy = property.FindPropertyRelative("maximum").FindPropertyRelative("y").intValue; var maxz = property.FindPropertyRelative("maximum").FindPropertyRelative("z").intValue; var center = new Vector3((minx + maxx) / 2.0f, (miny + maxy) / 2.0f, (minz + maxz) / 2.0f); var size = new Vector3(maxx - minx, maxy - miny, maxz - minz); var bounds = new Bounds(center, size); EditorGUI.BoundsField(position, label, bounds); EditorGUI.EndProperty(); }
protected void DrawCondition(Rect pos, AmountCondition condition, GUIContent label) { InLine.SetRect(pos, 0, 0, 6); { condition.typeOfFind = (FindType)EditorGUI.EnumPopup(InLine.NextRect(), condition.typeOfFind); switch (condition.typeOfFind) { case FindType.Tag: condition.checkTag = EditorGUI.TagField(InLine.NextRect(), condition.checkTag); break; case FindType.Layer: condition.layer = EditorGUI.MaskField(InLine.NextRect(), condition.layer, FindLayerNames()); break; case FindType.ByType: condition.typeTemplate = EditorGUI.ObjectField(InLine.NextRect(), condition.typeTemplate, typeof(UnityEngine.Object), true); if (condition.typeTemplate == null) { EditorGUILayout.HelpBox("A Amount Condition needs a type template", MessageType.Warning); } break; } EditorGUI.LabelField(InLine.GetLine(0, pos.width / 3, 5f), "Current", GUIStyle.none); EditorGUI.IntField(InLine.NextRect(), condition.numOfObjects, GUIStyle.none); } InLine.SetRect(pos, 1, 0, 6); { EditorGUI.LabelField(InLine.NextRect(), "Remaining"); condition.typeOfCompare = (CompareType)EditorGUI.EnumPopup(InLine.NextRect(), condition.typeOfCompare); condition.amount = EditorGUI.IntField(InLine.NextRect(), condition.amount); } condition.triggerArea = EditorGUI.BoundsField(InLine.GetLine(0, pos.width / 2, 1), condition.triggerArea); InLine.Reset(); }
protected void DrawCondition(Rect pos, AreaCondition condition, GUIContent label) { InLine.SetRect(pos, 0, 0, 6); { EditorGUI.LabelField(InLine.NextRect(), "Area"); } condition.triggerArea = EditorGUI.BoundsField(InLine.GetLine(0, pos.width / 2, 1), condition.triggerArea); InLine.SetRect(pos, 0, 50, 6); { EditorGUI.LabelField(InLine.NextRect(), "UsePlayer"); condition.UsePlayer = EditorGUI.Toggle(InLine.NextRect(true), condition.UsePlayer); } if (!condition.UsePlayer) { condition.checkObject = (GameObject)EditorGUI.ObjectField(InLine.GetLine(1, 0, 2), condition.checkObject, typeof(GameObject), true); if (!condition.checkObject) { EditorGUILayout.HelpBox("CheckObject is null for AreaCondition", MessageType.Warning); } } InLine.Reset(); }
public override void OnGUI(Rect position, ReflectedProperty property, GUIContent label = null) { property.Value = EditorGUI.BoundsField(position, label, (Bounds)property.Value); }
/// <summary> /// /// </summary> /// <returns></returns> protected override Bounds DrawAndUpdateValue() { return(EditorGUI.BoundsField(ScreenRect, new GUIContent(Label), m_cachedValue)); }
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 Draw(CutsceneEditor editor, CutscenePlayer player, Cutscene cutscene, Rect rect, int tokenIndex, GUIContent name, Bounds value, Type valueType, FieldInfo fieldInfo, Setter setter) { setter(EditorGUI.BoundsField(rect, name, value)); }
public static object ValueField(Rect rect, object value, Type type) { object newValue = value; GUIContent labelContent = GUIContent.none; var typeCode = SerializableValue.TypeToSerializableTypeCode(type); switch (typeCode) { case SerializableTypeCode.String: { string str = value as string; str = str ?? ""; newValue = EditorGUI.DelayedTextField(rect, str); } break; case SerializableTypeCode.Int32: { int n = (int)value; newValue = EditorGUI.DelayedIntField(rect, n); } break; case SerializableTypeCode.Single: { float f = (float)value; newValue = EditorGUI.DelayedFloatField(rect, f); } break; case SerializableTypeCode.Boolean: { bool b; b = (bool)value; newValue = EditorGUI.Toggle(rect, b); } break; case SerializableTypeCode.UnityObject: { UnityEngine.Object obj = value as UnityEngine.Object; newValue = EditorGUI.ObjectField(rect, obj, type, true); } break; case SerializableTypeCode.Vector2: { Vector2 v = (Vector2)value; newValue = EditorGUI.Vector2Field(rect, labelContent, v); } break; case SerializableTypeCode.Vector3: { Vector3 v = (Vector3)value; newValue = EditorGUI.Vector3Field(rect, labelContent, v); } break; case SerializableTypeCode.Vector4: { Vector4 v = (Vector4)value; newValue = EditorGUI.Vector4Field(rect, labelContent, v); } break; case SerializableTypeCode.Color: { Color v = (Color)value; newValue = EditorGUI.ColorField(rect, labelContent, v); } break; case SerializableTypeCode.Rect: { Rect v = (Rect)value; newValue = EditorGUI.RectField(rect, labelContent, v); } break; case SerializableTypeCode.Bounds: { Bounds v = (Bounds)value; newValue = EditorGUI.BoundsField(rect, labelContent, v); } break; case SerializableTypeCode.AnimationCurve: { AnimationCurve v = (AnimationCurve)value; newValue = EditorGUI.CurveField(rect, labelContent, v); } break; } return(newValue); }
protected void OnGUIOfPropertyType(SerializedPropertyType type, Rect rect, GUIContent label) { switch (type) { case SerializedPropertyType.AnimationCurve: EditorGUI.BeginChangeCheck(); GetAnimationCurve(); animationCurveValue = EditorGUI.CurveField(rect, label, animationCurveValue); if (EditorGUI.EndChangeCheck()) { SetAnimationCurve(); } return; case SerializedPropertyType.Boolean: EditorGUI.BeginChangeCheck(); GetBool(); boolValue = EditorGUI.Toggle(rect, label, boolValue); if (EditorGUI.EndChangeCheck()) { SetBool(); } return; case SerializedPropertyType.Bounds: EditorGUI.BeginChangeCheck(); GetBounds(); boundsValue = EditorGUI.BoundsField(rect, label, boundsValue); if (EditorGUI.EndChangeCheck()) { SetBounds(); } return; case SerializedPropertyType.Color: EditorGUI.BeginChangeCheck(); GetColor(); colorValue = EditorGUI.ColorField(rect, label, colorValue); if (EditorGUI.EndChangeCheck()) { SetColor(); } return; case SerializedPropertyType.Enum: EditorGUI.BeginChangeCheck(); GetEnum(); enumValue = EditorGUI.EnumPopup(rect, label, enumValue); if (EditorGUI.EndChangeCheck()) { SetEnum(); } return; case SerializedPropertyType.Float: EditorGUI.BeginChangeCheck(); GetFloat(); floatValue = EditorGUI.FloatField(rect, label, floatValue); if (EditorGUI.EndChangeCheck()) { SetFloat(); } return; case SerializedPropertyType.Integer: EditorGUI.BeginChangeCheck(); GetInt(); intValue = EditorGUI.IntField(rect, label, intValue); if (EditorGUI.EndChangeCheck()) { SetInt(); } return; case SerializedPropertyType.LayerMask: SerializedProperty property = BasePropertyDrawer.property; GetLayerMask(); EditorKit.LayerMaskField(rect, label, layerMaskValue, mask => { property.serializedObject.Update(); BasePropertyDrawer.property = property; layerMaskValue = mask; SetLayerMask(); property.serializedObject.ApplyModifiedProperties(); }); return; case SerializedPropertyType.ObjectReference: EditorGUI.BeginChangeCheck(); GetObjectReference(); objectReferenceValue = EditorGUI.ObjectField(rect, label, objectReferenceValue, fieldInfo.FieldType, !EditorUtility.IsPersistent(BasePropertyDrawer.property.serializedObject.targetObject)); if (EditorGUI.EndChangeCheck()) { SetObjectReference(); } return; case SerializedPropertyType.Rect: EditorGUI.BeginChangeCheck(); GetRect(); rectValue = EditorGUI.RectField(rect, label, rectValue); if (EditorGUI.EndChangeCheck()) { SetRect(); } return; case SerializedPropertyType.String: EditorGUI.BeginChangeCheck(); GetString(); stringValue = EditorGUI.TextField(rect, label, stringValue); if (EditorGUI.EndChangeCheck()) { SetString(); } return; case SerializedPropertyType.Vector2: EditorGUI.BeginChangeCheck(); GetVector2(); vector2Value = EditorGUI.Vector2Field(rect, label, vector2Value); if (EditorGUI.EndChangeCheck()) { SetVector2(); } return; case SerializedPropertyType.Vector3: EditorGUI.BeginChangeCheck(); GetVector3(); vector3Value = EditorGUI.Vector3Field(rect, label, vector3Value); if (EditorGUI.EndChangeCheck()) { SetVector3(); } return; case SerializedPropertyType.Vector4: EditorGUI.BeginChangeCheck(); GetVector4(); vector4Value = EditorGUI.Vector4Field(rect, label.text, vector4Value); if (EditorGUI.EndChangeCheck()) { SetVector4(); } return; default: EditorGUI.LabelField(rect, label.text, "Not supported"); return; } }
protected void DrawProperty(Rect pos, SerializedProperty prop, bool title) { GUIContent label = GUIContent.none; if (title) { label = new GUIContent(prop.displayName); } if (prop.propertyType == SerializedPropertyType.AnimationCurve) { prop.animationCurveValue = EditorGUI.CurveField(pos, label, prop.animationCurveValue); } else if (prop.propertyType == SerializedPropertyType.ArraySize) { } else if (prop.propertyType == SerializedPropertyType.Boolean) { prop.boolValue = EditorGUI.Toggle(pos, label, prop.boolValue); } else if (prop.propertyType == SerializedPropertyType.Bounds) { prop.boundsValue = EditorGUI.BoundsField(pos, label, prop.boundsValue); } else if (prop.propertyType == SerializedPropertyType.Character) { prop.intValue = EditorGUI.IntField(pos, label, prop.intValue); } else if (prop.propertyType == SerializedPropertyType.Color) { prop.colorValue = EditorGUI.ColorField(pos, label, prop.colorValue); } else if (prop.propertyType == SerializedPropertyType.Enum) { string[] optionNames = prop.enumNames; GUIContent[] options = new GUIContent[optionNames.Length]; for (int i = 0; i < optionNames.Length; i++) { options[i] = new GUIContent(optionNames[i]); } prop.enumValueIndex = EditorGUI.Popup(pos, label, prop.intValue, options); } else if (prop.propertyType == SerializedPropertyType.Float) { prop.floatValue = EditorGUI.FloatField(pos, label, prop.floatValue); // } else if (prop.propertyType == SerializedPropertyType.Generic) { // DrawGeneric(prop, pos); } else if (prop.propertyType == SerializedPropertyType.Gradient) { } else if (prop.propertyType == SerializedPropertyType.Integer) { prop.intValue = EditorGUI.IntField(pos, label, prop.intValue); } else if (prop.propertyType == SerializedPropertyType.LayerMask) { prop.intValue = EditorGUI.LayerField(pos, label, prop.intValue); } else if (prop.propertyType == SerializedPropertyType.ObjectReference) { prop.objectReferenceValue = EditorGUI.ObjectField(pos, label, prop.objectReferenceValue, Type.GetType(prop.type), true); } else if (prop.propertyType == SerializedPropertyType.Rect) { prop.rectValue = EditorGUI.RectField(pos, label, prop.rectValue); } else if (prop.propertyType == SerializedPropertyType.String) { prop.stringValue = EditorGUI.TextField(pos, label, prop.stringValue); } else if (prop.propertyType == SerializedPropertyType.Vector2) { prop.vector2Value = EditorGUI.Vector2Field(pos, label.text, prop.vector2Value); } else if (prop.propertyType == SerializedPropertyType.Vector3) { prop.vector3Value = EditorGUI.Vector2Field(pos, label.text, prop.vector3Value); } else if (prop.propertyType == SerializedPropertyType.Generic) { if (prop.type == typeof(Quaternion).ToString()) { DrawVec4(prop, label, pos); } } }
public static object DefaultPropertyField(Rect position, GUIContent label, object value, System.Type valueType) { var propertyType = (valueType != null) ? EditorHelper.GetPropertyType(valueType) : SerializedPropertyType.Generic; switch (propertyType) { case SerializedPropertyType.Integer: EditorGUI.BeginChangeCheck(); int num1 = EditorGUI.IntField(position, label, ConvertUtil.ToInt(value)); if (EditorGUI.EndChangeCheck()) { return(num1); } else { break; } case SerializedPropertyType.Boolean: EditorGUI.BeginChangeCheck(); bool flag2 = EditorGUI.Toggle(position, label, ConvertUtil.ToBool(value)); if (EditorGUI.EndChangeCheck()) { return(flag2); } else { break; } case SerializedPropertyType.Float: EditorGUI.BeginChangeCheck(); float num2 = EditorGUI.FloatField(position, label, ConvertUtil.ToSingle(value)); if (EditorGUI.EndChangeCheck()) { return(num2); } else { break; } case SerializedPropertyType.String: EditorGUI.BeginChangeCheck(); string str1 = EditorGUI.TextField(position, label, ConvertUtil.ToString(value)); if (EditorGUI.EndChangeCheck()) { return(str1); } else { break; } case SerializedPropertyType.Color: EditorGUI.BeginChangeCheck(); Color color = EditorGUI.ColorField(position, label, ConvertUtil.ToColor(value)); if (EditorGUI.EndChangeCheck()) { return(color); } else { break; } case SerializedPropertyType.ObjectReference: EditorGUI.BeginChangeCheck(); object obj = EditorGUI.ObjectField(position, label, value as UnityEngine.Object, valueType, true); if (EditorGUI.EndChangeCheck()) { return(obj); } break; case SerializedPropertyType.LayerMask: EditorGUI.BeginChangeCheck(); LayerMask mask = (value is LayerMask) ? (LayerMask)value : (LayerMask)ConvertUtil.ToInt(value); mask = SPEditorGUI.LayerMaskField(position, label, mask); if (EditorGUI.EndChangeCheck()) { return(mask); } break; case SerializedPropertyType.Enum: if (valueType.GetCustomAttributes(typeof(System.FlagsAttribute), false).Any()) { EditorGUI.BeginChangeCheck(); var e = SPEditorGUI.EnumFlagField(position, label, ConvertUtil.ToEnumOfType(valueType, value)); if (EditorGUI.EndChangeCheck()) { return(e); } } else { EditorGUI.BeginChangeCheck(); var e = SPEditorGUI.EnumPopupExcluding(position, label, ConvertUtil.ToEnumOfType(valueType, value)); if (EditorGUI.EndChangeCheck()) { return(e); } } break; case SerializedPropertyType.Vector2: EditorGUI.BeginChangeCheck(); var v2 = EditorGUI.Vector2Field(position, label, ConvertUtil.ToVector2(value)); if (EditorGUI.EndChangeCheck()) { return(v2); } break; case SerializedPropertyType.Vector3: EditorGUI.BeginChangeCheck(); var v3 = EditorGUI.Vector3Field(position, label, ConvertUtil.ToVector3(value)); if (EditorGUI.EndChangeCheck()) { return(v3); } break; case SerializedPropertyType.Vector4: EditorGUI.BeginChangeCheck(); var v4 = EditorGUI.Vector4Field(position, label.text, ConvertUtil.ToVector4(value)); if (EditorGUI.EndChangeCheck()) { return(v4); } break; case SerializedPropertyType.Rect: EditorGUI.BeginChangeCheck(); Rect rect = (value is Rect) ? (Rect)value : new Rect(); rect = EditorGUI.RectField(position, label, rect); if (EditorGUI.EndChangeCheck()) { return(rect); } break; case SerializedPropertyType.ArraySize: EditorGUI.BeginChangeCheck(); int num3 = EditorGUI.IntField(position, label, ConvertUtil.ToInt(value), EditorStyles.numberField); if (EditorGUI.EndChangeCheck()) { return(num3); } break; case SerializedPropertyType.Character: bool changed = GUI.changed; GUI.changed = false; string str2 = EditorGUI.TextField(position, label, new string(ConvertUtil.ToChar(value), 1)); if (GUI.changed) { if (str2.Length == 1) { return(str2[0]); } else { GUI.changed = false; } } GUI.changed = GUI.changed | changed; break; case SerializedPropertyType.AnimationCurve: EditorGUI.BeginChangeCheck(); AnimationCurve curve = value as AnimationCurve; curve = EditorGUI.CurveField(position, label, curve); if (EditorGUI.EndChangeCheck()) { return(curve); } break; case SerializedPropertyType.Bounds: EditorGUI.BeginChangeCheck(); Bounds bnds = (value is Bounds) ? (Bounds)value : new Bounds(); bnds = EditorGUI.BoundsField(position, label, bnds); if (EditorGUI.EndChangeCheck()) { return(bnds); } break; case SerializedPropertyType.Gradient: EditorGUI.BeginChangeCheck(); Gradient grad = value as Gradient; grad = SPEditorGUI.GradientField(position, label, grad); if (EditorGUI.EndChangeCheck()) { return(grad); } break; default: EditorGUI.PrefixLabel(position, label); break; } return(value); }
// 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 override void OnGUI(Rect pRect, SerializedProperty pProperty, GUIContent pLabel) { #if UNITY_EDITOR GUI.enabled = false; switch (pProperty.propertyType) { case SerializedPropertyType.Integer: EditorGUI.LabelField(pRect, pLabel.text, pProperty.intValue.ToString()); break; case SerializedPropertyType.Boolean: EditorGUI.LabelField(pRect, pLabel.text, pProperty.boolValue.ToString()); break; case SerializedPropertyType.Float: EditorGUI.LabelField(pRect, pLabel.text, pProperty.floatValue.ToString("0.00000")); break; case SerializedPropertyType.String: case SerializedPropertyType.Character: EditorGUI.LabelField(pRect, pLabel.text, pProperty.stringValue); break; case SerializedPropertyType.Color: EditorGUI.ColorField(pRect, pLabel.text, pProperty.colorValue); break; case SerializedPropertyType.ObjectReference: EditorGUI.ObjectField(pRect, pLabel.text, pProperty.objectReferenceValue, typeof(System.Object), true); break; case SerializedPropertyType.Vector2: EditorGUI.Vector2Field(pRect, pLabel.text, pProperty.vector2Value); break; case SerializedPropertyType.Vector3: EditorGUI.Vector3Field(pRect, pLabel.text, pProperty.vector3Value); break; case SerializedPropertyType.Vector4: EditorGUI.Vector4Field(pRect, pLabel.text, pProperty.vector4Value); break; case SerializedPropertyType.Quaternion: EditorGUI.LabelField(pRect, pLabel.text, pProperty.quaternionValue.ToString()); break; case SerializedPropertyType.Rect: EditorGUI.RectField(pRect, pLabel.text, pProperty.rectValue); break; case SerializedPropertyType.ArraySize: EditorGUI.LabelField(pRect, pLabel.text, pProperty.arraySize.ToString()); break; case SerializedPropertyType.AnimationCurve: EditorGUI.CurveField(pRect, pLabel.text, pProperty.animationCurveValue); break; case SerializedPropertyType.Bounds: EditorGUI.BoundsField(pRect, pProperty.boundsValue); break; case SerializedPropertyType.Gradient: default: EditorGUI.LabelField(pRect, pLabel.text, "(not supported)"); break; } GUI.enabled = true; #endif }
void DrawDirectField(bool readOnly, Rect?rect) { object value = rawValue; GUI.changed = false; try { switch (currentType) { case PropertyType.Bool: if (rect.HasValue) { value = EditorGUI.Toggle(rect.Value, nameContent, (bool)(value ?? false)); } else { value = EditorGUILayout.Toggle(nameContent, (bool)(value ?? false)); } break; case PropertyType.Enum: if (masked) { if (rect.HasValue) { value = Helper.MaskedEnumField(rect.Value, nameContent, requiredType, value); } else { value = Helper.MaskedEnumField(nameContent, requiredType, value); } break; } if (rect.HasValue) { value = Helper.EnumField(rect.Value, nameContent, requiredType, value); } else { value = Helper.EnumField(nameContent, requiredType, value); } break; case PropertyType.Long: #if UNITY_5 if (rect.HasValue) { value = EditorGUI.LongField(rect.Value, nameContent, (long)(value ?? 0L)); } else { value = EditorGUILayout.LongField(nameContent, (long)(value ?? 0L)); } break; #endif case PropertyType.Integer: if (rect.HasValue) { value = EditorGUI.IntField(rect.Value, nameContent, (int)(value ?? 0)); } else { value = EditorGUILayout.IntField(nameContent, (int)(value ?? 0)); } break; case PropertyType.Double: #if UNITY_5 if (rect.HasValue) { value = EditorGUI.DoubleField(rect.Value, nameContent, (double)(value ?? 0)); } else { value = EditorGUILayout.DoubleField(nameContent, (double)(value ?? 0)); } break; #endif case PropertyType.Single: if (rect.HasValue) { value = EditorGUI.FloatField(rect.Value, nameContent, (float)(value ?? 0F)); } else { value = EditorGUILayout.FloatField(nameContent, (float)(value ?? 0F)); } break; case PropertyType.Vector2: if (rect.HasValue) { value = EditorGUI.Vector2Field(rect.Value, nameContent, (Vector2)(value ?? Vector2.zero)); } else { value = EditorGUILayout.Vector2Field(nameContent, (Vector2)(value ?? Vector2.zero)); } break; case PropertyType.Vector3: if (rect.HasValue) { value = EditorGUI.Vector3Field(rect.Value, nameContent, (Vector3)(value ?? Vector3.zero)); } else { value = EditorGUILayout.Vector3Field(nameContent, (Vector3)(value ?? Vector3.zero)); } break; case PropertyType.Vector4: if (rect.HasValue) { value = EditorGUI.Vector4Field(rect.Value, name, (Vector4)(value ?? Vector4.zero)); } else { value = EditorGUILayout.Vector4Field(name, (Vector4)(value ?? Vector4.zero)); } break; case PropertyType.Quaterion: if (rect.HasValue) { value = Helper.QuaternionField(rect.Value, name, (Quaternion)(value ?? Quaternion.identity)); } else { value = Helper.QuaternionField(name, (Quaternion)(value ?? Quaternion.identity)); } break; case PropertyType.Color: if (rect.HasValue) { value = EditorGUI.ColorField(rect.Value, nameContent, (Color)(value ?? Color.white)); } else { value = EditorGUILayout.ColorField(nameContent, (Color)(value ?? Color.white)); } break; case PropertyType.Rect: if (rect.HasValue) { value = EditorGUI.RectField(rect.Value, nameContent, (Rect)(value ?? default(Rect))); } else { value = EditorGUILayout.RectField(nameContent, (Rect)(value ?? default(Rect))); } break; case PropertyType.Bounds: if (rect.HasValue) { value = EditorGUI.BoundsField(rect.Value, nameContent, (Bounds)(value ?? default(Bounds))); } else { value = EditorGUILayout.BoundsField(nameContent, (Bounds)(value ?? default(Bounds))); } break; case PropertyType.Curve: if (rect.HasValue) { value = EditorGUI.CurveField(rect.Value, nameContent, (AnimationCurve)(value ?? new AnimationCurve())); } else { value = EditorGUILayout.CurveField(nameContent, (AnimationCurve)(value ?? new AnimationCurve())); } break; case PropertyType.Object: if (rect.HasValue) { value = Helper.ObjectField(rect.Value, nameContent, (UnityObject)value, requiredType, true, readOnly); } else { value = Helper.ObjectField(nameContent, (UnityObject)value, requiredType, true, readOnly); } break; case PropertyType.Array: if (rect.HasValue) { arrayHandler.DoList(rect.Value); break; } EditorGUILayout.BeginVertical(); if (arrayShown = EditorGUILayout.Foldout(arrayShown, nameContent)) { arrayHandler.DoLayoutList(); } EditorGUILayout.EndVertical(); break; case PropertyType.String: if (rect.HasValue) { value = Helper.StringField(rect.Value, nameContent, (string)value, readOnly); } else { value = Helper.StringField(nameContent, (string)value, readOnly); } break; default: var stringValue = value != null?value.ToString() : "Null"; if (rect.HasValue) { Helper.StringField(Helper.ScaleRect(rect.Value, 0, 0, 1, 1, 0, 0, -36), nameContent, stringValue, true); DrawUnknownField(readOnly, value, Helper.ScaleRect(rect.Value, 1, 0, 0, 1, -34, 0, 32)); } else { Helper.StringField(nameContent, stringValue, true); DrawUnknownField(readOnly, value); } break; } } catch (InvalidCastException) { if (Event.current.type == EventType.Repaint) { value = null; } else { RequireRedraw(); } } if (!readOnly) { changed |= GUI.changed; rawValue = value; } }
/// <summary> /// Helper method for rendering various controls. /// </summary> /// <param name="type"></param> /// <param name="value"></param> /// <param name="content"></param> public static int AnyField(Rect rect, Type type, ref object value, GUIContent content) { if (type == typeof(bool)) { value = EditorGUI.Toggle(rect, content, (bool)value); } else if (type == typeof(byte)) { value = (byte)EditorGUI.DelayedIntField(rect, content, (byte)value); } else if (type == typeof(short)) { value = (short)EditorGUI.DelayedIntField(rect, content, (short)value); } else if (type == typeof(ushort)) { value = (ushort)EditorGUI.DelayedIntField(rect, content, (ushort)value); } else if (type == typeof(int)) { value = EditorGUI.IntField(rect, content, (int)value); } else if (type == typeof(uint)) { value = (uint)EditorGUI.IntField(rect, content, (int)value); } else if (type == typeof(long)) { value = EditorGUI.LongField(rect, content, (long)value); } else if (type == typeof(ulong)) { value = (ulong)EditorGUI.LongField(rect, content, (long)value); } else if (type == typeof(float)) { value = EditorGUI.FloatField(rect, content, (float)value); } else if (type == typeof(double)) { value = EditorGUI.DoubleField(rect, content, (double)value); } else if (type == typeof(string)) { value = EditorGUI.TextField(rect, content, (string)value); } else if (TypeHelper.IsSameOrSubclass(typeof(Enum), type)) { value = EditorGUI.EnumPopup(rect, content, (Enum)value); } else if (type == typeof(Vector2)) { value = EditorGUI.Vector2Field(rect, content, (Vector2)value); } else if (type == typeof(Vector3)) { value = EditorGUI.Vector3Field(rect, content, (Vector3)value); } else if (type == typeof(Vector4)) { value = EditorGUI.Vector4Field(rect, content, (Vector4)value); } else if (type == typeof(Quaternion)) { Quaternion q = (Quaternion)value; q.eulerAngles = EditorGUI.Vector3Field(rect, content, ((Quaternion)value).eulerAngles); value = q; } else if (type == typeof(Color)) { value = EditorGUI.ColorField(rect, content, (Color)value); } else if (type == typeof(Bounds)) { value = EditorGUI.BoundsField(rect, content, (Bounds)value); } else if (type == typeof(Rect)) { value = EditorGUI.RectField(rect, content, (Rect)value); } else if (type == typeof(AnimationCurve)) { value = EditorGUI.CurveField(rect, content, (AnimationCurve)value); } else if (TypeHelper.IsSameOrSubclass(typeof(UnityEngine.Object), type)) { value = EditorGUI.ObjectField(rect, content, (UnityEngine.Object)value, type, true); } else if (type == typeof(LayerMask)) { value = LayerMaskField(content, (LayerMask)value); } else { return(ComplexField(rect, content, value)); } //TODO: general EnumMask, Assets (Sprite, Texture, etc...) return(1); }
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; } }
/// <summary> /// Shows an object field editor for object types that do no derive from UnityEngine.Object. /// </summary> /// <typeparam name="T">Type of the object to modify.</typeparam> /// <param name="position">The region to show the UI.</param> /// <param name="label">Label to show.</param> /// <param name="value">Current value to show.</param> /// <param name="allowSceneObjects">Whether scene objects should be allowed in the set of field choices.</param> /// <returns>The new value.</returns> public static T ObjectField <T>(Rect position, GUIContent label, T value, bool allowSceneObjects) { object objValue = value; Type valueType = objValue.GetType(); if (valueType == typeof(Bounds)) { objValue = EditorGUI.BoundsField(position, label, (Bounds)objValue); } else if (valueType == typeof(Color)) { objValue = EditorGUI.ColorField(position, label, (Color)objValue); } else if (valueType == typeof(Material)) { objValue = EditorGUI.ObjectField(position, (Material)objValue, typeof(Material), allowSceneObjects); } else if (valueType == typeof(AnimationCurve)) { objValue = EditorGUI.CurveField(position, label, (AnimationCurve)objValue); } else if (valueType == typeof(float)) { objValue = EditorGUI.FloatField(position, label, (float)objValue); } else if (valueType == typeof(int)) { objValue = EditorGUI.IntField(position, label, (int)objValue); } else if (valueType == typeof(LayerMask)) { objValue = EditorGUI.MaskField(position, label, (LayerMask)objValue, LayerMaskExtensions.LayerMaskNames); } else if (valueType.IsEnum) { if (valueType.GetCustomAttributes(typeof(FlagsAttribute), true).Length > 0) { objValue = EditorGUI.EnumFlagsField(position, label, (Enum)objValue); } else { objValue = EditorGUI.EnumPopup(position, label, (Enum)objValue); } } else if (valueType == typeof(Rect)) { objValue = EditorGUI.RectField(position, label, (Rect)objValue); } else if (valueType == typeof(string)) { objValue = EditorGUI.TextField(position, label, (string)objValue); } else if (valueType == typeof(Vector2)) { objValue = EditorGUI.Vector2Field(position, new GUIContent(), (Vector2)objValue); } else if (valueType == typeof(Vector3)) { objValue = EditorGUI.Vector3Field(position, new GUIContent(), (Vector3)objValue); } else if (valueType == typeof(Vector4)) { if (label.image != null) { throw new ArgumentException("Images not supported for labels of Vector4 fields.", "label"); } if (!string.IsNullOrEmpty(label.tooltip)) { throw new ArgumentException("Tool-tips not supported for labels of Vector4 fields.", "label"); } objValue = EditorGUI.Vector4Field(position, label.text, (Vector4)objValue); } else if (Equals(objValue, typeof(SceneAsset))) { objValue = EditorGUI.ObjectField(position, (SceneAsset)objValue, typeof(SceneAsset), allowSceneObjects); } else if (objValue is UnityEngine.Object) { objValue = EditorGUI.ObjectField(position, label, (UnityEngine.Object)objValue, valueType, allowSceneObjects); } else { throw new ArgumentException( string.Format( CultureInfo.InvariantCulture, "Unimplemented value type: {0}.", valueType), "value"); } return((T)objValue); }
public override Bounds Edit(Rect region, GUIContent label, Bounds element, fiGraphMetadata metadata) { return(EditorGUI.BoundsField(region, label, element)); }