[英]Unity create scenes and add content to it in the editor
我想做的事:
我為什么要這個?
我需要在運行時創建一個異步/附加場景加載器來加速一切。 當玩家靠近某個扇區時,只想立即加載該扇區。
可能嗎? 也許在編輯器中?
更新:我的代碼:
private static IEnumerator SaveSectorToSceneCoroutine(Sector sector)
{
//TODO save this go to a new scene
var go = Object.Instantiate(sector.gameObject);
//Object.DontDestroyOnLoad(go); //this is not working from editor
//or need a prefab?
var newScene = EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Single); //maybe better from calling this in the background, how?
SceneManager.MoveGameObjectToScene(go, newScene); //this not working, "go" became null
string[] path = EditorSceneManager.GetActiveScene().path.Split(char.Parse("/"));
path[path.Length - 1] = "_SCN_SECTOR_" + go.name + path[path.Length - 1];
EditorSceneManager.SaveScene(newScene, string.Join("/", path), true);
Debug.Log("Saved Scene " + path);
}
您的問題可能在EditorSceneManager.NewScene
中。
作為模式,您傳入NewSceneMode.Single
所有當前打開的場景都關閉,新創建的場景打開。
您更願意使用的是NewSceneMode.Additive
新創建的場景被添加到當前打開的場景中。
像例如
var go = Object.Instantiate(sector.gameObject);
var newScene = EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Additive);
SceneManager.MoveGameObjectToScene(go, newScene);
string[] path = EditorSceneManager.GetActiveScene().path.Split('//'));
path[path.Length - 1] = "_SCN_SECTOR_" + go.name + path[path.Length - 1];
EditorSceneManager.SaveScene(newScene, string.Join('//', path), true);
EditorSceneManager.CloseScene(newScene, true);
Debug.Log("Saved Scene " + path);
那么我認為這不應該是協程。 我認為沒有必要/使用做
yield return null;
在這個用例中
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.