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 void DrawPropertySortableArray(Rect position, SerializedProperty property, GUIContent label) { // Try to get the sortable list this property belongs to ReorderableListData 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; // 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; EditorGUI.PropertyField(fieldPosition, property); bool doCreate = GUI.Button(buttonPosition, Create, EditorStyles.miniButton); if (doCreate) { var propType = property.GetTypeReflection(); ScriptableObjectUtility.CreateAssetWithSavePrompt(propType, postCreated: createdAsset => { property.objectReferenceValue = createdAsset; property.isExpanded = true; return(false); }); } } } else { EditorGUI.PropertyField(position, property, label, property.isExpanded); } }
public override float GetPropertyHeight(SerializedProperty property, GUIContent label) { // Try to get the sortable list this property belongs to ReorderableListData listData = null; if (listDataDict.Count > 0) { listData = listDataDict.Find(data => property.propertyPath.StartsWith(data.Parent)); } return(listData != null?listData.GetPropertyHeight(property) : EditorGUI.GetPropertyHeight(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)); }
private void CreateListData(SerializedProperty 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); data.EditableCallback = () => { if (!property.IsInspectableObjectDataArrayOrList()) { return(!Application.isPlaying); } return(true); }; 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); } } if (property.HasAttribute <DropdownMenuAttribute>()) { var dropDownAttr = property.GetAttributes <DropdownMenuAttribute>()[0] as DropdownMenuAttribute; var reorderableList = data.GetPropertyList(property); reorderableTypeIndex.Add(reorderableList, dropDownAttr.Type); reorderableList.onAddDropdownCallback += OnAddDropdownHandler; reorderableList.onRemoveCallback += OnRemoveHandler; } }
private void CreateListData(SerializedProperty property) { var root = property.GetRootPath(); // Try to find the grand parent in ReorderableListData var data = listDataDict.Find(listData => listData.Parent.Equals(root)); if (data == null) { data = new ReorderableListData(root); listDataDict.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); } } if (property.HasAttribute <PropertyAttribute>()) { foreach (var attr in property.GetAttributes <PropertyAttribute>()) { if (attr is ReorderableAttribute || attr is BackgroundColorAttribute || attr is DropdownMenuAttribute) { } else { data.ElementAttributes.Add(attr as PropertyAttribute); } } } }
private void HandleBackgroundColorOptions(BackgroundColorAttribute bgColorAttr, SerializedProperty property, ReorderableListData data) { data.DrawBackgroundCallback = (active, focused) => { if (focused) { return(1.35f * bgColorAttr.Color); } else if (active) { return(Color.Lerp(Color.white, bgColorAttr.Color, 0.75f)); } else { return(bgColorAttr.Color); } }; }
private void HandleReorderableOptions(ReorderableAttribute reorderableAttr, SerializedProperty property, ReorderableListData data) { data.HeaderCallback = rect => { return(DoHeader(property, rect, reorderableAttr.DisplayName)); }; if (!string.IsNullOrEmpty(reorderableAttr.ElementName)) { data.ElementNameCallback = i => string.Format(ElementNameStr, reorderableAttr.ElementName, i); } }
private void HandleReorderableOptions(ReorderableAttribute reorderableAttr, InspectableProperty property, ReorderableListData data) { data.HeaderCallback = rect => { return(DoHeader(property, rect, reorderableAttr.DisplayName)); }; if (!string.IsNullOrEmpty(reorderableAttr.ElementName)) { data.ElementNameCallback = i => string.Format(ElementNameStr, reorderableAttr.ElementName, i); } else if (reorderableAttr.ElementName == null) { data.ElementNameCallback = i => null; } data.IsDrawObjectReference = reorderableAttr.IsDrawObjectReference; }
private void CreateListData(SerializedProperty property) { var root = property.GetRootPath(); // Try to find the grand parent in ReorderableListData var data = listDataDict.Find(listData => listData.Parent.Equals(root)); if (data == null) { data = new ReorderableListData(root); listDataDict.Add(data); } data.AddProperty(property); data.EditableCallback = () => { if (Application.isPlaying && property.HasAttribute <RuntimeObjectAttribute>()) { return(false); } return(true); }; 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); } } if (property.HasAttribute <DropdownMenuAttribute>()) { var dropDownAttr = property.GetAttributes <DropdownMenuAttribute>()[0] as DropdownMenuAttribute; var reorderableList = data.GetPropertyList(property); reorderableTypeDict.Add(reorderableList, dropDownAttr.Type); reorderableList.onAddDropdownCallback += OnAddDropdownHandler; reorderableList.onRemoveCallback += OnRemoveHandler; } if (property.HasAttribute <PropertyAttribute>()) { foreach (var attr in property.GetAttributes <PropertyAttribute>()) { if (attr is ReorderableAttribute || attr is BackgroundColorAttribute || attr is DropdownMenuAttribute) { } else { data.ElementAttributes.Add(attr as PropertyAttribute); } } } }
private void HandleReorderableOptions(ReorderableAttribute reorderableAttr, SerializedProperty property, ReorderableListData data) { data.HeaderCallback = rect => { return(DoHeader(property, rect, reorderableAttr.DisplayName)); }; data.HeaderMenuCallback = (genericMenu) => { return(DoHeaderMenu(property, genericMenu)); }; if (!string.IsNullOrEmpty(reorderableAttr.ElementName)) { data.ElementNameCallback = i => string.Format(ElementNameStr, reorderableAttr.ElementName, i); } else if (reorderableAttr.ElementName == null) { data.ElementNameCallback = i => null; } data.ElementHeaderCallback = (position, label, inspectableObject) => { return(DoElementHeader(position, label, inspectableObject)); }; data.ElementFooterCallback = (position, inspectableObject) => { DoElementFooter(position, inspectableObject); }; data.IsDrawObjectReference = reorderableAttr.IsDrawObjectReference; }