private void AppendObject(SerializedProperty element, Object objectReference, ReorderableCollection collection) { //we can do more with a custom surrogate delegate :) element.FindPropertyRelative("gameObject").objectReferenceValue = objectReference; element.FindPropertyRelative("name").stringValue = objectReference.name; }
public override float GetPropertyHeight(SerializedProperty property, GUIContent label) { if (_reorderable == null) { _reorderable = new ReorderableCollection(property.FindPropertyRelative("Collection"), true, true, property.displayName); } return(_reorderable != null ? _reorderable.Height : base.GetPropertyHeight(property, label)); }
internal void SetReference(SerializedProperty element, Object objectReference, ReorderableCollection collection) { var prop = !string.IsNullOrEmpty(property) ? element.FindPropertyRelative(property) : null; if (prop != null && prop.propertyType == SerializedPropertyType.ObjectReference) { prop.objectReferenceValue = objectReference; } }
private void OnDisable() { if (_reorderableBase == null) { return; } _reorderableBase.CustomDrawerHeight -= PresetDrawerHeight; _reorderableBase.CustomDrawer -= PresetDrawer; _reorderableBase.CustomAdd -= CustomAdd; _reorderableBase = null; }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { if (_reorderable == null) { _reorderable = new ReorderableCollection(property.FindPropertyRelative("Collection"), true, true, property.displayName); } EditorGUI.BeginProperty(position, label, property); _reorderable.Draw(position); EditorGUI.EndProperty(); }
void OnEnable() { list1 = new ReorderableCollection(serializedObject.FindProperty("list1")) { elementNameProperty = "myEnum" }; list2 = serializedObject.FindProperty("list2"); list3 = new ReorderableCollection(serializedObject.FindProperty("list3")); list3.GetElementNameCallback += GetList3ElementName; }
private void OnEnable() { //custom list with more complex surrogate functionality collection = new ReorderableCollection(serializedObject.FindProperty("objects")) { surrogate = new ReorderableCollection.Surrogate(typeof(GameObject), AppendObject) }; //myClassArray uses an auto surrogate property on the "ReorderableAttribute" //it's limited to only setting a property field to the dragged object reference. Still handy! myClassArray = serializedObject.FindProperty("myClassList"); }
private void OnEnable() { _labelStyle = new GUIStyle(EditorStyles.label); _labelStyle.richText = true; _target = target as AssetsPresetPreprocessBase; _presets = serializedObject.FindProperty("Presets"); _exclude = serializedObject.FindProperty("ExcludeProperties"); _reorderableBase = new ReorderableCollection(_presets); _reorderableBase.CustomDrawerHeight += PresetDrawerHeight; _reorderableBase.CustomDrawer += PresetDrawer; _reorderableBase.CustomAdd += CustomAdd; }
public static ReorderableCollection GetDrawableCollection(SerializedProperty property, ReorderableAttribute attrib = null, int id = -1, string backingListName = DefaultBackingListName) { // if (property == null) { return(null); } if (id == -1) { id = GetListId(property); } if (attrib == null) { attrib = new ReorderableAttribute(); } ReorderableCollection collection = null; var backingList = property.FindPropertyRelative(backingListName); var obj = GetTargetObjectOfProperty(property); if (backingList == null || !backingList.isArray || !(obj is BaseReorderableCollection)) { return(null); } if (!Lists.TryGetValue(id, out collection)) { var icon = !string.IsNullOrEmpty(attrib.elementIconPath) ? AssetDatabase.GetCachedIcon(attrib.elementIconPath) : null; var displayType = attrib.singleLine ? ReorderableCollection.ElementDisplayType.SingleLine : ReorderableCollection.ElementDisplayType.Auto; collection = new ReorderableCollection(backingList, attrib.add, attrib.remove, attrib.draggable, displayType, attrib.elementNameProperty, attrib.elementNameOverride, icon) { Paginate = attrib.paginate, PageSize = attrib.pageSize, sortable = attrib.sortable }; // handle surrogate if any if (attrib.surrogateType != null) { var callback = new SurrogateCallback(attrib.surrogateProperty); collection.surrogate = new ReorderableCollection.Surrogate(attrib.surrogateType, callback.SetReference); } Lists.Add(id, collection); } else { collection.List = backingList; } return(collection); }