示例#1
0
 void OnSelectModeChanged(SelectMode selectMode)
 {
     if (ToolManager.IsActiveTool(this) && selectMode != SelectMode.Object)
     {
         ToolManager.RestorePreviousTool();
     }
 }
示例#2
0
 void ActiveToolChanging()
 {
     if (ToolManager.IsActiveTool(this))
     {
         EditorApplication.delayCall += () => ChangeToObjectMode();
     }
 }
示例#3
0
 void ChangeToObjectMode()
 {
     if (ToolManager.IsActiveTool(this))
     {
         ProBuilderEditor.selectMode = SelectMode.Object;
     }
 }
示例#4
0
 private void ActiveToolChanged()
 {
     if (Tools.IsActiveTool(this))
     {
         OnActivate();
     }
 }
示例#5
0
 private void ActiveToolChanging()
 {
     if (Tools.IsActiveTool(this))
     {
         OnDeactivate();
     }
 }
示例#6
0
 void ActiveToolDidChange()
 {
     if (!ToolManager.IsActiveTool(this))
     {
         return;
     }
 }
示例#7
0
        /// <summary>
        /// Draws the controls for controlling the comparison module for a particular editor
        /// </summary>
        /// <param name="editor">The editor that the controls are being draw inside.</param>
        void DrawCompareControls(Editor editor)
        {
            // Comparing only works with a single data object, so don't show the compare controls unless this is a Proxy
            if (((MARSEntity)editor.target).GetComponent <Proxy>() == null)
            {
                return;
            }

            if (m_CompareDataModule == null)
            {
                return;
            }

            GUILayout.Space(6f);

            m_CurrentEditor = editor;

            using (new EditorGUILayout.HorizontalScope())
            {
                GUILayout.Label("Compare Tool", MarsEditorGUI.Styles.LabelLeftAligned);

                if (m_CompareDataModule.IsComparing)
                {
                    if (GUILayout.Button(styles.includeAllButtonContent, MarsEditorGUI.Styles.MiniFontButton))
                    {
                        if (EditorUtility.DisplayDialog(k_ModifyConditionActionMessage, k_AreYouSureMessage, k_ConfirmActionMessage, k_CancelActionMessage))
                        {
                            m_CompareDataModule.IncludeAll();
                            Undo.IncrementCurrentGroup();
                            m_SimulatedObjectsManager.DirtySimulatableScene();
                        }
                    }

                    if (GUILayout.Button(styles.optimizeAllButtonContent, MarsEditorGUI.Styles.MiniFontButton))
                    {
                        if (EditorUtility.DisplayDialog(k_ModifyConditionActionMessage, k_AreYouSureMessage, k_ConfirmActionMessage, k_CancelActionMessage))
                        {
                            m_CompareDataModule.OptimizeAll();
                            Undo.IncrementCurrentGroup();
                            m_SimulatedObjectsManager.DirtySimulatableScene();
                        }
                    }

                    if (GUILayout.Button(styles.stopComparingButtonContent, MarsEditorGUI.Styles.MiniFontButton))
                    {
                        ToolManager.RestorePreviousPersistentTool();
                    }
                }
                else
                {
                    if (GUILayout.Button(styles.startComparingButtonContent, MarsEditorGUI.Styles.MiniFontButton))
                    {
                        ToolManager.SetActiveTool <MarsCompareTool>();
                    }
                }
            }
        }
示例#8
0
    public void CutTool_CutUsing3NewVerticesNoLoop_TestInsertionTypes_TestCreates2Faces()
    {
        CutTool tool = ScriptableObject.CreateInstance <CutTool>();

        ToolManager.SetActiveTool(tool);

        int  originalFaceCount = m_PBMesh.faces.Count;
        Face face = m_PBMesh.faces[0];

        Assume.That(face, Is.Not.Null);

        Vertex[] vertices    = m_PBMesh.GetVertices();
        var      faceIndexes = face.distinctIndexes;

        Assume.That(faceIndexes.Count, Is.EqualTo(4));

        Vector3 pos_a = Math.Average(new Vector3[] { vertices[faceIndexes[0]].position, vertices[faceIndexes[1]].position, vertices[faceIndexes[2]].position });
        Vector3 pos_b = Math.Average(new Vector3[] { vertices[faceIndexes[1]].position, vertices[faceIndexes[2]].position, vertices[faceIndexes[3]].position });
        Vector3 pos_c = Math.Average(new Vector3[] { vertices[faceIndexes[0]].position, vertices[faceIndexes[1]].position, vertices[faceIndexes[3]].position });

        //Creating a first new vertex
        tool.UpdateCurrentPosition(face, pos_a, Vector3.up);
        Assert.That(tool.m_CurrentVertexTypes, Is.EqualTo(CutTool.VertexTypes.NewVertex));

        //Insert first vertex to the path
        tool.AddCurrentPositionToPath();
        Assert.That(tool.m_CutPath.Count, Is.EqualTo(1));
        //No connection is created yet
        Assert.That(tool.m_MeshConnections.Count, Is.EqualTo(0));

        //Creating a second new vertex
        tool.UpdateCurrentPosition(face, pos_b, Vector3.up);
        Assert.That(tool.m_CurrentVertexTypes, Is.EqualTo(CutTool.VertexTypes.NewVertex));

        //Insert 2nd point to the path
        tool.AddCurrentPositionToPath();
        Assert.That(tool.m_CutPath.Count, Is.EqualTo(2));
        //Check that the created path is connected twice to the containing face
        Assert.That(tool.m_MeshConnections.Count, Is.EqualTo(2));

        //Creating a third new vertex
        tool.UpdateCurrentPosition(face, pos_c, Vector3.up);
        Assert.That(tool.m_CurrentVertexTypes, Is.EqualTo(CutTool.VertexTypes.NewVertex));

        //Insert 3rd point to the path
        tool.AddCurrentPositionToPath();
        Assert.That(tool.m_CutPath.Count, Is.EqualTo(3));
        //Check that the created path is connected twice to the containing face
        Assert.That(tool.m_MeshConnections.Count, Is.EqualTo(2));

        ActionResult result = tool.DoCut();

        Assert.That(result.status, Is.EqualTo(ActionResult.Success.status));
        Assert.That(m_PBMesh.faces.Count, Is.EqualTo(originalFaceCount - 1 /*removed face*/ + 2 /*added faces*/));

        Object.DestroyImmediate(tool);
    }
示例#9
0
 private static void DuringSceneGui(SceneView sceneView)
 {
     foreach (var tool in m_Tools)
     {
         if (tool.IsAvailable() && ToolManager.IsActiveTool(tool as EditorTool))
         {
             tool.DuringSceneGui(sceneView);
         }
     }
 }
示例#10
0
 void OnToolChanged()
 {
     if (!ToolManager.IsActiveTool(this))
     {
         End();
     }
     else
     {
         SetPolyEditMode(PolyShape.PolyEditMode.Edit);
     }
 }
示例#11
0
 private void HandleActivation()
 {
     if (m_IsActive == false && ToolManager.IsActiveTool(this))
     {
         Activate();
     }
     else if (m_IsActive)
     {
         Deactivate();
     }
 }
示例#12
0
        void OnActiveToolChanged()
        {
            m_ToolIsActive = ToolManager.IsActiveTool(this);
            if (m_CompareDataModule != null)
            {
                if (m_ToolIsActive)
                {
                    m_CompareDataModule.StartComparing();
                    m_CompareDataModule.CompareDataChanged += UpdateOverlayUI;
                }
                else
                {
                    m_CompareDataModule.StopComparing();
                    m_CompareDataModule.CompareDataChanged -= UpdateOverlayUI;
                }

                if (m_SceneViewInteractionModule != null)
                {
                    m_SceneViewInteractionModule.RequestInteraction(this, m_ToolIsActive);
                    if (m_ToolIsActive)
                    {
                        m_SceneViewInteractionModule.SelectionLimit    = 1;
                        m_SceneViewInteractionModule.HoverBegin       += OnHoverBegin;
                        m_SceneViewInteractionModule.HoverEnd         += OnHoverEnd;
                        m_SceneViewInteractionModule.SelectionChanged += OnDataSelectionChanged;
                    }
                    else
                    {
                        m_SceneViewInteractionModule.HoverBegin       -= OnHoverBegin;
                        m_SceneViewInteractionModule.HoverEnd         -= OnHoverEnd;
                        m_SceneViewInteractionModule.SelectionChanged -= OnDataSelectionChanged;
                    }
                }
            }

            if (m_ToolIsActive)
            {
                // Open simulation view if needed
                if (!SimulationSceneModule.UsingSimulation)
                {
                    EditorWindow.GetWindow <SceneView>(); // Need to make sure there is a scene view otherwise the simulation view will close immediately
                    EditorWindow.GetWindow <SimulationView>();
                }

                SimulationView.ActiveSimulationView.Focus();
            }

            UpdateOverlayUI();
            OnSelectionChanged();
        }
示例#13
0
 void ActiveToolDidChange()
 {
     if (ToolManager.IsActiveTool(this))
     {
     }
     else
     {
         if (_impl != null)
         {
             _impl.Dispose();
             _impl = null;
         }
     }
 }
示例#14
0
    public void CutTool_EdgeToEdgeCut_TestInsertOnEdge_TestCreatesTwoFaces()
    {
        CutTool tool = ScriptableObject.CreateInstance <CutTool>();

        ToolManager.SetActiveTool(tool);

        int  originalFaceCount = m_PBMesh.faces.Count;
        Face face = m_PBMesh.faces[0];

        Assert.That(face, Is.Not.Null);

        Vertex[] vertices    = m_PBMesh.GetVertices();
        var      faceIndexes = face.distinctIndexes;

        Assert.That(faceIndexes.Count, Is.EqualTo(4));

        Vector3 pos_a = Math.Average(new Vector3[] { vertices[faceIndexes[0]].position, vertices[faceIndexes[1]].position });
        Vector3 pos_b = Math.Average(new Vector3[] { vertices[faceIndexes[2]].position, vertices[faceIndexes[3]].position });

        tool.UpdateCurrentPosition(face, pos_a, Vector3.up);
        Assert.That(tool.m_TargetFace, Is.Null);
        Assert.That(tool.m_CurrentFace, Is.EqualTo(face));
        Assert.That(tool.m_CurrentVertexTypes, Is.EqualTo(CutTool.VertexTypes.AddedOnEdge));

        tool.AddCurrentPositionToPath();
        Assert.That(tool.m_CutPath.Count, Is.EqualTo(1));
        Assert.That(tool.m_TargetFace, Is.EqualTo(face));
        Assert.That(tool.m_MeshConnections.Count, Is.EqualTo(0));

        tool.UpdateCurrentPosition(face, pos_b, Vector3.up);
        Assert.That(tool.m_CurrentVertexTypes, Is.EqualTo(CutTool.VertexTypes.NewVertex));

        tool.m_SnappingPoint = true;
        tool.UpdateCurrentPosition(face, pos_b, Vector3.up);
        Assert.That(tool.m_CurrentVertexTypes, Is.EqualTo(CutTool.VertexTypes.AddedOnEdge));

        tool.AddCurrentPositionToPath();
        Assert.That(tool.m_CutPath.Count, Is.EqualTo(2));

        ActionResult result = tool.DoCut();

        Assert.That(result.status, Is.EqualTo(ActionResult.Success.status));
        Assert.That(m_PBMesh.faces.Count, Is.EqualTo(originalFaceCount - 1 /*removed face*/ + 2 /*added faces*/));

        Object.DestroyImmediate(tool);
    }
示例#15
0
        protected void DoEditButton <U>(GUIContent icon, string label) where U : PathEditorTool <T>
        {
            const float kButtonWidth  = 33;
            const float kButtonHeight = 23;
            const float k_SpaceBetweenLabelAndButton = 5;
            var         buttonStyle = new GUIStyle("EditModeSingleButton");

            var rect       = EditorGUILayout.GetControlRect(true, kButtonHeight, buttonStyle);
            var buttonRect = new Rect(rect.xMin + EditorGUIUtility.labelWidth, rect.yMin, kButtonWidth, kButtonHeight);

            var labelContent = new GUIContent(label);
            var labelSize    = GUI.skin.label.CalcSize(labelContent);

            var labelRect = new Rect(
                buttonRect.xMax + k_SpaceBetweenLabelAndButton,
                rect.yMin + (rect.height - labelSize.y) * .5f,
                labelSize.x,
                rect.height);

            using (new EditorGUI.DisabledGroupScope(!EditorToolManager.IsAvailable <U>()))
            {
                using (var check = new EditorGUI.ChangeCheckScope())
                {
                    var isActive = GUI.Toggle(buttonRect, EditorToolManager.IsActiveTool <U>(), icon, buttonStyle);

                    GUI.Label(labelRect, label);

                    if (check.changed)
                    {
                        if (isActive)
                        {
                            ToolManager.SetActiveTool <U>();
                        }
                        else
                        {
                            ToolManager.RestorePreviousTool();
                        }
                    }
                }
            }
        }
        void OnActiveToolChanged()
        {
#if UNITY_2020_2_OR_NEWER
            m_ToolIsActive = ToolManager.IsActiveTool(this);
#else
            m_ToolIsActive = EditorTools.EditorTools.IsActiveTool(this);
#endif

            if (m_DataVisualsModule != null)
            {
                m_DataVisualsModule.RequestDataVisuals(this, m_ToolIsActive);
            }

            if (m_ScenePlacementModule != null)
            {
                if (m_ToolIsActive)
                {
                    m_ScenePlacementModule.ObjectDropped += OnObjectDropped;
                }
                else
                {
                    m_ScenePlacementModule.ObjectDropped -= OnObjectDropped;
                }
            }

            if (m_InteractionModule != null)
            {
                m_InteractionModule.RequestInteraction(this, m_ToolIsActive);
                if (m_ToolIsActive)
                {
                    m_InteractionModule.SelectionLimit = 2;
                }
            }

            UpdateInfoOverlayUI();
            UpdateCreateUI();
        }
        /// <summary>
        /// Draw a menu button.  Returns true if the button is active and settings are enabled, false if settings are not enabled.
        /// </summary>
        /// <param name="isHorizontal"></param>
        /// <param name="showOptions"></param>
        /// <param name="optionsRect"></param>
        /// <param name="layoutOptions"></param>
        /// <returns></returns>
        internal override bool DoButton(bool isHorizontal, bool showOptions, ref Rect optionsRect, params GUILayoutOption[] layoutOptions)
        {
            bool wasEnabled    = GUI.enabled;
            bool buttonEnabled = (menuActionState & MenuActionState.Enabled) == MenuActionState.Enabled;

            bool isActiveTool = m_Tool != null && ToolManager.IsActiveTool(m_Tool);

            GUI.enabled = buttonEnabled;

            GUI.backgroundColor = Color.white;

            if (iconMode)
            {
                GUIStyle style = ToolbarGroupUtility.GetStyle(group, isHorizontal);

                Texture2D normalTex = style.normal.background;
                Texture2D hoverTex  = style.hover.background;
                if (isActiveTool)
                {
                    style.normal.background = hoverTex;
                    style.hover.background  = normalTex;
                }

                bool isToggled = GUILayout.Toggle(isActiveTool, buttonEnabled || !disabledIcon ? icon : disabledIcon, style, layoutOptions);
                if (isToggled != isActiveTool)
                {
                    if (showOptions && (optionsMenuState & MenuActionState.VisibleAndEnabled) == MenuActionState.VisibleAndEnabled)
                    {
                        DoAlternateAction();
                    }
                    else
                    {
                        var result = isActiveTool ? EndActivation() : StartActivation();
                        EditorUtility.ShowNotification(result.notification);
                    }
                }

                style.normal.background = normalTex;
                style.hover.background  = hoverTex;

                if ((optionsMenuState & MenuActionState.VisibleAndEnabled) == MenuActionState.VisibleAndEnabled)
                {
                    Rect r = GUILayoutUtility.GetLastRect();
                    r.x      = r.x + r.width - 16;
                    r.y     += 0;
                    r.width  = 14;
                    r.height = 14;
                    GUI.Label(r, IconUtility.GetIcon("Toolbar/Options", IconSkin.Pro), GUIStyle.none);
                    optionsRect = r;
                    GUI.enabled = wasEnabled;
                    return(buttonEnabled);
                }
                else
                {
                    GUI.enabled = wasEnabled;
                    return(false);
                }
            }
            else
            {
                // in text mode always use the vertical layout.
                isHorizontal = false;
                GUILayout.BeginHorizontal(MenuActionStyles.rowStyleVertical, layoutOptions);
                GUI.backgroundColor = ToolbarGroupUtility.GetColor(group);

                GUIStyle   style  = MenuActionStyles.buttonStyleVertical;
                RectOffset border = new RectOffset(style.border.left, style.border.right, style.border.top, style.border.bottom);
                if (isActiveTool)
                {
                    style.border = new RectOffset(0, 4, 0, 0);
                }

                bool isToggled = GUILayout.Toggle(isActiveTool, menuTitle, style);
                if (isToggled != isActiveTool)
                {
                    var result = isActiveTool ? EndActivation() : StartActivation();
                    EditorUtility.ShowNotification(result.notification);
                }

                MenuActionState altState = optionsMenuState;

                if ((altState & MenuActionState.Visible) == MenuActionState.Visible)
                {
                    GUI.enabled = GUI.enabled && (altState & MenuActionState.Enabled) == MenuActionState.Enabled;

                    if (DoAltButton(GUILayout.MaxWidth(21), GUILayout.MaxHeight(16)))
                    {
                        DoAlternateAction();
                    }
                }

                style.border = border;
                GUILayout.EndHorizontal();

                GUI.backgroundColor = Color.white;

                GUI.enabled = wasEnabled;

                return(false);
            }
        }