fix?
This commit is contained in:
210
Editor/RebootWindow/WorldsView.cs
Normal file → Executable file
210
Editor/RebootWindow/WorldsView.cs
Normal file → Executable file
@@ -1,106 +1,106 @@
|
||||
using RebootKit.Engine;
|
||||
using RebootKit.Engine.Services.Simulation;
|
||||
using RebootKit.Engine.UI;
|
||||
using RebootKitEditor.Utils;
|
||||
using UnityEditor;
|
||||
using UnityEditor.SceneManagement;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace RebootKitEditor.RebootWindow {
|
||||
public class WorldsView : IView {
|
||||
public void Dispose() {
|
||||
}
|
||||
|
||||
public VisualElement Build() {
|
||||
VisualElement root = new() {
|
||||
style = {
|
||||
paddingBottom = 4,
|
||||
paddingTop = 4,
|
||||
paddingLeft = 4,
|
||||
paddingRight = 4,
|
||||
}
|
||||
};
|
||||
|
||||
WorldConfigAsset[] worlds = AssetDatabaseEx.LoadAllAssets<WorldConfigAsset>();
|
||||
foreach (WorldConfigAsset worldConfigAsset in worlds) {
|
||||
VisualElement worldView = CreateWorldView(worldConfigAsset);
|
||||
root.Add(worldView);
|
||||
}
|
||||
|
||||
return root;
|
||||
}
|
||||
|
||||
VisualElement CreateWorldView(WorldConfigAsset worldConfigAsset) {
|
||||
VisualElement root = new() {
|
||||
style = {
|
||||
backgroundColor = new Color(0.1f, 0.1f, 0.1f),
|
||||
paddingBottom = 4,
|
||||
paddingTop = 4,
|
||||
paddingLeft = 4,
|
||||
paddingRight = 4,
|
||||
borderBottomLeftRadius = 4,
|
||||
borderBottomRightRadius = 4
|
||||
}
|
||||
};
|
||||
|
||||
Label label = new(worldConfigAsset.name) {
|
||||
style = {
|
||||
color = new Color(0.7f, 0.9f, 0.9f),
|
||||
unityFontStyleAndWeight = FontStyle.Bold
|
||||
}
|
||||
};
|
||||
root.Add(label);
|
||||
|
||||
Button openButton = new(() => OpenWorldScenes(worldConfigAsset)) {
|
||||
text = "Open",
|
||||
style = {
|
||||
backgroundColor = new Color(0.2f, 0.2f, 0.2f),
|
||||
paddingBottom = 4,
|
||||
paddingTop = 4,
|
||||
paddingLeft = 4,
|
||||
paddingRight = 4,
|
||||
borderBottomLeftRadius = 4,
|
||||
borderBottomRightRadius = 4
|
||||
}
|
||||
};
|
||||
root.Add(openButton);
|
||||
|
||||
return root;
|
||||
}
|
||||
|
||||
static void OpenWorldScenes(WorldConfigAsset worldConfigAsset) {
|
||||
if (worldConfigAsset == null) {
|
||||
Debug.LogError("WorldConfigAsset is null");
|
||||
return;
|
||||
}
|
||||
|
||||
// Load first scene from build settings
|
||||
string mainScenePath = GetScenePathByBuildIndex(RConsts.k_MainSceneBuildIndex);
|
||||
if (mainScenePath == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
EditorSceneManager.OpenScene(mainScenePath, OpenSceneMode.Single);
|
||||
|
||||
// Load world scene
|
||||
string worldScenePath = AssetDatabase.GUIDToAssetPath(worldConfigAsset.Config.mainScene.AssetGUID);
|
||||
if (string.IsNullOrEmpty(worldScenePath)) {
|
||||
Debug.LogError($"WorldConfigAsset {worldConfigAsset.name} has invalid main scene path");
|
||||
return;
|
||||
}
|
||||
|
||||
SceneManager.SetActiveScene(EditorSceneManager.OpenScene(worldScenePath, OpenSceneMode.Additive));
|
||||
}
|
||||
|
||||
static string GetScenePathByBuildIndex(int buildIndex) {
|
||||
if (buildIndex < 0 || buildIndex >= EditorBuildSettings.scenes.Length) {
|
||||
Debug.LogError($"Build index {buildIndex} out of range. Total scenes in build: {EditorBuildSettings.scenes.Length}");
|
||||
return null;
|
||||
}
|
||||
|
||||
return EditorBuildSettings.scenes[buildIndex].path;
|
||||
}
|
||||
}
|
||||
using RebootKit.Engine;
|
||||
using RebootKit.Engine.Services.Simulation;
|
||||
using RebootKit.Engine.UI;
|
||||
using RebootKitEditor.Utils;
|
||||
using UnityEditor;
|
||||
using UnityEditor.SceneManagement;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace RebootKitEditor.RebootWindow {
|
||||
public class WorldsView : IView {
|
||||
public void Dispose() {
|
||||
}
|
||||
|
||||
public VisualElement Build() {
|
||||
VisualElement root = new() {
|
||||
style = {
|
||||
paddingBottom = 4,
|
||||
paddingTop = 4,
|
||||
paddingLeft = 4,
|
||||
paddingRight = 4,
|
||||
}
|
||||
};
|
||||
|
||||
WorldConfigAsset[] worlds = AssetDatabaseEx.LoadAllAssets<WorldConfigAsset>();
|
||||
foreach (WorldConfigAsset worldConfigAsset in worlds) {
|
||||
VisualElement worldView = CreateWorldView(worldConfigAsset);
|
||||
root.Add(worldView);
|
||||
}
|
||||
|
||||
return root;
|
||||
}
|
||||
|
||||
VisualElement CreateWorldView(WorldConfigAsset worldConfigAsset) {
|
||||
VisualElement root = new() {
|
||||
style = {
|
||||
backgroundColor = new Color(0.1f, 0.1f, 0.1f),
|
||||
paddingBottom = 4,
|
||||
paddingTop = 4,
|
||||
paddingLeft = 4,
|
||||
paddingRight = 4,
|
||||
borderBottomLeftRadius = 4,
|
||||
borderBottomRightRadius = 4
|
||||
}
|
||||
};
|
||||
|
||||
Label label = new(worldConfigAsset.name) {
|
||||
style = {
|
||||
color = new Color(0.7f, 0.9f, 0.9f),
|
||||
unityFontStyleAndWeight = FontStyle.Bold
|
||||
}
|
||||
};
|
||||
root.Add(label);
|
||||
|
||||
Button openButton = new(() => OpenWorldScenes(worldConfigAsset)) {
|
||||
text = "Open",
|
||||
style = {
|
||||
backgroundColor = new Color(0.2f, 0.2f, 0.2f),
|
||||
paddingBottom = 4,
|
||||
paddingTop = 4,
|
||||
paddingLeft = 4,
|
||||
paddingRight = 4,
|
||||
borderBottomLeftRadius = 4,
|
||||
borderBottomRightRadius = 4
|
||||
}
|
||||
};
|
||||
root.Add(openButton);
|
||||
|
||||
return root;
|
||||
}
|
||||
|
||||
static void OpenWorldScenes(WorldConfigAsset worldConfigAsset) {
|
||||
if (worldConfigAsset == null) {
|
||||
Debug.LogError("WorldConfigAsset is null");
|
||||
return;
|
||||
}
|
||||
|
||||
// Load first scene from build settings
|
||||
string mainScenePath = GetScenePathByBuildIndex(RConsts.k_MainSceneBuildIndex);
|
||||
if (mainScenePath == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
EditorSceneManager.OpenScene(mainScenePath, OpenSceneMode.Single);
|
||||
|
||||
// Load world scene
|
||||
string worldScenePath = AssetDatabase.GUIDToAssetPath(worldConfigAsset.Config.mainScene.AssetGUID);
|
||||
if (string.IsNullOrEmpty(worldScenePath)) {
|
||||
Debug.LogError($"WorldConfigAsset {worldConfigAsset.name} has invalid main scene path");
|
||||
return;
|
||||
}
|
||||
|
||||
SceneManager.SetActiveScene(EditorSceneManager.OpenScene(worldScenePath, OpenSceneMode.Additive));
|
||||
}
|
||||
|
||||
static string GetScenePathByBuildIndex(int buildIndex) {
|
||||
if (buildIndex < 0 || buildIndex >= EditorBuildSettings.scenes.Length) {
|
||||
Debug.LogError($"Build index {buildIndex} out of range. Total scenes in build: {EditorBuildSettings.scenes.Length}");
|
||||
return null;
|
||||
}
|
||||
|
||||
return EditorBuildSettings.scenes[buildIndex].path;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user