private void CreateListData(InspectableProperty property) { var root = property.GetRootPath(); // Try to find the grand parent in ReorderableListData var data = listIndex.Find(listData => listData.Parent.Equals(root)); if (data == null) { data = new ReorderableListData(root); listIndex.Add(data); } data.AddProperty(property); if (property.HasAttribute <ReorderableAttribute>()) { var reorderableAttr = property.GetAttributes <ReorderableAttribute>()[0] as ReorderableAttribute; if (reorderableAttr != null) { HandleReorderableOptions(reorderableAttr, property, data); } } if (property.HasAttribute <BackgroundColorAttribute>()) { var bgColorAttr = property.GetAttributes <BackgroundColorAttribute>()[0] as BackgroundColorAttribute; if (bgColorAttr != null) { HandleBackgroundColorOptions(bgColorAttr, property, data); } } }
private float ElementHeightCallback(InspectableProperty property, int index) { var height = 3f; var iterProp = property.GetArrayElementAtIndex(index); if (iterProp.IsExpanded || !ElementHeights.ContainsKey(index)) { var displayName = new GUIContent(iterProp.DisplayName); if (ElementNameCallback != null) { var elementName = ElementNameCallback(index); displayName = elementName == null ? GUIContent.none : new GUIContent(elementName); } height += EasyGUI.GetInspectableObjectHeight(iterProp, displayName, IsDrawObjectReference); if (!iterProp.IsExpanded) { ElementHeights.Add(index, height); } } else { height = ElementHeights[index]; } return(height); }
public InspectableProperty FindPropertyRelative(string relativePropertyPath) { InspectableProperty property = null; if (!string.IsNullOrEmpty(relativePropertyPath)) { string[] paths = relativePropertyPath.Split(StopChar); if (paths.Length > 0 && propertyBase.Properties != null) { foreach (var child in propertyBase.Properties) { if (child.Name == paths[0]) { property = new InspectableProperty(child); if (paths.Length == 1) { return(property); } else { int startIndex = paths[0].Length + 1; string path = relativePropertyPath.Substring(startIndex, relativePropertyPath.Length - startIndex); property = property.FindPropertyRelative(path); if (property != null) { return(property); } } } } } } return(property); }
public InspectableProperty GetFixedBufferElementAtIndex(int index) { InspectableProperty property = Copy(); InspectableProperty result = null; if (index >= 0 && index < property.FixedBufferSize) { int i = 0; if (property.NextVisible(true)) { property.NextVisible(false); do { if (i == index) { result = property; break; } i++; } while (property.NextVisible(false)); } } else { result = null; } return(result); }
public bool DuplicateCommand() { var length = PropertyPath.LastIndexOf(StopStr); var parentPath = PropertyPath.Substring(0, length); var property = FindProperty(parentPath); var property2 = property.Copy(); if (property != null && property.IsArray) { int index = 0; // Skip Array Size Property property2.NextVisible(true); while (property2.NextVisible(false)) { if (InspectableProperty.EqualContents(property2, this)) { object o = property.GetArrayElementAtIndex(index).Value; property.InsertArrayElementAtIndex(index); property.GetArrayElementAtIndex(index).Value = o; return(true); } index++; } } return(false); }
public void AddProperty(InspectableProperty property) { // Check if this property actually belongs to the same direct child if (!property.GetRootPath().Equals(Parent)) { return; } if (extendListIndex.ContainsKey(property.PropertyPath)) { return; } InspectableReorderableList propList = new InspectableReorderableList( property.InspectableObject.SerializedObject, property, draggable: true, displayHeader: false, displayAddButton: true, displayRemoveButton: true) { headerHeight = 5 }; propList.drawElementBackgroundCallback = delegate(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 = delegate(Rect position, int index, bool active, bool focused) { var iterProp = property.GetArrayElementAtIndex(index); var displayName = new GUIContent(iterProp.DisplayName); if (ElementNameCallback != null) { var elementName = ElementNameCallback(index); displayName = elementName == null ? GUIContent.none : new GUIContent(elementName); } EasyGUI.TryDrawInspectableObject(position, iterProp, displayName, IsDrawObjectReference); }; propList.elementHeightCallback = index => ElementHeightCallback(property, index); extendListIndex.Add(property.PropertyPath, propList); }
internal float GetPropertyHeightSafe(InspectableProperty property, GUIContent label) { InspectableAttributeUtility.s_DrawerStack.Push(this); float propertyHeight = this.GetPropertyHeight(property, label); InspectableAttributeUtility.s_DrawerStack.Pop(); return(propertyHeight); }
public PropertyGUIData(InspectableProperty property, Rect totalPosition, bool wasBoldDefaultFont, bool wasEnabled, Color color) { Property = property; TotalPosition = totalPosition; WasBoldDefaultFont = wasBoldDefaultFont; WasEnabled = wasEnabled; Color = color; }
private string DoHeader(InspectableProperty property, Rect position, string displayName) { displayName = string.IsNullOrEmpty(displayName) ? property.DisplayName : displayName; string headerName = string.Format(HeaderStr, displayName, property.ArraySize); EasyGUI.PropertyField(position, property, new GUIContent(headerName), false); return(headerName); }
public bool MoveNext() { uint num = (uint)position; position = -1; switch (num) { case 0: if (!target.IsArray) { end = target.GetEndProperty(); if (target.NextVisible(true) && !InspectableProperty.EqualContents(target, end)) { current = target; if (!disposing) { position = 2; } return(true); } position = -1; return(false); } index = 0; break; case 1: index++; break; case 2: if (target.NextVisible(true) && !InspectableProperty.EqualContents(target, end)) { current = target; if (!disposing) { position = 2; } return(true); } position = -1; return(false); default: return(false); } if (index >= target.ArraySize) { position = -1; return(false); } current = target.GetArrayElementAtIndex(index); if (!disposing) { position = 1; } return(true); }
public static bool HasAttribute <T>(this InspectableProperty property) { object[] attrs = GetAttributes <T>(property); if (attrs != null) { return(attrs.Length > 0); } return(false); }
private void Initialize(InspectableProperty property) { if (isInitialized) { return; } FindTargetProperties(property.Copy()); }
public static void PasteComponentValues(object userData) { InspectableProperty inspectableProperty = (InspectableProperty)userData; InspectableObjectData data = clipboard[inspectableProperty.InspectableObject.Type]; JsonUtility.FromJsonOverwrite(data.Data, inspectableProperty.InspectableObject.Object); inspectableProperty.InspectableObject.ParentProperty.SetInspectableObjectData(data); inspectableProperty.InspectableObject.SerializedObject.ApplyModifiedProperties(); }
private void Initialize(InspectableProperty property, bool force) { if (force) { isInitialized = false; } Initialize(property); }
public override void OnGUI(Rect position, InspectableProperty property, GUIContent label) { EditorGUI.BeginChangeCheck(); var index = EditorGUI.MaskField(position, property.DisplayName, property.IntValue, property.EnumDisplayNames); if (EditorGUI.EndChangeCheck()) { property.IntValue = index; } }
public InspectableHandler GetHandler(InspectableProperty property) { InspectableHandler handler; int key = GetPropertyHash(property); if (InspectableHandlers.TryGetValue(key, out handler)) { return(handler); } return(null); }
public static string GetRootPath(this InspectableProperty property) { var rootPath = property.PropertyPath; var firstDot = property.PropertyPath.IndexOf(StopChar); if (firstDot > 0) { rootPath = property.PropertyPath.Substring(0, firstDot); } return(rootPath); }
private void SetValue(InspectableProperty property, float value) { if (property.PropertyType == InspectablePropertyType.Integer) { property.IntValue = (int)value; } else if (property.PropertyType == InspectablePropertyType.Float) { property.FloatValue = value; } }
private void DrawPropertySortableArray(Rect position, InspectableProperty property, GUIContent label) { // Try to get the sortable list this property belongs to ReorderableListData listData = null; if (listIndex.Count > 0) { listData = listIndex.Find(data => property.PropertyPath.StartsWith(data.Parent)); } UnityEditor.Editor scriptableEditor; bool isScriptableEditor = editableIndex.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; // No data in property, draw property field with create button if (scriptableEditor == null) { var fieldPosition = new Rect(position); var buttonPosition = new Rect(position); fieldPosition.width -= hasSpace ? 60 : 50; buttonPosition.xMin = fieldPosition.xMax; EasyGUI.PropertyField(fieldPosition, property); bool doCreate = GUI.Button(buttonPosition, Create, EditorStyles.miniButton); if (doCreate) { var propType = property.GetTypeReflection(); ScriptableObjectUtility.CreateAssetWithSavePrompt(propType, postCreated: createdAsset => { property.ObjectReference = createdAsset; property.IsExpanded = true; return(false); }); } } } else { EasyGUI.PropertyField(position, property, label, property.IsExpanded); } }
public override float GetPropertyHeight(InspectableProperty property, GUIContent label) { // Try to get the sortable list this property belongs to ReorderableListData listData = null; if (listIndex.Count > 0) { listData = listIndex.Find(data => property.PropertyPath.StartsWith(data.Parent)); } return(listData != null?listData.GetPropertyHeight(property) : EasyGUI.GetPropertyHeight(property, label, property.IsExpanded)); }
public InspectableProperty GetEndProperty(bool includeInVisible = false) { InspectableProperty property = Copy(); if (includeInVisible) { property.Next(false); return(property); } property.NextVisible(false); return(property); }
public static T GetParent <T>(this InspectableProperty property) { var obj = property.InspectableObject.Object; var length = property.PropertyPath.LastIndexOf(StopChar); if (length > -1) { var path = property.PropertyPath.Substring(0, length); obj = property.InspectableObject.FindProperty(path).Value; } return((T)obj); }
private float GetValue(InspectableProperty property) { if (property.PropertyType == InspectablePropertyType.Integer) { return(property.IntValue); } else if (property.PropertyType == InspectablePropertyType.Float) { return(property.FloatValue); } return(0); }
private static FieldInfo GetFieldInfoFromProperty(InspectableProperty property, out Type type) { var classType = GetScriptTypeFromProperty(property); if (classType == null) { type = null; return(null); } return(GetFieldInfoFromPropertyPath(classType, property.PropertyPath, out type)); }
public override void OnGUI(Rect position, InspectableProperty property, GUIContent label) { var range = Attribute as MinMaxRangeAttribute; var minProperty = property.FindPropertyRelative(Min); var maxProperty = property.FindPropertyRelative(Max); if (minProperty != null && maxProperty != null) { minValue = GetValue(minProperty); maxValue = GetValue(maxProperty); Rect contentPosition = EditorGUI.PrefixLabel(position, label); EditorGUI.BeginChangeCheck(); int indentLevel = EditorGUI.indentLevel; EditorGUI.indentLevel = 0; if (range.Min == float.MinValue || range.Max == float.MaxValue) { var tempPosition = new Rect(contentPosition); tempPosition.xMax = tempPosition.xMin + 0.2f * contentPosition.width; EditorGUI.LabelField(tempPosition, Min); tempPosition.xMin = tempPosition.xMax; tempPosition.xMax += 0.3f * contentPosition.width; minValue = EditorGUI.FloatField(tempPosition, minValue); tempPosition.xMin = tempPosition.xMax; tempPosition.xMax += 0.2f * contentPosition.width; EditorGUI.LabelField(tempPosition, Max); tempPosition.xMin = tempPosition.xMax; tempPosition.xMax += 0.3f * contentPosition.width; maxValue = EditorGUI.FloatField(tempPosition, maxValue); } else { var tempPosition = new Rect(contentPosition); tempPosition.xMax = tempPosition.xMin + 0.2f * contentPosition.width; minValue = EditorGUI.FloatField(tempPosition, minValue); tempPosition.xMin = tempPosition.xMax; tempPosition.xMax += 0.6f * contentPosition.width; EditorGUI.MinMaxSlider(tempPosition, ref minValue, ref maxValue, range.Min, range.Max); tempPosition.xMin = tempPosition.xMax; tempPosition.xMax += 0.2f * contentPosition.width; maxValue = EditorGUI.FloatField(tempPosition, maxValue); } EditorGUI.indentLevel = indentLevel; if (EditorGUI.EndChangeCheck()) { SetValue(minProperty, minValue); SetValue(maxProperty, maxValue); } } }
public override float GetPropertyHeight(InspectableProperty property, GUIContent label) { var height = base.GetPropertyHeight(property, label); if (!useSearchIndex.ContainsKey(property.PropertyPath)) { useSearchIndex.Add(property.PropertyPath, false); } if (useSearchIndex[property.PropertyPath]) { height += EditorGUIUtility.singleLineHeight + 6; } return(height); }
public override void OnGUI(Rect position, InspectableProperty property, GUIContent label) { Initialize(property); EditorGUI.BeginChangeCheck(); DrawPropertySortableArray(position, property, label); if (EditorGUI.EndChangeCheck()) { property.InspectableObject.ApplyModifiedProperties(); Initialize(property, true); } }
public static void CopyComponent(object userData) { InspectableProperty inspectableProperty = (InspectableProperty)userData; datas.Clear(); datas.Add(inspectableProperty.InspectableObject.ParentProperty.GetInspectableObjectData()); if (clipboard.ContainsKey(datas[0].Type)) { clipboard[datas[0].Type] = datas[0]; } else { clipboard.Add(datas[0].Type, datas[0]); } }
protected virtual void EmitPropertyField(Rect position, InspectableProperty targetInspectableProperty, GUIContent label) { var multiline = GetMultilineAttribute(); if (multiline == null) { var range = GetRangeAttribute(); if (range == null) { EasyGUI.PropertyField(position, targetInspectableProperty, label, includeChildren: true); } else { if (targetInspectableProperty.PropertyType == InspectablePropertyType.Float) { EasyGUI.Slider(position, targetInspectableProperty, range.Min, range.Max, label); } else if (targetInspectableProperty.PropertyType == InspectablePropertyType.Integer) { EasyGUI.IntSlider(position, targetInspectableProperty, (int)range.Min, (int)range.Max, label); } else { EditorGUI.LabelField(position, label.text, "Use Range with float or int."); } } } else { var property = targetInspectableProperty; label = EasyGUI.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; } EasyGUI.EndProperty(); } }
public override void OnGUI(Rect position, InspectableProperty property, GUIContent label) { RangeAttribute rangeAttribute = (RangeAttribute)base.Attribute; if (property.PropertyType == InspectablePropertyType.Float) { EasyGUI.Slider(position, property, rangeAttribute.min, rangeAttribute.max, label); } else if (property.PropertyType == InspectablePropertyType.Integer) { EasyGUI.IntSlider(position, property, (int)rangeAttribute.min, (int)rangeAttribute.max, label); } else { EditorGUI.LabelField(position, label.text, "Use Range with float or int."); } }