private void ChangeSubMode(SubMode subMode) { // Toggle sub-mode. if (subMode == m_subMode) { subMode = SubMode.None; } m_rbSelection = null; m_subMode = subMode; }
public override void OnSceneViewGUI(SceneView sceneView) { // TODO: This is not responsive. if (Manager.KeyEscapeDown) { ChangeMode(Mode.None); EditorUtility.SetDirty(Assembly); } if (m_mode == Mode.RigidBody) { if (Manager.HijackLeftMouseClick()) { Predicate <GameObject> filter = m_subMode == SubMode.None ? new Predicate <GameObject>(obj => { return(obj != null && obj.GetComponent <AGXUnity.Collide.Shape>() == null); }) : m_subMode == SubMode.SelectRigidBody ? new Predicate <GameObject>(obj => { return(obj != null && obj.GetComponentInParent <RigidBody>() != null); }) : null; if (filter == null) { Debug.LogError("Unknown sub-mode in assembly tool.", Assembly); return; } var hitResults = Raycast.TestChildren(Assembly.gameObject, HandleUtility.GUIPointToWorldRay(Event.current.mousePosition), 500f, filter); if (hitResults.Count > 0) { // TODO: If count > 1 - the user should be able to chose which object to select. GameObject selected = hitResults[0].Triangle.Target; if (m_subMode == SubMode.SelectRigidBody) { if (m_rbSelection != null && m_rbSelection.RigidBody == selected.GetComponentInParent <RigidBody>()) { m_rbSelection = null; } else { m_rbSelection = new RigidBodySelection(selected.GetComponentInParent <RigidBody>()); } } else { int selectedIndex = m_selection.FindIndex(entry => { return(entry.Object == selected); }); // New entry, add it. if (selectedIndex < 0) { m_selection.Add(new SelectionEntry(selected)); } // Remove selected entry if it already exist. else { m_selection.RemoveAt(selectedIndex); } } EditorUtility.SetDirty(Assembly); } } } else if (m_mode == Mode.Shape) { // ShapeCreateTool on scene view handles this. } else if (m_mode == Mode.Constraint) { // ConstraintCreateTool on scene view handles this. } }