private static void ResetAllSavedAssets(MenuCommand menuCommand)
        {
            var explosionObject = menuCommand.context as VoxelChunksObjectExplosion;

            if (explosionObject == null)
            {
                return;
            }

            var explosionCore = new VoxelChunksObjectExplosionCore(explosionObject);

            Undo.RecordObject(explosionObject, "Reset All Assets");
            if (explosionObject.chunksExplosion != null)
            {
                Undo.RecordObjects(explosionObject.chunksExplosion, "Reset All Assets");
            }

            explosionCore.ResetAllAssets();
            explosionCore.Generate();
            InternalEditorUtility.RepaintAllViews();
        }
Exemplo n.º 2
0
        private static void ResetAllSavedAssets(MenuCommand menuCommand)
        {
            var explosionObject = menuCommand.context as VoxelChunksObjectExplosion;

            if (explosionObject == null)
            {
                return;
            }

            var explosionCore = new VoxelChunksObjectExplosionCore(explosionObject);

            Undo.RecordObject(explosionObject, "Reset All Assets");
            if (explosionObject.chunksExplosion != null)
            {
                Undo.RecordObjects(explosionObject.chunksExplosion, "Reset All Assets");
            }

            #region Mesh
            if (explosionObject.chunksExplosion != null)
            {
                for (int i = 0; i < explosionObject.chunksExplosion.Length; i++)
                {
                    if (explosionObject.chunksExplosion[i] == null)
                    {
                        continue;
                    }
                    explosionObject.chunksExplosion[i].meshes = null;
                    if (explosionObject.chunksExplosion[i].materials == null)
                    {
                        continue;
                    }
                    for (int j = 0; j < explosionObject.chunksExplosion[i].materials.Count; j++)
                    {
                        if (explosionObject.chunksExplosion[i].materials[j] == null)
                        {
                            continue;
                        }
                        if (!IsMainAsset(explosionObject.chunksExplosion[i].materials[j]))
                        {
                            explosionObject.chunksExplosion[i].materials[j] = null;
                        }
                        else
                        {
                            explosionObject.chunksExplosion[i].materials[j] = Instantiate <Material>(explosionObject.chunksExplosion[i].materials[j]);
                        }
                    }
                }
            }
            #endregion

            #region Material
            if (explosionObject.materials != null)
            {
                for (int i = 0; i < explosionObject.materials.Count; i++)
                {
                    if (explosionObject.materials[i] == null)
                    {
                        continue;
                    }
                    if (!IsMainAsset(explosionObject.materials[i]))
                    {
                        explosionObject.materials[i] = null;
                    }
                    else
                    {
                        explosionObject.materials[i] = Instantiate <Material>(explosionObject.materials[i]);
                    }
                }
            }
            #endregion

            explosionCore.Generate();
            InternalEditorUtility.RepaintAllViews();
        }
Exemplo n.º 3
0
        private static void ContextSaveAllUnsavedAssets(MenuCommand menuCommand)
        {
            var explosionObject = menuCommand.context as VoxelChunksObjectExplosion;

            if (explosionObject == null)
            {
                return;
            }

            var explosionCore = new VoxelChunksObjectExplosionCore(explosionObject);

            var folder = EditorUtility.OpenFolderPanel("Save all", explosionCore.voxelBaseCore.GetDefaultPath(), null);

            if (string.IsNullOrEmpty(folder))
            {
                return;
            }
            if (folder.IndexOf(Application.dataPath) < 0)
            {
                SaveInsideAssetsFolderDisplayDialog();
                return;
            }

            Undo.RecordObject(explosionObject, "Save All Unsaved Assets");
            if (explosionObject.chunksExplosion != null)
            {
                Undo.RecordObjects(explosionObject.chunksExplosion, "Save All Unsaved Assets");
            }

            if (explosionObject.materialMode == VoxelChunksObject.MaterialMode.Combine)
            {
                if (explosionObject.chunksExplosion != null)
                {
                    for (int i = 0; i < explosionObject.chunksExplosion.Length; i++)
                    {
                        if (explosionObject.chunksExplosion[i] == null)
                        {
                            continue;
                        }
                        #region Mesh
                        for (int j = 0; j < explosionObject.chunksExplosion[i].meshes.Count; j++)
                        {
                            if (explosionObject.chunksExplosion[i].meshes[j] != null && explosionObject.chunksExplosion[i].meshes[j].mesh != null && !IsMainAsset(explosionObject.chunksExplosion[i].meshes[j].mesh))
                            {
                                var chunkObject = explosionObject.chunksExplosion[i].GetComponent <VoxelChunksObjectChunk>();
                                if (chunkObject == null)
                                {
                                    continue;
                                }
                                var path = folder + "/" + string.Format("{0}_{1}_explosion_mesh{2}.asset", explosionObject.gameObject.name, chunkObject.chunkName, j);
                                path = path.Replace(Application.dataPath, "Assets");
                                AssetDatabase.CreateAsset(Mesh.Instantiate(explosionObject.chunksExplosion[i].meshes[j].mesh), path);
                                explosionObject.chunksExplosion[i].meshes[j].mesh = AssetDatabase.LoadAssetAtPath <Mesh>(path);
                            }
                        }
                        #endregion
                    }
                }

                #region Material
                if (explosionObject.materials != null)
                {
                    for (int index = 0; index < explosionObject.materials.Count; index++)
                    {
                        if (explosionObject.materials[index] == null)
                        {
                            continue;
                        }
                        if (IsMainAsset(explosionObject.materials[index]))
                        {
                            continue;
                        }
                        var path = folder + "/" + string.Format("{0}_explosion_mat{1}.mat", explosionObject.gameObject.name, index);
                        path = path.Replace(Application.dataPath, "Assets");
                        AssetDatabase.CreateAsset(Material.Instantiate(explosionObject.materials[index]), path);
                        explosionObject.materials[index] = AssetDatabase.LoadAssetAtPath <Material>(path);
                    }
                }
                #endregion
            }
            else if (explosionObject.materialMode == VoxelChunksObject.MaterialMode.Individual)
            {
                if (explosionObject.chunksExplosion != null)
                {
                    for (int i = 0; i < explosionObject.chunksExplosion.Length; i++)
                    {
                        if (explosionObject.chunksExplosion[i] == null)
                        {
                            continue;
                        }
                        var chunkObject = explosionObject.chunksExplosion[i].GetComponent <VoxelChunksObjectChunk>();
                        if (chunkObject == null)
                        {
                            continue;
                        }
                        #region Mesh
                        for (int j = 0; j < explosionObject.chunksExplosion[i].meshes.Count; j++)
                        {
                            if (explosionObject.chunksExplosion[i].meshes[j] != null && explosionObject.chunksExplosion[i].meshes[j].mesh != null && !IsMainAsset(explosionObject.chunksExplosion[i].meshes[j].mesh))
                            {
                                var path = folder + "/" + string.Format("{0}_{1}_explosion_mesh{2}.asset", explosionObject.gameObject.name, chunkObject.chunkName, j);
                                path = path.Replace(Application.dataPath, "Assets");
                                AssetDatabase.CreateAsset(Mesh.Instantiate(explosionObject.chunksExplosion[i].meshes[j].mesh), path);
                                explosionObject.chunksExplosion[i].meshes[j].mesh = AssetDatabase.LoadAssetAtPath <Mesh>(path);
                            }
                        }
                        #endregion

                        #region Material
                        if (explosionObject.chunksExplosion[i].materials != null)
                        {
                            for (int index = 0; index < explosionObject.chunksExplosion[i].materials.Count; index++)
                            {
                                if (explosionObject.chunksExplosion[i].materials[index] == null)
                                {
                                    continue;
                                }
                                if (IsMainAsset(explosionObject.chunksExplosion[i].materials[index]))
                                {
                                    continue;
                                }
                                var path = folder + "/" + string.Format("{0}_{1}_explosion_mat{2}.mat", explosionObject.gameObject.name, chunkObject.chunkName, index);
                                path = path.Replace(Application.dataPath, "Assets");
                                AssetDatabase.CreateAsset(Material.Instantiate(explosionObject.chunksExplosion[i].materials[index]), path);
                                explosionObject.chunksExplosion[i].materials[index] = AssetDatabase.LoadAssetAtPath <Material>(path);
                            }
                        }
                        #endregion
                    }
                }
            }
            else
            {
                Assert.IsTrue(false);
            }

            explosionCore.Generate();
            InternalEditorUtility.RepaintAllViews();
        }