Ejemplo n.º 1
0
        /**
         * Initialize a new qe_Mesh with @InGameObject.  Must have a valid meshfilter and mesh.
         * GameObject will have it's MeshFilter.sharedMesh property set to the clone mesh for editing.
         * Call qe_Mesh.Revert() to undo this change (and destroy the cloned mesh in the process).
         */
        public static qe_Mesh Create(GameObject InGameObject)
        {
            qe_Mesh qmesh = ScriptableObject.CreateInstance <qe_Mesh>();

            qmesh.hideFlags = HideFlags.DontSave;

            qmesh.gameObject = InGameObject;
            qmesh.transform  = qmesh.gameObject.transform;

            qmesh.originalMesh = InGameObject.GetComponent <MeshFilter>().sharedMesh;
            qmesh.source       = qe_Editor_Utility.GetMeshGUID(qmesh.originalMesh, ref qmesh.originalMeshGUID);

            // Copy mesh from InMesh.
            qmesh.cloneMesh = qe_Mesh_Utility.Clone(InGameObject.GetComponent <MeshFilter>().sharedMesh);
            Undo.RegisterCreatedObjectUndo(qmesh.cloneMesh, "Open Quick Edit");

            Undo.RecordObject(qmesh, "Open Quick Edit");
            qmesh.Apply();

            qmesh.handlesRenderer           = (qe_HandleRenderer)Undo.AddComponent(InGameObject, typeof(qe_HandleRenderer));
            qmesh.handlesRenderer.hideFlags = HideFlags.HideAndDontSave;

            qmesh.handlesRenderer.mesh           = new Mesh();
            qmesh.handlesRenderer.mesh.hideFlags = HideFlags.HideAndDontSave;
            qmesh.handlesRenderer.material       = null;

            qmesh.CacheElements();

            return(qmesh);
        }
Ejemplo n.º 2
0
        /**
         * Do this crazy undo dance because calling Undo.RecordObject(UnityEngine.mesh, "") is insanely slow.
         */
        public static void RecordMeshUndo(qe_Mesh mesh, string message)
        {
            Mesh m = qe_Mesh_Utility.Clone(mesh.cloneMesh);

            Undo.RegisterCreatedObjectUndo(m, message);

            Mesh old = mesh.cloneMesh;

            Undo.RecordObject(mesh, message);
            {
                mesh.cloneMesh = m;
                mesh.Apply();
            }

            Undo.DestroyObjectImmediate(old);

                        #if UNITY_5
            Undo.SetCurrentGroupName(message);
                        #endif
        }