-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIEditorScenePanel.cs
121 lines (114 loc) · 4.3 KB
/
IEditorScenePanel.cs
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System.IO;
using System;
namespace KuFramework.EditorTools
{
internal interface IEditorScenePanel
{
List<SceneInfo> GetSceneInfo();
void OpenScene(string path);
void DeleteScene(string path);
void AddSceneToBuildList(string path);
void OpenBuildSettingPanel();
void OpenInDirectory(string path, string sceneName);
}
internal class EditorScenePanel : IEditorScenePanel
{
//public List<SceneInfo> mSceneInfoList;
public List<SceneInfo> GetSceneInfo()
{
return SearchScene();
}
public List<SceneInfo> SearchScene()
{
List<SceneInfo> sceneinfolist = new List<SceneInfo>();
string curscenename = UnityEditor.SceneManagement.EditorSceneManager.GetActiveScene().name;
foreach (string sceneGuid in AssetDatabase.FindAssets("t:Scene", new string[] { "Assets" }))
{
string scenePath = AssetDatabase.GUIDToAssetPath(sceneGuid);
string sceneName = Path.GetFileNameWithoutExtension(scenePath);
FileInfo fileinfo = new FileInfo(Application.dataPath + "/" + scenePath.Replace("Assets/", ""));
double size = Math.Ceiling(fileinfo.Length / 1024.0);
sceneinfolist.Add(new SceneInfo(sceneName, scenePath, curscenename.Equals(sceneName), size));
}
sceneinfolist.Sort();
return sceneinfolist;
}
public void OpenScene(string path)
{
if (UnityEditor.SceneManagement.EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo())
{
UnityEditor.SceneManagement.EditorSceneManager.OpenScene(path);
UpdateSceneState();
}
}
private void UpdateSceneState()
{
KuEditorSceneManager.UpdatePanel();
}
public void DeleteScene(string path)
{
if (EditorUtility.DisplayDialog("Confirm", string.Format("About to delete scene : {0}", path), "confirm"))
{
File.Delete(Application.dataPath + "/" + path.Replace("Assets/", ""));
UpdateSceneState();
AssetDatabase.Refresh();
Debug.Log("successful");
}
else Debug.Log("cancel");
}
public void AddSceneToBuildList(string path)
{
if (IsInBuildList(path))
return;
EditorBuildSettingsScene[] buildscenearray = EditorBuildSettings.scenes;
List<EditorBuildSettingsScene> buildscenelist = new List<EditorBuildSettingsScene>(buildscenearray)
{
new EditorBuildSettingsScene(path, true)
};
EditorBuildSettings.scenes = buildscenelist.ToArray();
}
public void OpenBuildSettingPanel()
{
EditorWindow.GetWindow<BuildPlayerWindow>();
}
private bool IsInBuildList(string path)
{
for (int i = 0; i < EditorBuildSettings.scenes.Length; i++)
{
if (EditorBuildSettings.scenes[i].path.Equals(path))
return true;
}
return false;
}
public void OpenInDirectory(string path, string sceneName)
{
string dir = Application.dataPath.Replace("Assets", "") + path;
//Debug.Log(dir);
EditorUtility.RevealInFinder(dir);
}
}
internal class SceneInfo : IComparable<SceneInfo>
{
public readonly string sceneName;
public readonly string scenePath;
public readonly double sceneSize;
public readonly bool isActive;
public SceneInfo(string sceneName, string scenePath, bool isActive, double sceneSize)
{
this.sceneName = sceneName;
this.scenePath = scenePath;
this.isActive = isActive;
this.sceneSize = sceneSize;
}
public int CompareTo(SceneInfo other)
{
char[] scenename1 = this.sceneName.ToCharArray();
char[] scenename2 = other.sceneName.ToCharArray();
return scenename1[0] == scenename2[0] ? 0 : (scenename1[0] < scenename2[0] ? -1 : 1);
}
}
}