protected override void OnDraw(Rect position, SerializedProperty property, GUIContent label) { ActionBase instance = PropertyDrawerTools.GetPropertyInstance <ActionBase>(property); if (instance) { EditorGUI.BeginProperty(position, label, property); if (label.text != string.Empty) { Rect r1 = OnGUIUtility.Layout.Divide.FirstRect(position, 3); EditorGUI.PrefixLabel(r1, label); Rect r2 = OnGUIUtility.Layout.Divide.NextRect(r1); GUI.backgroundColor = instance.ActionColor; EditorGUI.LabelField(r2, instance.ActionName, ActionBaseInspector.ActionStyle); GUI.backgroundColor = Color.white; Rect r3 = OnGUIUtility.Layout.Divide.NextRect(r2); property.objectReferenceValue = EditorGUI.ObjectField(r3, instance, typeof(ActionBase), true); } else { Rect r2; Rect r1 = OnGUIUtility.Layout.Divide.Golden(position, out r2); GUI.backgroundColor = instance.ActionColor; EditorGUI.LabelField(r1, instance.ActionName, ActionBaseInspector.ActionStyle); GUI.backgroundColor = Color.white; property.objectReferenceValue = EditorGUI.ObjectField(r2, instance, typeof(ActionBase), true); } EditorGUI.EndProperty(); } else { EditorGUI.PropertyField(position, property, label); } }
private void Remove(ReorderableList list) { IList l = PropertyDrawerTools.GetPropertyInstance <IList>(currentList.serializedProperty); if (l != null) { l.RemoveAt(list.index); } }
private void DrawHeader(Rect rect) { GUI.Label(rect, currentList.serializedProperty.name); var eventType = Event.current.type; if (eventType == EventType.DragUpdated || eventType == EventType.DragPerform) { if (rect.Contains(Event.current.mousePosition)) { // Show a copy icon on the drag DragAndDrop.visualMode = DragAndDropVisualMode.Link; if (eventType == EventType.DragPerform) { DragAndDrop.AcceptDrag(); if (DragAndDrop.objectReferences.Length > 0) { IList list = PropertyDrawerTools.GetPropertyInstance <IList>(currentList.serializedProperty); if (list != null) { Type t = list.GetType().GetGenericArguments()[0]; foreach (Object reference in DragAndDrop.objectReferences) { if (reference is GameObject) { if (t == typeof(GameObject)) { list.Add(reference); } else { Component c = (reference as GameObject).GetComponent(t); if (c) { list.Add(c); } } } else if (reference.GetType() == t || reference.GetType().IsSubclassOf(t)) { list.Add(reference); } } } } } Event.current.Use(); } } }
protected override void OnDraw(Rect position, SerializedProperty property, GUIContent label) { State target = PropertyDrawerTools.GetPropertyInstance <State>(property, this.fieldInfo); if (target != null && target.BindEnum != null) { string[] enumstr = Enum.GetNames(target.BindEnum.GetType()); Undo.RecordObject(property.serializedObject.targetObject, "StateChange"); target.Current = EditorGUI.MaskField(position, label, target.Current, enumstr); } else { EditorGUI.PropertyField(position, property.FindPropertyRelative("Current")); } }
private void DrawFooter(Rect rect) { float xMax = rect.xMax; float num = xMax - 8f; if (currentList.displayAdd) { num -= 25f; } if (currentList.displayRemove) { num -= 25f; } Rect r0 = new Rect(rect.x, rect.y, 25f, 13f); Rect p0 = new Rect(rect.x, rect.y - 4f, 25f, 13f); rect = new Rect(num, rect.y, xMax - num, rect.height); Rect rect2 = new Rect(num + 4f, rect.y - 3f, 25f, 13f); Rect rect3 = new Rect(xMax - 29f, rect.y - 3f, 25f, 13f); if (Event.current.type == EventType.Repaint) { ReorderableList.defaultBehaviours.footerBackground.Draw(rect, false, false, false, false); ReorderableList.defaultBehaviours.footerBackground.Draw(r0, false, false, false, false); } if (GUI.Button(p0, "c", ReorderableList.defaultBehaviours.preButton)) { IList list = PropertyDrawerTools.GetPropertyInstance <IList>(currentList.serializedProperty); if (list != null) { list.Clear(); } } if (currentList.displayAdd) { if (GUI.Button( rect2, (currentList.onAddDropdownCallback == null) ? ReorderableList.defaultBehaviours.iconToolbarPlus : ReorderableList.defaultBehaviours.iconToolbarPlusMore, ReorderableList.defaultBehaviours.preButton)) { if (currentList.onAddDropdownCallback != null) { currentList.onAddDropdownCallback(rect2, currentList); } else if (currentList.onAddCallback != null) { currentList.onAddCallback(currentList); } else { ReorderableList.defaultBehaviours.DoAddButton(currentList); } if (currentList.onChangedCallback != null) { currentList.onChangedCallback(currentList); } } } if (currentList.displayRemove) { using (new EditorGUI.DisabledScope(currentList.index < 0 || currentList.index >= currentList.count || (currentList.onCanRemoveCallback != null && !currentList.onCanRemoveCallback(currentList)))) { if (GUI.Button(rect3, ReorderableList.defaultBehaviours.iconToolbarMinus, ReorderableList.defaultBehaviours.preButton)) { Remove(currentList); if (currentList.onChangedCallback != null) { currentList.onChangedCallback(currentList); } } } } }
public override void OnGUI() { base.OnGUI(); if (Current != null) { GUI.enabled = false; EditorGUILayout.ObjectField("Current ActionList", Current, typeof(ActionList), true); GUI.enabled = true; EditorGUI.BeginChangeCheck(); obj.Update(); SerializedProperty property = obj.GetIterator(); bool enterChildren = true; while (property.NextVisible(enterChildren)) { using (new EditorGUI.DisabledScope("m_Script" == property.propertyPath)) { if (property.propertyType == SerializedPropertyType.Generic && property.type == "vector") { InspectorPlus.Singleton singleAtt = PropertyDrawerTools.GetAttribute <InspectorPlus.Singleton>(property); if (singleAtt != null) { IList listInstance = PropertyDrawerTools.GetPropertyInstance <IList>(property); if (listInstance != null) { for (int i = 0; i < listInstance.Count; i++) { var listElement = listInstance[i]; for (int j = listInstance.Count - 1; j > i; j--) { var listElement1 = listInstance[j]; if (listElement == listElement1) { listInstance.RemoveAt(j); } } } } } InspectorPlus.Orderable att = PropertyDrawerTools.GetAttribute <InspectorPlus.Orderable>(property); if (att != null) { ReorderableList list = RecorderLists[property.name]; currentList = list; bool show = EditorPrefs.GetBool(property.propertyPath); show = EditorGUILayout.Foldout(show, property.name); if (show) { list.DoLayoutList(); foreach (int i in deleteList) { property.DeleteArrayElementAtIndex(i); } deleteList.Clear(); } EditorPrefs.SetBool(property.propertyPath, show); } else { EditorGUILayout.PropertyField(property, true, new GUILayoutOption[0]); } } else { EditorGUILayout.PropertyField(property, true, new GUILayoutOption[0]); } } enterChildren = false; } obj.ApplyModifiedProperties(); EditorGUI.EndChangeCheck(); } DebugAllList(); DebugAllPack(); DebugPlayer(); DebugActions(); }