protected void OnEnable()
 {
     explosionObject = target as VoxelChunksObjectChunkExplosion;
     if (explosionObject == null)
     {
         return;
     }
     explosionObjectCore = new VoxelChunksObjectChunkExplosionCore(explosionObject);
     chunkObject         = explosionObject.GetComponent <VoxelChunksObjectChunk>();
     if (chunkObject == null)
     {
         return;
     }
     chunkCore = new VoxelChunksObjectChunkCore(chunkObject);
     if (explosionObject.transform.parent == null)
     {
         return;
     }
     voxelObject = explosionObject.transform.parent.GetComponent <VoxelChunksObject>();
     if (voxelObject == null)
     {
         return;
     }
     voxelExplosionObject = voxelObject.GetComponent <VoxelChunksObjectExplosion>();
     if (voxelExplosionObject == null)
     {
         return;
     }
     voxelExplosionCore = new VoxelChunksObjectExplosionCore(voxelExplosionObject);
 }
        public static void StaticForceGenerate(VoxelBaseExplosion voxelBase)
        {
            VoxelBaseExplosionCore voxelCore = null;

            if (voxelBase is VoxelObjectExplosion)
            {
                voxelCore = new VoxelObjectExplosionCore(voxelBase);
            }
            else if (voxelBase is VoxelChunksObjectExplosion)
            {
                voxelCore = new VoxelChunksObjectExplosionCore(voxelBase);
            }
            else if (voxelBase is VoxelFrameAnimationObjectExplosion)
            {
                voxelCore = new VoxelFrameAnimationObjectExplosionCore(voxelBase);
            }
            else if (voxelBase is VoxelSkinnedAnimationObjectExplosion)
            {
                voxelCore = new VoxelSkinnedAnimationObjectExplosionCore(voxelBase);
            }
            else
            {
                Assert.IsTrue(false);
            }
            if (voxelCore == null)
            {
                return;
            }

            voxelCore.ResetAllAssets();
            voxelCore.Generate();

            #region Extra
            if (voxelCore is VoxelSkinnedAnimationObjectExplosionCore)
            {
                var voxelCoreEx = voxelCore as VoxelSkinnedAnimationObjectExplosionCore;
                if (voxelCoreEx.explosionObject.meshes != null &&
                    voxelCoreEx.explosionObject.meshes.Count > 0 &&
                    voxelCoreEx.explosionObject.meshes[0].bakeMesh != null)
                {
                    voxelCoreEx.Bake();
                }
            }
            #endregion
        }
        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();
        }
Beispiel #4
0
        protected override void OnEnable()
        {
            base.OnEnable();

            explosionBase = explosionObject = target as VoxelChunksObjectExplosion;
            if (explosionObject == null)
            {
                return;
            }
            explosionCore = explosionObjectCore = new VoxelChunksObjectExplosionCore(explosionObject);
            if (explosionCore.voxelBase == null)
            {
                if (explosionObject.chunksExplosion != null)
                {
                    for (int i = 0; i < explosionObject.chunksExplosion.Length; i++)
                    {
                        Undo.DestroyObjectImmediate(explosionObject.chunksExplosion[i]);
                    }
                }
                Undo.DestroyObjectImmediate(explosionBase);
                return;
            }
            OnEnableInitializeSet();
        }
Beispiel #5
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();
        }
Beispiel #6
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();
        }