public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { if (SerializedPropertyUtility.IsArrayElement(property)) { if (SerializedPropertyUtility.IndexOfArrayElement(property) == 0) { //EditorGUI.PropertyField(new Rect(position.x, position.y, position.width, EditorGUIUtility.singleLineHeight), property, true); //position.y += EditorGUIUtility.singleLineHeight; firstProperty = property; SerializedProperty parentProp = SerializedPropertyUtility.GetArrayParentProperty(property); if (list == null || list.serializedProperty.propertyPath != parentProp.propertyPath) { list = new ReorderableList(parentProp.serializedObject, parentProp, true, true, true, true); list.drawElementCallback += DrawElement; list.elementHeightCallback += ElementHeightCallback; list.drawHeaderCallback += DrawHeader; //list.drawFooterCallback += DrawFooter; } if (list != null) { list.elementHeight = maxHeight; //list.DoLayoutList(); list.DoList(new Rect(position.x, position.y, position.width, maxHeight)); } } } }
// Entry Point public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { if (showDebug) { Rect sliderRect = new Rect(0, position.y, position.width, normalHeight); labelWidthPercent = EditorGUI.Slider(sliderRect, labelWidthPercent, 0, 1); sliderRect.y += debugTool; position.yMin += debugTool; } float yMax = position.yMax; currHeight = 0; EditorGUI.indentLevel = 0; isCalcHeight = false; SetupGUIStyle(); // Inspector Label Width labelWidth = position.width * labelWidthPercent; EditorGUIUtility.labelWidth = labelWidth; currProperty = property.propertyPath; SerializedProperty origProp = null; // Special case of array element (4.3) if (SerializedPropertyUtility.IsArrayElement(property)) { isArrayElement = true; arrayElementIndex = SerializedPropertyUtility.IndexOfArrayElement(property); origProp = SerializedPropertyUtility.GetArrayParentProperty(property); } else { origProp = property.Copy(); } AutoPropertyField(position, property, origProp, label, 0, out yMax); // delay action if (action != null) { action.Action(); action = null; } GUI.skin = null; }
public override float GetPropertyHeight(SerializedProperty property, GUIContent label) { float h = 0; // base.GetPropertyHeight(property, label); if (SerializedPropertyUtility.IsArrayElement(property)) { if (SerializedPropertyUtility.IndexOfArrayElement(property) == 0) { h += EditorGUIUtility.singleLineHeight; // header h += EditorGUIUtility.singleLineHeight; // footer //SerializedProperty parentProp = SerializedPropertyUtility.GetArrayParentProperty(property); } //h += EditorGUI.GetPropertyHeight(property); h += maxHeight; } return(h); }
public override float GetPropertyHeight(SerializedProperty property, GUIContent label) { SerializedProperty origProp = property; bool backupFlag = isArrayElement; if (SerializedPropertyUtility.IsArrayElement(property)) { isArrayElement = true; arrayElementIndex = SerializedPropertyUtility.IndexOfArrayElement(property); origProp = SerializedPropertyUtility.GetArrayParentProperty(property); } else { origProp = property.Copy(); } float height = GetPropertyHeight(property, origProp, label) + (1) + ((showDebug)? debugTool: 0); isArrayElement = backupFlag; return(height); }
void CustomPropertyField(Rect position, SerializedProperty prop, GUIContent label, out float yMax) { Vector2 xRangeContent = new Vector2(GetXRange(prop) + marginWidth.x, position.xMax - GetXRange(prop) - marginWidth.x); position.x = xRangeContent[0]; position.xMax = xRangeContent[1]; position.height = normalHeight; Rect controlPos = new Rect(position); controlPos.x += labelWidth; controlPos.width -= labelWidth; controlPos.height = normalHeight; switch (prop.propertyType) { case SerializedPropertyType.ArraySize: { if (currProperty != prop.propertyPath) { position.y += UnknownPropertyField(position, prop, label); break; } if (!isCalcHeight) { EditorGUI.LabelField(position, label); EditorGUI.BeginChangeCheck(); int intValue = EditorGUI.IntField(controlPos, prop.intValue); // Code to execute if GUI.changed // was set to true inside the block of code above. if (EditorGUI.EndChangeCheck()) { prop.intValue = intValue; } } position.y += normalHeight; break; } case SerializedPropertyType.Integer: { if (currProperty != prop.propertyPath) { position.y += UnknownPropertyField(position, prop, label); break; } if (!isCalcHeight) { //GUI.Label(position, new GUIContent(label.text), "label"); controlPos = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), new GUIContent(label.text)); EditorGUI.BeginChangeCheck(); int intValue = EditorGUI.IntField(controlPos, prop.intValue); // Code to execute if GUI.changed // was set to true inside the block of code above. if (EditorGUI.EndChangeCheck()) { prop.intValue = intValue; } } position.y += normalHeight; break; } case SerializedPropertyType.Float: { if (currProperty != prop.propertyPath) { position.y += UnknownPropertyField(position, prop, label); break; } if (!isCalcHeight) { controlPos = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), new GUIContent(label.text)); EditorGUI.BeginChangeCheck(); float floatValue = EditorGUI.FloatField(controlPos, prop.floatValue); // Code to execute if GUI.changed // was set to true inside the block of code above. if (EditorGUI.EndChangeCheck()) { prop.floatValue = floatValue; } } position.y += normalHeight; break; } case SerializedPropertyType.String: { if (!isCalcHeight) { controlPos = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), new GUIContent(label.text)); EditorGUI.BeginChangeCheck(); string str = EditorGUI.TextField(controlPos, prop.stringValue); // Code to execute if GUI.changed // was set to true inside the block of code above. if (EditorGUI.EndChangeCheck()) { prop.stringValue = str; } } position.y += normalHeight; break; } case SerializedPropertyType.Color: { if (!isCalcHeight) { controlPos = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), new GUIContent(label.text)); EditorGUI.BeginChangeCheck(); Color color = EditorGUI.ColorField(controlPos, prop.colorValue); // Code to execute if GUI.changed // was set to true inside the block of code above. if (EditorGUI.EndChangeCheck()) { prop.colorValue = color; } } position.y += normalHeight; break; } case SerializedPropertyType.LayerMask: { if (!isCalcHeight) { controlPos = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), new GUIContent(label.text)); EditorGUI.BeginChangeCheck(); int layer = EditorGUI.LayerField(controlPos, prop.intValue); // Code to execute if GUI.changed // was set to true inside the block of code above. if (EditorGUI.EndChangeCheck()) { prop.intValue = layer; } } position.y += normalHeight; break; } case SerializedPropertyType.Vector2: { if (!isCalcHeight) { EditorGUI.LabelField(position, label); EditorGUI.BeginChangeCheck(); Vector2 vector2Value = EditorGUI.Vector2Field(controlPos, "", prop.vector2Value); // Code to execute if GUI.changed // was set to true inside the block of code above. if (EditorGUI.EndChangeCheck()) { prop.vector2Value = vector2Value; } } position.y += normalHeight; break; } case SerializedPropertyType.Quaternion: { if (!isCalcHeight) { EditorGUI.LabelField(position, label); EditorGUI.BeginChangeCheck(); controlPos.y -= normalHeight; Vector4 vector4Value = EditorGUI.Vector4Field(controlPos, "", new Vector4(prop.quaternionValue.x, prop.quaternionValue.y, prop.quaternionValue.z, prop.quaternionValue.w)); // Code to execute if GUI.changed // was set to true inside the block of code above. if (EditorGUI.EndChangeCheck()) { prop.quaternionValue = new Quaternion(vector4Value.x, vector4Value.y, vector4Value.z, vector4Value.w); } } position.y += normalHeight; break; } case SerializedPropertyType.Vector3: { if (!isCalcHeight) { EditorGUI.LabelField(position, label); EditorGUI.BeginChangeCheck(); Vector3 vector3Value = EditorGUI.Vector3Field(controlPos, "", prop.vector3Value); // Code to execute if GUI.changed // was set to true inside the block of code above. if (EditorGUI.EndChangeCheck()) { prop.vector3Value = vector3Value; } } position.y += normalHeight; break; } case SerializedPropertyType.Rect: { if (!isCalcHeight) { controlPos = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), new GUIContent(label.text)); EditorGUI.BeginChangeCheck(); Rect rectValue = EditorGUI.RectField(controlPos, prop.rectValue); // Code to execute if GUI.changed // was set to true inside the block of code above. if (EditorGUI.EndChangeCheck()) { prop.rectValue = rectValue; } } position.y += doubleHeight; break; } case SerializedPropertyType.Gradient: case SerializedPropertyType.Character: { if (!isCalcHeight) { // TODO EditorGUI.LabelField(position, prop.propertyType.ToString()); EditorGUI.LabelField(controlPos, "Unsupport type"); } position.y += normalHeight; break; } case SerializedPropertyType.AnimationCurve: { if (!isCalcHeight) { controlPos = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), new GUIContent(label.text)); EditorGUI.BeginChangeCheck(); AnimationCurve animationCurveValue = EditorGUI.CurveField(controlPos, prop.animationCurveValue); // Code to execute if GUI.changed // was set to true inside the block of code above. if (EditorGUI.EndChangeCheck()) { prop.animationCurveValue = animationCurveValue; } } position.y += normalHeight; break; } case SerializedPropertyType.Bounds: { if (!isCalcHeight) { controlPos = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), new GUIContent(label.text)); EditorGUI.BeginChangeCheck(); Bounds boundsValue = EditorGUI.BoundsField(controlPos, prop.boundsValue); // Code to execute if GUI.changed // was set to true inside the block of code above. if (EditorGUI.EndChangeCheck()) { prop.boundsValue = boundsValue; } } position.y += doubleHeight; break; } case SerializedPropertyType.Boolean: { if (!isCalcHeight) { controlPos = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), new GUIContent(label.text)); EditorGUI.BeginChangeCheck(); bool boolValue = EditorGUI.Toggle(controlPos, prop.boolValue); // Code to execute if GUI.changed // was set to true inside the block of code above. if (EditorGUI.EndChangeCheck()) { prop.boolValue = boolValue; } } position.y += normalHeight; break; } case SerializedPropertyType.ObjectReference: { if (currProperty != prop.propertyPath) { position.y += UnknownPropertyField(position, prop, label); break; } if (!isCalcHeight) { Type objType = null; SerializedProperty testProp = prop; if (SerializedPropertyUtility.IsArrayElement(prop)) { object obj = SerializedPropertyUtility.GetParent(prop); objType = obj.GetType(); } Type currType = testProp.serializedObject.targetObject.GetType(); FieldInfo field = currType.GetField(testProp.name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (field != null) { objType = field.FieldType; } if (objType != null) { controlPos = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), new GUIContent(label.text)); EditorGUI.BeginChangeCheck(); UnityEngine.Object objectReferenceValue = EditorGUI.ObjectField(controlPos, prop.objectReferenceValue, objType, true); // Code to execute if GUI.changed // was set to true inside the block of code above. if (EditorGUI.EndChangeCheck()) { prop.objectReferenceValue = objectReferenceValue; } } } position.y += normalHeight; break; } case SerializedPropertyType.Enum: { if (currProperty != prop.propertyPath) { position.y += UnknownPropertyField(position, prop, label); break; } if (!isCalcHeight) { Type currType = prop.serializedObject.targetObject.GetType(); FieldInfo field = currType.GetField(prop.name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (field != null) { Type enumType = field.FieldType; FieldInfo[] fields = enumType.GetFields(BindingFlags.Public | BindingFlags.Static); if (fields != null) { int[] intArray = new int[fields.Length]; for (int i = 0; i < fields.Length; i++) { intArray[i] = (int)Convert.ChangeType(fields[i].GetValue(null), typeof(int)); } prop.enumValueIndex = (prop.enumValueIndex < 0)? 0: prop.enumValueIndex; EditorGUI.LabelField(position, label); EditorGUI.BeginChangeCheck(); int intValue = EditorGUI.IntPopup(controlPos, prop.intValue, prop.enumNames, intArray); // Code to execute if GUI.changed // was set to true inside the block of code above. if (EditorGUI.EndChangeCheck()) { prop.intValue = intValue; } } } } position.y += normalHeight; break; } default: { if (currProperty != prop.propertyPath) { position.y += UnknownPropertyField(position, prop, label); break; } if (!isCalcHeight) { Type currType = prop.serializedObject.targetObject.GetType(); FieldInfo field = currType.GetField(prop.name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (field != null) { EditorGUI.LabelField(position, field.FieldType.ToString()); } } position.y += normalHeight; break; } } yMax = position.y; }