private void DrawRuntimeObject(Rect position, RuntimeSerializedObject runtimeSerializedObject) { var prop = runtimeSerializedObject.GetIterator(); var height = RuntimeEasyGUI.GetSinglePropertyHeight(prop, new GUIContent(prop.DisplayName)); var headerPosition = new Rect(position.x, position.y, position.width, height); headerPosition.xMin += Space; prop.IsExpanded = EditorGUI.Foldout(headerPosition, prop.IsExpanded, prop.DisplayName); RuntimeEasyGUI.PropertyField(headerPosition, prop, null); if (prop.IsExpanded) { var y = RuntimeEasyGUI.GetPropertyHeight(prop, null); EditorGUI.indentLevel++; while (prop.NextVisible(false)) { var mainPosition = new Rect(position.x, position.y + y, position.width, height); mainPosition.xMin += Space; height = RuntimeEasyGUI.GetPropertyHeight(prop, new GUIContent(prop.DisplayName), prop.IsExpanded, null); RuntimeEasyGUI.PropertyField(mainPosition, prop, new GUIContent(prop.DisplayName), prop.IsExpanded, null); y += height; } EditorGUI.indentLevel--; } }
private void DrawPropertySortableArray(Rect position, RuntimeSerializedProperty property, GUIContent label) { // Try to get the sortable list this property belongs to RuntimeReorderableListData listData = null; if (listDataDict.Count > 0) { listData = listDataDict.Find(data => property.PropertyPath.StartsWith(data.Parent)); } UnityEditor.Editor scriptableEditor; bool isScriptableEditor = editableDict.TryGetValue(property.PropertyPath, out scriptableEditor); // Has ReorderableList and Try to show the list if (listData != null && listData.DoProperty(position, property)) { } // Else try to draw ScriptableObject editor else if (isScriptableEditor) { bool hasHeader = property.HasAttribute <HeaderAttribute>(); bool hasSpace = property.HasAttribute <SpaceAttribute>(); hasSpace |= hasHeader; // Reference type is not supported! } else { RuntimeEasyGUI.PropertyField(position, property, label, property.IsExpanded, null); } }
private string DoHeader(RuntimeSerializedProperty property, Rect position, string displayName) { displayName = string.IsNullOrEmpty(displayName) ? property.DisplayName : displayName; string headerName = string.Format(HeaderStr, displayName, property.ArraySize, property.HashCodeForPropertyPath()); RuntimeEasyGUI.PropertyField(position, property, new GUIContent(headerName), false, null); return(headerName); }
public void AddProperty(RuntimeSerializedProperty property) { // Check if this property actually belongs to the same direct child if (!property.GetRootPath().Equals(Parent)) { return; } if (runtimeReorderableListDict.ContainsKey(property.PropertyPath)) { return; } RuntimeReorderableList propList = new RuntimeReorderableList( property.RuntimeSerializedObject.SerializedObject, property, draggable: true, displayHeader: false, displayAddButton: true, displayRemoveButton: true) { headerHeight = 5 }; propList.drawElementBackgroundCallback = (Rect position, int index, bool active, bool focused) => { if (DrawBackgroundCallback != null) { Rect backgroundRect = new Rect(position); if (index <= 0) { backgroundRect.yMin -= 8; } if (index >= propList.count - 1) { backgroundRect.yMax += 3; } EditorGUI.DrawRect(backgroundRect, DrawBackgroundCallback(active, focused)); } else { propList.drawElementBackgroundCallback = null; } }; propList.drawElementCallback = (Rect position, int index, bool active, bool focused) => { var iterProp = property.GetArrayElementAtIndex(index); var elementName = iterProp.DisplayName; if (ElementNameCallback != null) { elementName = ElementNameCallback(index); } RuntimeEasyGUI.PropertyField(position, iterProp, new GUIContent(elementName), ElementAttributes); }; propList.elementHeightCallback = index => ElementHeightCallback(property, index); runtimeReorderableListDict.Add(property.PropertyPath, propList); }
protected virtual void EmitPropertyField(Rect position, RuntimeSerializedProperty runtimeSerializedProperty, GUIContent label) { var multiline = GetMultilineAttribute(); if (multiline == null) { var range = GetRangeAttribute(); if (range == null) { RuntimeEasyGUI.PropertyField(position, runtimeSerializedProperty, label, true, null); } else { if (runtimeSerializedProperty.PropertyType == RuntimeSerializedPropertyType.Float) { RuntimeEasyGUI.Slider(position, runtimeSerializedProperty, range.Min, range.Max, label); } else if (runtimeSerializedProperty.PropertyType == RuntimeSerializedPropertyType.Integer) { RuntimeEasyGUI.IntSlider(position, runtimeSerializedProperty, (int)range.Min, (int)range.Max, label); } else { EditorGUI.LabelField(position, label.text, "Use Range with float or int."); } } } else { var property = runtimeSerializedProperty; label = RuntimeEasyGUI.BeginProperty(position, label, property); var method = typeof(EditorGUI).GetMethod("MultiFieldPrefixLabel", BindingFlags.Static | BindingFlags.InvokeMethod | BindingFlags.Public | BindingFlags.NonPublic); position = (Rect)method.Invoke(null, new object[] { position, 0, label, 1 }); EditorGUI.BeginChangeCheck(); int indentLevel = EditorGUI.indentLevel; EditorGUI.indentLevel = 0; var stringValue = EditorGUI.TextArea(position, property.StringValue); EditorGUI.indentLevel = indentLevel; if (EditorGUI.EndChangeCheck()) { property.StringValue = stringValue; } RuntimeEasyGUI.EndProperty(); } }
public bool DoProperty(Rect position, RuntimeSerializedProperty property) { if (!runtimeReorderableListDict.ContainsKey(property.PropertyPath)) { return(false); } headerPosition = new Rect(position); headerPosition.height = RuntimeEasyGUI.GetPropertyHeight(property, GUIContent.none, false, null); // Draw the background if (DrawBackgroundCallback != null) { Rect backgroundPosition = new Rect(headerPosition); backgroundPosition.xMin += EasyGUI.Indent; if (property.IsExpanded) { backgroundPosition.yMax += 19; } EditorGUI.DrawRect(backgroundPosition, DrawBackgroundCallback(false, false)); } // Draw header if (HeaderCallback != null) { HeaderCallback(headerPosition); } else { string headerName = string.Format(HeaderStr, property.DisplayName, property.ArraySize, property.HashCodeForPropertyPath()); RuntimeEasyGUI.PropertyField(headerPosition, property, new GUIContent(headerName), false, null); } // Draw the reorderable list for the property if (property.IsExpanded) { EditorGUI.BeginDisabledGroup(!Editable); if (!property.Editable) { EditorGUI.indentLevel++; } EditorGUI.BeginChangeCheck(); var sizePosition = new Rect(headerPosition); sizePosition.yMin = headerPosition.yMax; sizePosition.height = EditorGUIUtility.singleLineHeight; var newArraySize = Mathf.Clamp(EditorGUI.IntField(sizePosition, SizeStr, property.ArraySize), 0, int.MaxValue); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(property.RuntimeSerializedObject.TargetObject, SetArraySizeStr); property.ArraySize = newArraySize; EditorUtility.SetDirty(property.RuntimeSerializedObject.TargetObject); } var listPosition = new Rect(sizePosition); listPosition.xMin += EasyGUI.Indent; listPosition.yMin = sizePosition.yMax; var indentLevel = EditorGUI.indentLevel; EditorGUI.indentLevel = 0; runtimeReorderableListDict[property.PropertyPath].DoList(listPosition); EditorGUI.indentLevel = indentLevel; if (!property.Editable) { EditorGUI.indentLevel--; } EditorGUI.EndDisabledGroup(); } return(true); }