[英]How to load a new scene you create in current scene?
我用 Unity 制作了一個 3Dworld,我想在菜單中保存我的世界。 我用以下方式拯救我的世界:
EditorApplication.SaveScene("Assets/Scene/name.unity",true);
我將我的新場景添加到我的構建設置中:
var original = EditorBuildSettings.scenes;
var newSettings = new EditorBuildSettingsScene[original.Length + 1];
System.Array.Copy(original, newSettings, original.Length);
var sceneToAdd = new EditorBuildSettingsScene("Assets/Scene/name.unity", true);
newSettings[newSettings.Length - 1] = sceneToAdd;
EditorBuildSettings.scenes = newSettings;
當我在不關閉游戲的情況下加載我的新場景時:
Application.LoadLevel("name");
我有這個錯誤:
Level 'name' (-1) couldn't be loaded because it has not been added to the build settings.
To add a level to the build settings use the menu File->Build Settings...
當我查看構建設置時,會添加並檢查我的新場景。 如果我重建游戲,我可以加載我的新場景,但我不想在我剛剛保存它時重建游戲以加載新的關卡。
如何在不關閉游戲的情況下刷新我的構建設置? 或者如何更簡單地保存我的新場景?
編輯:我找到了一個替代方案,我首先創建了我的場景,將它添加到構建設置中,並在使用相同名稱保存時在游戲中將其刪除。
在Application.LoadLevel("name");
之前添加此代碼將其添加到您的構建設置中:
var original = EditorBuildSettings.scenes;
var newSettings = new EditorBuildSettingsScene[original.Length + 1];
System.Array.Copy(original, newSettings, original.Length);
var sceneToAdd = new EditorBuildSettingsScene("Assets/Path/To/Scene/name.unity", false);
newSettings[newSettings.Length - 1] = sceneToAdd;
EditorBuildSettings.scenes = newSettings;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.