Exemple #1
0
        private static void Subdivide()
        {
            if (Application.isPlaying)
            {
                EditorUtility.DisplayDialog("Unable to Subdivide Mesh", "Application.isPlaying == true", "OK");
                return;
            }

            foreach (Transform transform in Selection.transforms)
            {
                MeshFilter meshFilter = transform.GetComponent <MeshFilter>();
                if (meshFilter == null)
                {
                    Debug.LogWarning("Select object with MeshFilter component attached");
                    return;
                }

                if (meshFilter.sharedMesh == null)
                {
                    Debug.LogError("meshFilter.sharedMesh is null");
                    return;
                }

                Undo.RecordObject(meshFilter, "Subdivide");
                HBFixBounds hbFixBounds = transform.GetComponent <HBFixBounds>();
                if (hbFixBounds == null)
                {
                    Mesh mesh = Subdivider.Subdivide4(meshFilter.sharedMesh);
                    if (!meshFilter.sharedMesh.name.Contains("HBSubdivided"))
                    {
                        mesh.name = meshFilter.sharedMesh.name + " HBSubdivided";
                    }
                    else
                    {
                        mesh.name = meshFilter.sharedMesh.name;
                    }
                    meshFilter.sharedMesh = mesh;
                }
                else
                {
                    if (hbFixBounds.OriginalMesh != meshFilter.sharedMesh)
                    {
                        hbFixBounds.Rollback();
                    }

                    Mesh mesh = Subdivider.Subdivide4(meshFilter.sharedMesh);
                    if (!hbFixBounds.OriginalMesh.name.Contains("HBSubdivided"))
                    {
                        mesh.name = hbFixBounds.OriginalMesh.name + " HBSubdivided";
                    }
                    else
                    {
                        mesh.name = hbFixBounds.OriginalMesh.name;
                    }

                    hbFixBounds.OriginalMesh = mesh;
                    hbFixBounds.FixBounds(false);
                }
                Undo.RecordObject(meshFilter, "Subdivide");
            }
        }
Exemple #2
0
        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            HBFixBounds fixBounds = (HBFixBounds)target;

            if (HB.Instance != null)
            {
                if (fixBounds.OverrideBounds)
                {
                    if (fixBounds.SkinnedMesh != null && fixBounds.MeshFilter != null)
                    {
                        DrawPropertiesExcluding(serializedObject, "BendingMode", "Curvature", "Flatten", "HorizonZOffset", "HorizonYOffset", "HorizonXOffset", "FixBoundsRadius");
                    }
                    else if (fixBounds.SkinnedMesh != null)
                    {
                        DrawPropertiesExcluding(serializedObject, "Bounds", "BendingMode", "Curvature", "Flatten", "HorizonZOffset", "HorizonYOffset", "HorizonXOffset", "FixBoundsRadius");
                    }
                    else if (fixBounds.MeshFilter != null)
                    {
                        DrawPropertiesExcluding(serializedObject, "SkinnedBounds", "BendingMode", "Curvature", "Flatten", "HorizonZOffset", "HorizonYOffset", "HorizonXOffset", "FixBoundsRadius");
                    }
                    else
                    {
                        DrawPropertiesExcluding(serializedObject, "Bounds", "SkinnedBounds", "BendingMode", "Curvature", "Flatten", "HorizonZOffset", "HorizonYOffset", "HorizonXOffset", "FixBoundsRadius");
                    }
                }
                else
                {
                    DrawPropertiesExcluding(serializedObject,
                                            "SkinnedBounds", "Bounds", "Lock", "BendingMode", "Curvature", "Flatten", "HorizonZOffset", "HorizonYOffset", "HorizonXOffset", "FixBoundsRadius");
                }
            }
            else
            {
                if (!fixBounds.OverrideBounds)
                {
                    DrawPropertiesExcluding(serializedObject, "BendingMode", "SkinnedBounds", "Bounds");
                }
                else
                {
                    if (fixBounds.SkinnedMesh != null && fixBounds.MeshFilter != null)
                    {
                        DrawPropertiesExcluding(serializedObject, "BendingMode", "Curvature", "Flatten", "HorizonZOffset", "HorizonYOffset", "HorizonXOffset", "FixBoundsRadius");
                    }
                    else if (fixBounds.SkinnedMesh != null)
                    {
                        DrawPropertiesExcluding(serializedObject, "Bounds", "BendingMode", "Curvature", "Flatten", "HorizonZOffset", "HorizonYOffset", "HorizonXOffset", "FixBoundsRadius");
                    }
                    else if (fixBounds.MeshFilter != null)
                    {
                        DrawPropertiesExcluding(serializedObject, "SkinnedBounds", "BendingMode", "Curvature", "Flatten", "HorizonZOffset", "HorizonYOffset", "HorizonXOffset", "FixBoundsRadius");
                    }
                    else
                    {
                        DrawPropertiesExcluding(serializedObject, "Bounds", "SkinnedBounds", "BendingMode", "Curvature", "Flatten", "HorizonZOffset", "HorizonYOffset", "HorizonXOffset", "FixBoundsRadius");
                    }
                }
            }

            serializedObject.ApplyModifiedProperties();


            if (fixBounds.MeshFilter != null)
            {
                if (PrefabUtility.GetPrefabType(target) != PrefabType.Prefab)
                {
                    if (!Application.isPlaying)
                    {
                        if (GUILayout.Button("Fix Bounds"))
                        {
                            if (Application.isEditor)
                            {
                                bool global = false;
                                fixBounds.Rollback();
                                fixBounds.FixBounds(global);
                            }
                        }

                        if (fixBounds.IsBoundsFixed || fixBounds.IsMeshFixed)
                        {
                            if (GUILayout.Button("Rollback"))
                            {
                                if (Application.isEditor)
                                {
                                    fixBounds.Rollback();
                                }
                            }

                            if (GUILayout.Button("Create Prefab"))
                            {
                                if (Application.isEditor)
                                {
                                    HBFixBounds.CreatePrefab(fixBounds.gameObject);
                                }
                            }
                        }
                    }
                }
            }
        }