Esempio n. 1
0
        private void DoOriginalMeshes()
        {
            EditorGUI.BeginChangeCheck();
            Mesh originalMesh = (Mesh)EditorGUILayout.ObjectField("OriginalMesh", m_deformer.Original, typeof(Mesh), false);

            if (EditorGUI.EndChangeCheck())
            {
                EditorUtility.SetDirty(m_deformer);
                Undo.RecordObject(m_deformer, "Battlehub.MeshDeformer.OriginalMeshes");
                m_deformer.Original            = originalMesh;
                m_deformer.Internal_HasChanged = true;
            }

            EditorGUI.BeginChangeCheck();
            Mesh colliderOriginalMesh = (Mesh)EditorGUILayout.ObjectField("Original Collider Mesh", m_deformer.ColliderOriginal, typeof(Mesh), false);

            if (EditorGUI.EndChangeCheck())
            {
                EditorUtility.SetDirty(m_deformer);
                Undo.RecordObject(m_deformer, "Battlehub.MeshDeformer.OriginalMeshes");

                MeshCollider collider = m_deformer.GetComponent <MeshCollider>();
                if (collider != null)
                {
                    Undo.RecordObject(collider, "Battlehub.MeshDeformer.OriginalMeshes");
                    if (colliderOriginalMesh)
                    {
                        collider.sharedMesh      = GameObject.Instantiate(colliderOriginalMesh);
                        collider.sharedMesh.name = colliderOriginalMesh.name + " Collider";
                    }
                    else
                    {
                        collider.sharedMesh = new Mesh();
                    }

                    m_deformer.ColliderOriginal = collider.sharedMesh;
                }

                m_deformer.Internal_HasChanged = true;
            }
        }
Esempio n. 2
0
        public static bool Rollback(GameObject selected)
        {
            MeshDeformer deformer = selected.GetComponentInParent <MeshDeformer>();

            if (deformer != null)
            {
                selected = deformer.gameObject;
                Selection.activeGameObject = selected;
            }
            MeshFilter meshFilter = selected.GetComponent <MeshFilter>();

            if (meshFilter == null)
            {
                EditorUtility.DisplayDialog("MeshFilter required", "Select object with MeshFilter component", "OK");
                return(false);
            }

            if (deformer != null)
            {
                if (!EditorUtility.DisplayDialog("Are you sure?", "This action is irreversible. Deformation will be lost", "Ok", "Cancel"))
                {
                    return(false);
                }

                ControlPoint[] controlPoints = deformer.GetComponentsInChildren <ControlPoint>(true);
                for (int i = 0; i < controlPoints.Length; ++i)
                {
                    Object.DestroyImmediate(controlPoints[i].gameObject);
                }

                Scaffold[] scaffolds = deformer.GetComponentsInChildren <Scaffold>();
                for (int i = 0; i < scaffolds.Length; ++i)
                {
                    if (scaffolds[i].gameObject != deformer.gameObject)
                    {
                        Object.DestroyImmediate(scaffolds[i].gameObject);
                    }
                }

                Mesh original = deformer.Original;
                meshFilter.sharedMesh = original;

                Mesh colliderOriginal = deformer.ColliderOriginal;
                if (colliderOriginal != null)
                {
                    MeshCollider collider = deformer.GetComponent <MeshCollider>();
                    if (collider != null)
                    {
                        collider.sharedMesh = colliderOriginal;
                    }
                }

                Object.DestroyImmediate(deformer);
            }


            Scaffold scaffold = selected.GetComponent <Scaffold>();

            if (scaffold != null)
            {
                Object.DestroyImmediate(scaffold);
            }

            return(true);
        }