SaveAssets.cs
3.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
using System.IO;
using System.Collections.Generic;
using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine.SceneManagement;
using Codice.Client.BaseCommands;
using Codice.Client.Common;
namespace Unity.PlasticSCM.Editor.AssetUtils
{
internal static class SaveAssets
{
internal static void ForChangesWithConfirmation(
List<ChangeInfo> changes,
out bool isCancelled)
{
ForPaths(
GetPaths(changes), true,
out isCancelled);
}
internal static void ForPathsWithConfirmation(
List<string> paths,
out bool isCancelled)
{
ForPaths(
paths, true,
out isCancelled);
}
internal static void ForChangesWithoutConfirmation(
List<ChangeInfo> changes)
{
bool isCancelled;
ForPaths(
GetPaths(changes), false,
out isCancelled);
}
internal static void ForPathsWithoutConfirmation(
List<string> paths)
{
bool isCancelled;
ForPaths(
paths, false,
out isCancelled);
}
static void ForPaths(
List<string> paths,
bool askForUserConfirmation,
out bool isCancelled)
{
SaveDirtyScenes(
paths,
askForUserConfirmation,
out isCancelled);
if (isCancelled)
return;
AssetDatabase.SaveAssets();
}
static void SaveDirtyScenes(
List<string> paths,
bool askForUserConfirmation,
out bool isCancelled)
{
isCancelled = false;
List<Scene> scenesToSave = new List<Scene>();
foreach (Scene dirtyScene in GetDirtyScenes())
{
if (Contains(paths, dirtyScene))
scenesToSave.Add(dirtyScene);
}
if (scenesToSave.Count == 0)
return;
if (askForUserConfirmation)
{
isCancelled = !EditorSceneManager.
SaveModifiedScenesIfUserWantsTo(
scenesToSave.ToArray());
return;
}
EditorSceneManager.SaveScenes(
scenesToSave.ToArray());
}
static List<Scene> GetDirtyScenes()
{
List<Scene> dirtyScenes = new List<Scene>();
for (int i = 0; i < SceneManager.sceneCount; i++)
{
Scene scene = SceneManager.GetSceneAt(i);
if (!scene.isDirty)
continue;
dirtyScenes.Add(scene);
}
return dirtyScenes;
}
static bool Contains(
List<string> paths,
Scene scene)
{
foreach (string path in paths)
{
if (PathHelper.IsSamePath(
path,
Path.GetFullPath(scene.path)))
return true;
}
return false;
}
static List<string> GetPaths(List<ChangeInfo> changeInfos)
{
List<string> result = new List<string>();
foreach (ChangeInfo change in changeInfos)
result.Add(change.GetFullPath());
return result;
}
}
}