private void SaveNewChopInfo(Dictionary <GameObject, int> dictChoppedGOInteriorSubmeshIdx) { List <GameObject> listChoppedGameObject = new List <GameObject>(); GameObject[] arrChoppedGO = CREditorUtils.GetAllChildObjectsWithGeometry(Data.GameObjectChoppedRoot, true); listChoppedGameObject.AddRange(arrChoppedGO); int nTotalPieces = listChoppedGameObject.Count; Data.ArrChoppedGameObject = listChoppedGameObject.ToArray(); Data.ArrInteriorSubmeshIdx = new int[nTotalPieces]; Data.ArrGameObject_Bounds_Chopped = new Bounds[nTotalPieces]; Data.ArrGameObject_Chopped_Positions = new Vector3[nTotalPieces]; for (int i = 0; i < nTotalPieces; i++) { GameObject go = listChoppedGameObject[i]; int interiorSubMeshIdx = dictChoppedGOInteriorSubmeshIdx[go]; Data.ArrInteriorSubmeshIdx[i] = interiorSubMeshIdx; Data.ArrGameObject_Bounds_Chopped[i] = go.GetWorldBounds(); Data.ArrGameObject_Chopped_Positions[i] = go.transform.localPosition; } EditorUtility.SetDirty(Data); }
public static bool IsAnyUnsavedMeshInHierarchy(GameObject go) { bool isAnyUnsavedMesh = false; GameObject[] arrGameObjects = CREditorUtils.GetAllChildObjectsWithGeometry(go, true); int nGameObjects = arrGameObjects.Length; for (int i = 0; i < nGameObjects; i++) { UnityEngine.GameObject gameObject = arrGameObjects[i]; UnityEngine.Mesh mesh = gameObject.GetMesh(); if (mesh != null && !AssetDatabase.Contains(mesh.GetInstanceID())) { isAnyUnsavedMesh = true; } } return(isAnyUnsavedMesh); }
void DoSubstitution() { Undo.RecordObject(rootObject_, "Substitute material in hierarchy"); List <GameObject> listGameObject = new List <GameObject>(); listGameObject.Add(rootObject_); GameObject[] arrGameObject = CREditorUtils.GetAllChildObjectsWithGeometry(rootObject_, true); listGameObject.AddRange(arrGameObject); foreach (GameObject go in listGameObject) { Renderer rn = go.GetComponent <Renderer>(); if (rn != null) { Material[] arrMaterial = rn.sharedMaterials; bool modifiedArray = false; for (int i = 0; i < arrMaterial.Length; i++) { Material mat = arrMaterial[i]; if (mat == originalMaterial_) { modifiedArray = true; arrMaterial[i] = newMaterial_; } } if (modifiedArray) { Undo.RecordObject(rn, "Change materials"); rn.sharedMaterials = arrMaterial; } } } Undo.SetCurrentGroupName("Substitute material in hierarchy"); Undo.CollapseUndoOperations(Undo.GetCurrentGroup()); }
public static void SaveAnyUnsavedMeshInHierarchy(GameObject go, bool saveAsCopy) { string path = EditorUtility.SaveFilePanelInProject("Save unsaved meshes into Assets...", go.name + ".prefab", "prefab", "Please, enter a name where the unsaved meshes will be saved to"); if (path.Length != 0) { string meshesPrefabPath = AssetDatabase.GenerateUniqueAssetPath(path); Object meshesPrefab = PrefabUtility.CreateEmptyPrefab(meshesPrefabPath); GameObject[] arrGameObjects = CREditorUtils.GetAllChildObjectsWithGeometry(go, true); int nGameObjects = arrGameObjects.Length; for (int i = 0; i < nGameObjects; i++) { UnityEngine.GameObject gameObject = arrGameObjects[i]; UnityEngine.Mesh mesh = gameObject.GetMesh(); if (mesh != null && !AssetDatabase.Contains(mesh.GetInstanceID())) { if (saveAsCopy) { Mesh newMesh = UnityEngine.Object.Instantiate(mesh); newMesh.name = mesh.name; CREditorUtils.SetMesh(gameObject, newMesh); AssetDatabase.AddObjectToAsset(newMesh, meshesPrefab); } else { AssetDatabase.AddObjectToAsset(mesh, meshesPrefab); } EditorUtility.DisplayProgressBar("Saving scene meshes to prefab...", "Saving mesh " + i + 1 + " of " + nGameObjects, (float)i + 1 / (float)nGameObjects); } } EditorUtility.ClearProgressBar(); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); } }