Ejemplo n.º 1
0
        void SetupReordeableList()
        {
            m_ReorderableList = new ReorderableList(serializedObject, m_SolversProperty, true, true, true, true);
            m_ReorderableList.drawHeaderCallback = (Rect rect) =>
            {
                GUI.Label(rect, Contents.listHeaderLabel);
            };
            m_ReorderableList.elementHeightCallback = (int index) =>
            {
                return(EditorGUIUtility.singleLineHeight + 6);
            };
            m_ReorderableList.drawElementCallback = (Rect rect, int index, bool isactive, bool isfocused) =>
            {
                rect.y     += 2f;
                rect.height = EditorGUIUtility.singleLineHeight;
                SerializedProperty element     = m_SolversProperty.GetArrayElementAtIndex(index);
                SerializedProperty elementData = m_SolverEditorDataProperty.GetArrayElementAtIndex(index);
                var width = rect.width;
                rect.width = width > Contents.showGizmoPropertyWidth ? Contents.showGizmoPropertyWidth : width;
                var showGizmoProperty = elementData.FindPropertyRelative("showGizmo");
                showGizmoProperty.boolValue = GUI.Toggle(rect, showGizmoProperty.boolValue, Contents.gizmoVisibilityToolTip, k_Contents.visibilityToggleStyle);
                rect.x    += rect.width;
                width     -= rect.width;
                rect.width = width > Contents.solverPropertyWidth ? width - Contents.solverColorPropertyWidth  : Contents.solverPropertyWidth;
                EditorGUI.PropertyField(rect, element, GUIContent.none);
                rect.x    += rect.width;
                width     -= 100;
                rect.width = width > Contents.solverColorPropertyWidth ? Contents.solverColorPropertyWidth : width;
                EditorGUI.PropertyField(rect, elementData.FindPropertyRelative("color"), Contents.gizmoColorTooltip);
            };
            m_ReorderableList.onAddCallback = (ReorderableList list) =>
            {
                var menu = new GenericMenu();

                foreach (Type type in m_SolverTypes)
                {
                    Solver2DMenuAttribute attribute = Attribute.GetCustomAttribute(type, typeof(Solver2DMenuAttribute)) as Solver2DMenuAttribute;

                    if (attribute != null)
                    {
                        menu.AddItem(new GUIContent(attribute.menuPath), false, OnSelectMenu, type);
                    }
                    else
                    {
                        menu.AddItem(new GUIContent(type.Name), false, OnSelectMenu, type);
                    }
                }

                menu.ShowAsContext();
            };
            m_ReorderableList.onRemoveCallback = (ReorderableList list) =>
            {
                Solver2D solver = m_Manager.solvers[list.index];
                if (solver)
                {
                    Undo.RegisterCompleteObjectUndo(m_Manager, Undo.GetCurrentGroupName());

                    m_Manager.RemoveSolver(solver);

                    GameObject solverGO = solver.gameObject;

                    if (solverGO.transform.childCount == 0)
                    {
                        Undo.DestroyObjectImmediate(solverGO);
                    }
                    else
                    {
                        Undo.DestroyObjectImmediate(solver);
                    }

                    EditorUtility.SetDirty(m_Manager);
                }
                else
                {
                    ReorderableList.defaultBehaviours.DoRemoveButton(list);
                }
            };
        }
        public void SetupReordeableList()
        {
            m_ReorderableList = new ReorderableList(serializedObject, m_SolversProperty, true, true, true, true);
            m_ReorderableList.drawHeaderCallback = (Rect rect) =>
            {
                GUI.Label(rect, Contents.listHeaderLabel);
            };
            m_ReorderableList.elementHeightCallback = (int index) =>
            {
                return(EditorGUIUtility.singleLineHeight + 6);
            };
            m_ReorderableList.drawElementCallback = (Rect rect, int index, bool isactive, bool isfocused) =>
            {
                rect.y     += 2f;
                rect.height = EditorGUIUtility.singleLineHeight;
                SerializedProperty element = m_SolversProperty.GetArrayElementAtIndex(index);
                EditorGUI.PropertyField(rect, element, GUIContent.none);
            };
            m_ReorderableList.onAddCallback = (ReorderableList list) =>
            {
                var menu = new GenericMenu();

                foreach (Type type in m_SolverTypes)
                {
                    Solver2DMenuAttribute attribute = Attribute.GetCustomAttribute(type, typeof(Solver2DMenuAttribute)) as Solver2DMenuAttribute;

                    if (attribute != null)
                    {
                        menu.AddItem(new GUIContent(attribute.menuPath), false, OnSelectMenu, type);
                    }
                    else
                    {
                        menu.AddItem(new GUIContent(type.Name), false, OnSelectMenu, type);
                    }
                }

                menu.ShowAsContext();
            };
            m_ReorderableList.onRemoveCallback = (ReorderableList list) =>
            {
                Solver2D solver = m_Manager.solvers[list.index];
                if (solver)
                {
                    Undo.RegisterCompleteObjectUndo(m_Manager, Undo.GetCurrentGroupName());

                    m_Manager.RemoveSolver(solver);

                    GameObject solverGO = solver.gameObject;

                    if (solverGO.transform.childCount == 0)
                    {
                        Undo.DestroyObjectImmediate(solverGO);
                    }
                    else
                    {
                        Undo.DestroyObjectImmediate(solver);
                    }

                    EditorUtility.SetDirty(m_Manager);
                }
                else
                {
                    ReorderableList.defaultBehaviours.DoRemoveButton(list);
                }
            };
        }