Last active
May 18, 2016 04:35
-
-
Save yamashita8655/bef9f04040aa0bbe057b101d1f28d6cc to your computer and use it in GitHub Desktop.
vimからtest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using UnityEditor; | |
using UnityEditor.SceneManagement; | |
using System.Collections; | |
using System.Collections.Generic; | |
public class SceneSelectEditorWindow : EditorWindow { | |
private class SceneData { | |
public string DisplaySceneName = ""; | |
public string LoadScenePath = ""; | |
} | |
List<SceneData> SceneNameList = new List<SceneData>(); | |
static SceneSelectEditorWindow This = null; | |
private Vector2 ScrollPosition; | |
[MenuItem ("Window/SceneSelectEditorWindow")] | |
public static void ShowWindow () { | |
This = EditorWindow.GetWindow(typeof(SceneSelectEditorWindow)) as SceneSelectEditorWindow; | |
This.Initialize(); | |
} | |
void Initialize () { | |
Debug.Log ("---- SceneSelectEditorWindow:Initialize ----"); | |
SceneNameList.Clear(); | |
CreateList(); | |
} | |
void OnFocus() { | |
CreateList(); | |
} | |
void CreateList() { | |
if (SceneNameList.Count == 0) { | |
foreach (var guid in AssetDatabase.FindAssets("t:Scene")) { | |
var path = AssetDatabase.GUIDToAssetPath (guid); | |
if (path.IndexOf ("Test") != -1) { | |
continue; | |
} | |
SceneData data = new SceneData(); | |
int index = path.LastIndexOf("/"); | |
string name = path; | |
if (index != -1) { | |
name = path.Remove(0, index+1); | |
} | |
data.DisplaySceneName = name; | |
data.LoadScenePath = path; | |
SceneNameList.Add(data); | |
// Debug.Log(AssetDatabase.LoadMainAssetAtPath(path)); | |
} | |
} | |
} | |
// Update is called once per frame | |
void Update () { | |
} | |
void OnGUI () { | |
if (EditorApplication.isPlaying == false) { | |
EditorGUILayout.BeginVertical(); | |
//PropertyFieldを使えば、型に合わせて基本通り描画してくれる。 | |
//面倒なUndo処理とかも書かなくてもいい、 | |
// EditorGUILayout.PropertyField(serializedObject.FindProperty("customSize"), new GUIContent("Size")); | |
ScrollPosition = EditorGUILayout.BeginScrollView(ScrollPosition, GUILayout.Height(200)); | |
for (int i = 0; i < SceneNameList.Count; i++) { | |
if (GUILayout.Button(SceneNameList[i].DisplaySceneName, GUILayout.Width(200f))) { | |
if (EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo()) { | |
EditorSceneManager.OpenScene(SceneNameList[i].LoadScenePath); | |
} | |
} | |
} | |
EditorGUILayout.EndScrollView(); | |
EditorGUILayout.EndVertical(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment