private static void ResetAllSavedAssets(MenuCommand menuCommand) { var objectTarget = menuCommand.context as VoxelSkinnedAnimationObject; if (objectTarget == null) { return; } var objectCore = new VoxelSkinnedAnimationObjectCore(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 #region Avatar objectTarget.avatar = null; #endregion objectCore.ReCreate(); InternalEditorUtility.RepaintAllViews(); }
private static void ContextSaveAllUnsavedAssets(MenuCommand menuCommand) { var objectTarget = menuCommand.context as VoxelSkinnedAnimationObject; if (objectTarget == null) { return; } var objectCore = new VoxelSkinnedAnimationObjectCore(objectTarget); var folder = EditorUtility.OpenFolderPanel("Save all", objectCore.GetDefaultPath(), null); if (string.IsNullOrEmpty(folder)) { return; } if (folder.IndexOf(Application.dataPath) < 0) { SaveInsideAssetsFolderDisplayDialog(); return; } Undo.RecordObject(objectTarget, "Save All Unsaved Assets"); #region Mesh if (objectTarget.mesh != null && !IsMainAsset(objectTarget.mesh)) { var path = folder + "/" + string.Format("{0}_mesh.asset", objectTarget.gameObject.name); path = path.Replace(Application.dataPath, "Assets"); 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 || IsMainAsset(objectTarget.materials[index])) { continue; } var path = folder + "/" + string.Format("{0}_mat{1}.mat", objectTarget.gameObject.name, index); path = path.Replace(Application.dataPath, "Assets"); 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 && !IsMainAsset(objectTarget.atlasTexture)) { var path = folder + "/" + string.Format("{0}_tex.png", objectTarget.gameObject.name); { path = AssetDatabase.GenerateUniqueAssetPath(path.Replace(Application.dataPath, "Assets")); path = (Application.dataPath + path).Replace("AssetsAssets", "Assets"); } File.WriteAllBytes(path, objectTarget.atlasTexture.EncodeToPNG()); path = path.Replace(Application.dataPath, "Assets"); AssetDatabase.ImportAsset(path); objectCore.SetTextureImporterSetting(path, objectTarget.atlasTexture); objectTarget.atlasTexture = AssetDatabase.LoadAssetAtPath <Texture2D>(path); } #endregion #region Avatar if (objectTarget.avatar != null && !IsMainAsset(objectTarget.avatar)) { var path = folder + "/" + string.Format("{0}_avatar.asset", objectTarget.gameObject.name); path = path.Replace(Application.dataPath, "Assets"); path = AssetDatabase.GenerateUniqueAssetPath(path); AssetDatabase.CreateAsset(Avatar.Instantiate(objectTarget.avatar), path); objectTarget.avatar = AssetDatabase.LoadAssetAtPath <Avatar>(path); } #endregion objectCore.ReCreate(); InternalEditorUtility.RepaintAllViews(); }