Esempio n. 1
0
        private static void ResetAllSavedAssets(MenuCommand menuCommand)
        {
            var objectTarget = menuCommand.context as VoxelObject;

            if (objectTarget == null)
            {
                return;
            }

            var objectCore = new VoxelObjectCore(objectTarget);

            Undo.RecordObject(objectTarget, "Reset All Assets");

            objectCore.ResetAllAssets();
            objectCore.ReCreate();
            InternalEditorUtility.RepaintAllViews();
        }
Esempio n. 2
0
        private static void ResetAllSavedAssets(MenuCommand menuCommand)
        {
            var objectTarget = menuCommand.context as VoxelObject;

            if (objectTarget == null)
            {
                return;
            }

            var objectCore = new VoxelObjectCore(objectTarget);

            Undo.RecordObject(objectTarget, "Reset All Assets");

            #region Mesh
            objectTarget.mesh = null;
            #endregion

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

            #region Texture
            objectTarget.atlasTexture = null;
            #endregion

            objectCore.ReCreate();
            InternalEditorUtility.RepaintAllViews();
        }
Esempio n. 3
0
        private static void SaveAllUnsavedAssets(MenuCommand menuCommand)
        {
            var objectTarget = menuCommand.context as VoxelObject;

            if (objectTarget == null)
            {
                return;
            }

            var objectCore = new VoxelObjectCore(objectTarget);

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

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

            Undo.RecordObject(objectTarget, "Save All Unsaved Assets");

            #region Mesh
            if (objectTarget.mesh != null && !EditorCommon.IsMainAsset(objectTarget.mesh))
            {
                var path = folder + "/" + string.Format("{0}_mesh.asset", objectTarget.gameObject.name);
                path = FileUtil.GetProjectRelativePath(path);
                path = AssetDatabase.GenerateUniqueAssetPath(path);
                AssetDatabase.CreateAsset(Mesh.Instantiate(objectTarget.mesh), path);
                objectTarget.mesh = AssetDatabase.LoadAssetAtPath <Mesh>(path);
            }
            #endregion

            #region Material
            if (objectTarget.materials != null)
            {
                for (int index = 0; index < objectTarget.materials.Count; index++)
                {
                    if (objectTarget.materials[index] == null || EditorCommon.IsMainAsset(objectTarget.materials[index]))
                    {
                        continue;
                    }
                    var path = folder + "/" + string.Format("{0}_mat{1}.mat", objectTarget.gameObject.name, index);
                    path = FileUtil.GetProjectRelativePath(path);
                    path = AssetDatabase.GenerateUniqueAssetPath(path);
                    AssetDatabase.CreateAsset(Material.Instantiate(objectTarget.materials[index]), path);
                    objectTarget.materials[index] = AssetDatabase.LoadAssetAtPath <Material>(path);
                }
            }
            #endregion

            #region Texture
            if (objectTarget.atlasTexture != null && !EditorCommon.IsMainAsset(objectTarget.atlasTexture))
            {
                var path = folder + "/" + string.Format("{0}_tex.png", objectTarget.gameObject.name);
                path = EditorCommon.GenerateUniqueAssetFullPath(path);
                File.WriteAllBytes(path, objectTarget.atlasTexture.EncodeToPNG());
                path = FileUtil.GetProjectRelativePath(path);
                AssetDatabase.ImportAsset(path);
                objectCore.SetTextureImporterSetting(path, objectTarget.atlasTexture);
                objectTarget.atlasTexture = AssetDatabase.LoadAssetAtPath <Texture2D>(path);
            }
            #endregion

            objectCore.ReCreate();
            InternalEditorUtility.RepaintAllViews();
        }