Esempio n. 1
0
        protected virtual void DrawToolUI()
        {
            if (GUILayout.Button("Color Fill", curSkin.button, GUILayout.Height(44), GUILayout.ExpandWidth(true)))
            {
                GameObject curSelected = EF_VertexPainter_Utils.GetSelection();
                Mesh       curMesh     = EF_VertexPainter_Utils.GetMesh(curSelected);

                EF_VertexPainter_Utils.FillMeshWithColor(curMesh, m_BrushData.brushColor);
            }

            if (GUILayout.Button("Add Mesh Collider", curSkin.button, GUILayout.Height(44), GUILayout.ExpandWidth(true)))
            {
                //Get the Selected GO
                GameObject curSelected = EF_VertexPainter_Utils.GetSelection();

                //Add the Mesh Collider
                EF_VertexPainter_Utils.AddMeshCollider(curSelected);
            }

            if (GUILayout.Button("Save Mesh", curSkin.button, GUILayout.Height(44), GUILayout.ExpandWidth(true)))
            {
                //Get the current selection
                GameObject curSelected = EF_VertexPainter_Utils.GetSelection();

                //Save the mesh
                EF_VertexPainter_Utils.SaveMesh(curSelected);
            }
        }
Esempio n. 2
0
        void OnSceneGUI(SceneView sceneView)
        {
            ProcessInputs();

            if (m_CurrentState == EF_VTXPainterState.Painting || m_CurrentState == EF_VTXPainterState.Sculpting)
            {
                //Raycast into the scene and see if we are hitting anything
                Ray worldRay = HandleUtility.GUIPointToWorldRay(m_MouseData.mousePos);
                if (!Physics.Raycast(worldRay, out m_CurHit, float.MaxValue))
                {
                    m_CurrentGO   = null;
                    m_CurrentMesh = null;
                    return;
                }
                m_CurrentGO = m_CurHit.transform.gameObject;

                //Show the Brush
                if (m_CurHit.transform != null)
                {
                    if (m_CurrentState == EF_VTXPainterState.Painting)
                    {
                        Handles.color = m_BrushData.brushColor;
                    }

                    if (m_CurrentState == EF_VTXPainterState.Sculpting)
                    {
                        Handles.color = Color.red;
                    }
                    Handles.DrawWireDisc(m_CurHit.point, m_CurHit.normal, m_BrushData.falloffSize);
                    Handles.DrawWireDisc(m_CurHit.point, m_CurHit.normal, m_BrushData.brushSize);

                    Handles.color = new Color(Handles.color.r, Handles.color.g, Handles.color.b, m_BrushData.opacity);
                    Handles.DrawSolidDisc(m_CurHit.point, m_CurHit.normal, m_BrushData.brushSize);
                }

                //Get the Mesh only if its different than what is in the current it object
                if (m_CurHit.transform.GetInstanceID() != m_CurrentGO.GetInstanceID())
                {
                    m_CurrentMesh = EF_VertexPainter_Utils.GetMesh(m_CurrentGO);
                }

                //Set Scene View to passive so we can paint without selecting anything
                Tools.current = Tool.None;
                HandleUtility.AddDefaultControl(GUIUtility.GetControlID(FocusType.Passive));
            }

            //Handle the Functions of the brush
            if (m_MouseData.leftClickHold)
            {
                EF_VertexPainter_Utils.HandleBrush(m_CurrentGO, m_CurrentMesh, m_CurHit.point, m_BrushData, m_CurrentState);
                if (m_CurrentMesh)
                {
                    EditorUtility.SetDirty(m_CurrentMesh);
                }
                m_WasPainting = true;
            }
            else
            {
                if (m_WasPainting && m_CurrentGO)
                {
                    MeshCollider curCollider = m_CurrentGO.GetComponent <MeshCollider>();
                    if (curCollider)
                    {
                        curCollider.convex = true;
                        curCollider.convex = false;
                    }

                    m_WasPainting = false;
                }
            }


            //Update the Scene View
            sceneView.Repaint();
        }