Tanoda
ResaveUtility.cs
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright (C) Ultraleap, Inc. 2011-2020. *
3 * *
4 * Use subject to the terms of the Apache License 2.0 available at *
5 * http://www.apache.org/licenses/LICENSE-2.0, or another agreement *
6 * between Ultraleap and you, your company or other organization. *
7 ******************************************************************************/
8
9using System.IO;
10using UnityEngine;
11using UnityEditor;
12using UnityEditor.SceneManagement;
13
14namespace Leap.Unity {
15 using Query;
16
17 public static class ResaveUtility {
18
19 [MenuItem("Assets/Save All Scenes And Assets")]
20 public static void SaveAllScenesAndAssets() {
21 SaveAllScenes();
22 SaveAllAssets();
23 }
24
25 public static void SaveAllScenes() {
26 EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo();
27
28 var paths = AssetDatabase.FindAssets("t:Scene").
29 Query().
30 Select(guid => AssetDatabase.GUIDToAssetPath(guid)).
31 ToList();
32
33 try {
34 for (int i = 0; i < paths.Count; i++) {
35 var scenePath = paths[i];
36
37 if (EditorUtility.DisplayCancelableProgressBar("Saving Scenes", "Saving " + Path.GetFileNameWithoutExtension(scenePath), i / (float)paths.Count)) {
38 break;
39 }
40
41 var scene = EditorSceneManager.OpenScene(scenePath, OpenSceneMode.Single);
42 EditorSceneManager.SaveScene(scene);
43 }
44 } finally {
45 EditorUtility.ClearProgressBar();
46 }
47 }
48
49 public static void SaveAllAssets() {
50 var paths = AssetDatabase.FindAssets("t:ScriptableObject").
51 Query().
52 Concat(AssetDatabase.FindAssets("t:GameObject").
53 Query()).
54 Select(guid => AssetDatabase.GUIDToAssetPath(guid)).
55 ToList();
56
57 try {
58 for (int i = 0; i < paths.Count; i++) {
59 var assetPath = paths[i];
60
61 if (EditorUtility.DisplayCancelableProgressBar("Saving Assets", "Saving " + Path.GetFileNameWithoutExtension(assetPath), i / (float)paths.Count)) {
62 break;
63 }
64
65 var obj = AssetDatabase.LoadAssetAtPath<Object>(assetPath);
66 EditorUtility.SetDirty(obj);
67 }
68 } finally {
69 AssetDatabase.SaveAssets();
70 EditorUtility.ClearProgressBar();
71 }
72 }
73 }
74}
UnityEngine.Object Object