浏览代码

Editor Scene Setup Almost Functional

/main
Thomas ICHÉ 6 年前
当前提交
81c8c419
共有 2 个文件被更改,包括 37 次插入3 次删除
  1. 34
      Editor/EditorSceneSetup/EditorSceneSetup.cs
  2. 6
      Editor/EditorSceneSetup/EditorSceneSetupEditor.cs

34
Editor/EditorSceneSetup/EditorSceneSetup.cs


using System.Collections;
using System.Collections.Generic;
using UnityEngine.SceneManagement;
using UnityEditor.Callbacks;
[OnOpenAsset]
static bool OnOpenAsset(int instanceID, int line)
{
var obj = EditorUtility.InstanceIDToObject(instanceID);
if(obj is EditorSceneSetup)
{
EditorSceneSetup setup = (EditorSceneSetup)obj;
int active = setup.ActiveScene;
try
{
for (int i = 0; i < setup.LoadedScenes.Length; i++)
{
var scene = setup.LoadedScenes[i];
EditorUtility.DisplayProgressBar("Loading Scenes", string.Format("Loading {0}", scene.Scene.name), (float)i / setup.LoadedScenes.Length - 1);
var path = AssetDatabase.GetAssetPath(scene.Scene);
EditorSceneManager.OpenScene(path, i == 0 ? OpenSceneMode.Single : (scene.Loaded ? OpenSceneMode.Additive : OpenSceneMode.AdditiveWithoutLoading));
}
EditorUtility.DisplayProgressBar("Loading Scenes", "Set Active Scene", 1.0f);
SceneManager.SetActiveScene(EditorSceneManager.GetSceneAt(active));
}
finally
{
EditorUtility.ClearProgressBar();
}
}
return true;
}
[MenuItem("Assets/Create/Editor Scene Setup", priority = 200)]
public static void CreateAsset()
{

6
Editor/EditorSceneSetup/EditorSceneSetupEditor.cs


m_LoadedScenes.GetArrayElementAtIndex(index).FindPropertyRelative("Scene").objectReferenceValue = sceneAsset;
}
EditorGUI.BeginDisabledGroup(index == 0);
int visible = m_LoadedScenes.GetArrayElementAtIndex(index).FindPropertyRelative("Loaded").boolValue ? 1 : 0;
visible = EditorGUI.IntPopup(loadedRect, visible, kLoadedItems, kLoadedIndices);

} else if(index == 0)
{
m_LoadedScenes.GetArrayElementAtIndex(index).FindPropertyRelative("Loaded").boolValue = true;
EditorGUI.EndDisabledGroup();
serializedObject.ApplyModifiedProperties();
}

正在加载...
取消
保存