Esempio n. 1
0
        void OnEnable()
        {
            if (EditorApplication.isPlayingOrWillChangePlaymode)
            {
                return;
            }

            m_Mesh = (ProBuilderMesh)target;

            if (!m_Mesh)
            {
                return;
            }

            m_GameObjectsSerializedObject = new SerializedObject(serializedObject.targetObjects.Select(t => ((Component)t).gameObject).ToArray());

            m_UnwrapParameters  = serializedObject.FindProperty("m_UnwrapParameters");
            m_StaticEditorFlags = m_GameObjectsSerializedObject.FindProperty("m_StaticEditorFlags");
            m_MeshRenderer      = m_Mesh.gameObject.GetComponent <Renderer>();

            SelectionRenderState s = EditorUtility.GetSelectionRenderState();

            EditorUtility.SetSelectionRenderState(m_MeshRenderer, editor != null ? s & SelectionRenderState.Outline : s);

            foreach (var mesh in Selection.transforms.GetComponents <ProBuilderMesh>())
            {
                EditorUtility.SynchronizeWithMeshFilter(mesh);
            }

            VertexManipulationTool.beforeMeshModification += OnBeginMeshModification;
            VertexManipulationTool.afterMeshModification  += OnFinishMeshModification;
        }
Esempio n. 2
0
        /// <summary>
        /// Hide the default unity wireframe renderer
        /// </summary>
        void HideSelectedWireframe()
        {
            foreach (ProBuilderMesh pb in selection)
            {
                EditorUtility.SetSelectionRenderState(pb.gameObject.GetComponent <Renderer>(),
                                                      EditorUtility.GetSelectionRenderState() & SelectionRenderState.Outline);
            }

            SceneView.RepaintAll();
        }
Esempio n. 3
0
        void OnDisable()
        {
            s_Instance = null;

            VertexManipulationTool.beforeMeshModification -= BeforeMeshModification;
            VertexManipulationTool.afterMeshModification  -= AfterMeshModification;

            if (s_EditorToolbar != null)
            {
                DestroyImmediate(s_EditorToolbar);
            }

            ClearElementSelection();

            UpdateSelection();

            if (selectionUpdated != null)
            {
                selectionUpdated(null);
            }

#if UNITY_2019_1_OR_NEWER
            SceneView.duringSceneGui -= OnSceneGUI;
#else
            SceneView.onSceneGUIDelegate -= OnSceneGUI;
#endif
            ProGridsInterface.UnsubscribePushToGridEvent(PushToGrid);
            ProGridsInterface.UnsubscribeToolbarEvent(ProGridsToolbarOpen);
            MeshSelection.objectSelectionChanged -= OnObjectSelectionChanged;

            // re-enable unity wireframe
            // todo set wireframe override in pb_Selection, no pb_Editor
            foreach (var pb in FindObjectsOfType <ProBuilderMesh>())
            {
                EditorUtility.SetSelectionRenderState(pb.gameObject.GetComponent <Renderer>(),
                                                      EditorUtility.GetSelectionRenderState());
            }

            if (selectModeChanged != null)
            {
                selectModeChanged(SelectMode.Object);
            }

            SceneView.RepaintAll();
        }
        public static void DoStrip(ProBuilderMesh pb)
        {
            try
            {
                GameObject go = pb.gameObject;

                Renderer ren = go.GetComponent <Renderer>();

                if (ren != null)
                {
                    EditorUtility.SetSelectionRenderState(ren, EditorUtility.GetSelectionRenderState());
                }

                if (EditorUtility.IsPrefabAsset(go))
                {
                    return;
                }

                EditorUtility.SynchronizeWithMeshFilter(pb);

                if (pb.mesh == null)
                {
                    DestroyImmediate(pb);

                    if (go.GetComponent <Entity>())
                    {
                        DestroyImmediate(go.GetComponent <Entity>());
                    }

                    return;
                }

                string cachedMeshPath;
                Mesh   cachedMesh;

                // if meshes are assets and the mesh cache is valid don't duplicate the mesh to an instance.
                if (Experimental.meshesAreAssets && EditorMeshUtility.GetCachedMesh(pb, out cachedMeshPath, out cachedMesh))
                {
                    pb.preserveMeshAssetOnDestroy = true;
                    DestroyImmediate(pb);
                    if (go.GetComponent <Entity>())
                    {
                        DestroyImmediate(go.GetComponent <Entity>());
                    }
                }
                else
                {
                    Mesh m = UnityEngine.ProBuilder.MeshUtility.DeepCopy(pb.mesh);

                    DestroyImmediate(pb);

                    if (go.GetComponent <Entity>())
                    {
                        DestroyImmediate(go.GetComponent <Entity>());
                    }

                    go.GetComponent <MeshFilter>().sharedMesh = m;
                    if (go.GetComponent <MeshCollider>())
                    {
                        go.GetComponent <MeshCollider>().sharedMesh = m;
                    }
                }
            }
            catch {}
        }