refactor
This commit is contained in:
@@ -27,21 +27,23 @@ namespace RebootKitEditor.RebootWindow {
|
||||
public VisualElement Build() {
|
||||
m_RootElement = new ScrollView();
|
||||
|
||||
Label servicesAmountLabel = new($"Game services: {m_EngineConfigAsset.services.Length}") {
|
||||
style = {
|
||||
color = new Color(0.7f, 0.9f, 0.9f),
|
||||
unityFontStyleAndWeight = FontStyle.Bold
|
||||
}
|
||||
};
|
||||
m_RootElement.Add(servicesAmountLabel);
|
||||
|
||||
for (int i = 0; i < m_EngineConfigAsset.services.Length; i++) {
|
||||
ServiceAsset serviceAsset = m_EngineConfigAsset.services[i];
|
||||
|
||||
VisualElement serviceView = CreateServicesView(serviceAsset);
|
||||
serviceView.style.backgroundColor = i % 2 == 0 ? new Color(0.1f, 0.1f, 0.1f) : new Color(0.2f, 0.2f, 0.2f);
|
||||
m_RootElement.Add(serviceView);
|
||||
}
|
||||
// int servicesLength = m_EngineConfigAsset.services?.Length ?? 0;
|
||||
//
|
||||
// Label servicesAmountLabel = new($"Game services: {servicesLength}") {
|
||||
// style = {
|
||||
// color = new Color(0.7f, 0.9f, 0.9f),
|
||||
// unityFontStyleAndWeight = FontStyle.Bold
|
||||
// }
|
||||
// };
|
||||
// m_RootElement.Add(servicesAmountLabel);
|
||||
//
|
||||
// for (int i = 0; i < servicesLength; i++) {
|
||||
// ServiceAsset serviceAsset = m_EngineConfigAsset.services[i];
|
||||
//
|
||||
// VisualElement serviceView = CreateServicesView(serviceAsset);
|
||||
// serviceView.style.backgroundColor = i % 2 == 0 ? new Color(0.1f, 0.1f, 0.1f) : new Color(0.2f, 0.2f, 0.2f);
|
||||
// m_RootElement.Add(serviceView);
|
||||
// }
|
||||
|
||||
return m_RootElement;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
using RebootKit.Engine.UI;
|
||||
using RebootKit.Engine.Main;
|
||||
using RebootKit.Engine.Services.Console;
|
||||
using RebootKit.Engine.UI;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
@@ -55,6 +58,67 @@ namespace RebootKitEditor.RebootWindow {
|
||||
persistentPathContainer.Add(openPersistentPathButton);
|
||||
|
||||
rootContainer.Add(persistentPathContainer);
|
||||
|
||||
Label onGameRunScriptLabel = new("On Game Run Script (User):") {
|
||||
style = {
|
||||
fontSize = 12,
|
||||
color = new Color(0.7f, 0.9f, 0.9f)
|
||||
}
|
||||
};
|
||||
rootContainer.Add(onGameRunScriptLabel);
|
||||
|
||||
TextField onGameRunScriptTextField = new() {
|
||||
style = {
|
||||
fontSize = 12,
|
||||
},
|
||||
multiline = true,
|
||||
value = EditorPrefs.GetString(REditorConsts.k_OnGameRunScriptContentKey, "")
|
||||
};
|
||||
|
||||
onGameRunScriptTextField.RegisterValueChangedCallback(evt => {
|
||||
EditorPrefs.SetString(REditorConsts.k_OnGameRunScriptContentKey, evt.newValue);
|
||||
});
|
||||
rootContainer.Add(onGameRunScriptTextField);
|
||||
|
||||
Label consoleCommandsLabel = new("Console Commands:") {
|
||||
style = {
|
||||
fontSize = 12,
|
||||
color = new Color(0.7f, 0.9f, 0.9f)
|
||||
}
|
||||
};
|
||||
rootContainer.Add(consoleCommandsLabel);
|
||||
|
||||
ConsoleService.ConsoleCommand[] consoleCommands = ConsoleService.GenerateCommandsToRegister();
|
||||
foreach (ConsoleService.ConsoleCommand consoleCommand in consoleCommands) {
|
||||
VisualElement commandContainer = new() {
|
||||
style = {
|
||||
flexDirection = FlexDirection.Row,
|
||||
marginTop = 4,
|
||||
marginBottom = 4,
|
||||
paddingLeft = 4,
|
||||
paddingRight = 4,
|
||||
paddingTop = 4,
|
||||
paddingBottom = 4,
|
||||
}
|
||||
};
|
||||
Label commandLabel = new(consoleCommand.name) {
|
||||
style = {
|
||||
fontSize = 12,
|
||||
color = new Color(0.7f, 0.9f, 0.9f)
|
||||
}
|
||||
};
|
||||
commandContainer.Add(commandLabel);
|
||||
|
||||
Label descriptionLabel = new(consoleCommand.description) {
|
||||
style = {
|
||||
fontSize = 12,
|
||||
color = new Color(0.5f, 0.7f, 0.7f)
|
||||
}
|
||||
};
|
||||
commandContainer.Add(descriptionLabel);
|
||||
|
||||
rootContainer.Add(commandContainer);
|
||||
}
|
||||
|
||||
return rootContainer;
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ namespace RebootKitEditor.RebootWindow {
|
||||
}
|
||||
};
|
||||
root.Add(label);
|
||||
|
||||
|
||||
Button openButton = new(() => OpenWorldScenes(worldConfigAsset)) {
|
||||
text = "Open",
|
||||
style = {
|
||||
@@ -76,14 +76,16 @@ namespace RebootKitEditor.RebootWindow {
|
||||
return;
|
||||
}
|
||||
|
||||
EditorSceneManager.SaveOpenScenes();
|
||||
|
||||
// Load first scene from build settings
|
||||
string mainScenePath = SceneManager.GetSceneByBuildIndex(RConsts.k_MainSceneBuildIndex).path;
|
||||
string mainScenePath = GetScenePathByBuildIndex(RConsts.k_MainSceneBuildIndex);
|
||||
if (mainScenePath == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
EditorSceneManager.OpenScene(mainScenePath, OpenSceneMode.Single);
|
||||
|
||||
// Load world scene
|
||||
string worldScenePath = AssetDatabase.GetAssetPath(worldConfigAsset.Config.mainScene.editorAsset);
|
||||
string worldScenePath = AssetDatabase.GUIDToAssetPath(worldConfigAsset.Config.mainScene.AssetGUID);
|
||||
if (string.IsNullOrEmpty(worldScenePath)) {
|
||||
Debug.LogError($"WorldConfigAsset {worldConfigAsset.name} has invalid main scene path");
|
||||
return;
|
||||
@@ -91,5 +93,14 @@ namespace RebootKitEditor.RebootWindow {
|
||||
|
||||
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