public void RemoveSolverFromManager_ManagerDoesNotHaveSolverInList() { var go1 = new GameObject(); var solver1 = go1.AddComponent <LimbSolver2D>(); go1.transform.parent = ikGO.transform; var go2 = new GameObject(); var solver2 = go1.AddComponent <LimbSolver2D>(); go2.transform.parent = ikGO.transform; manager.AddSolver(solver1); manager.AddSolver(solver2); manager.RemoveSolver(solver2); Assert.IsTrue(manager.solvers.Contains(solver1)); Assert.IsFalse(manager.solvers.Contains(solver2)); }
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); } }; }