mirror of
https://github.com/LazyDuchess/OpenTS2.git
synced 2025-01-22 08:11:47 -05:00
Allow viewing/editing VM globals in Unity Editor
This commit is contained in:
parent
25763a9bb9
commit
406c3f27b9
2 changed files with 39 additions and 9 deletions
|
@ -1,6 +1,7 @@
|
|||
using OpenTS2.Game;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
@ -12,6 +13,8 @@ namespace OpenTS2
|
|||
[CustomEditor(typeof(Simulator))]
|
||||
public class SimulatorEditor : Editor
|
||||
{
|
||||
private bool _showGlobals = false;
|
||||
private bool _showEntities = false;
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
DrawDefaultInspector();
|
||||
|
@ -20,19 +23,45 @@ namespace OpenTS2
|
|||
if (vm == null) return;
|
||||
var entities = vm.Entities;
|
||||
if (entities == null) return;
|
||||
GUILayout.Label("Entities");
|
||||
GUILayout.BeginVertical("box");
|
||||
foreach(var entity in entities)
|
||||
|
||||
_showGlobals = EditorGUILayout.Foldout(_showGlobals, "Globals");
|
||||
if (_showGlobals)
|
||||
{
|
||||
GUILayout.BeginVertical("box");
|
||||
GUILayout.Label($"{entity.ID} - {entity.ObjectDefinition.FileName}");
|
||||
GUILayout.EndVertical();
|
||||
if (GUILayout.Button("Kill"))
|
||||
EditorGUI.indentLevel++;
|
||||
for (var i = 0; i < vm.GlobalState.Length; i++)
|
||||
{
|
||||
entity.Delete();
|
||||
GUILayout.BeginVertical("box");
|
||||
var globalName = ((SimAntics.VMGlobals)i).ToString();
|
||||
GUILayout.BeginHorizontal();
|
||||
var editedGlobal = EditorGUILayout.TextField(globalName, vm.GlobalState[i].ToString(CultureInfo.InvariantCulture));
|
||||
if (short.TryParse(editedGlobal,NumberStyles.Integer, CultureInfo.InvariantCulture, out var res))
|
||||
{
|
||||
if (res != vm.GlobalState[i])
|
||||
vm.SetGlobal((ushort)i, res);
|
||||
}
|
||||
GUILayout.EndHorizontal();
|
||||
GUILayout.EndVertical();
|
||||
}
|
||||
EditorGUI.indentLevel--;
|
||||
}
|
||||
|
||||
_showEntities = EditorGUILayout.Foldout(_showEntities, "Entities");
|
||||
if (_showEntities)
|
||||
{
|
||||
EditorGUI.indentLevel++;
|
||||
foreach (var entity in entities)
|
||||
{
|
||||
GUILayout.BeginVertical("box");
|
||||
GUILayout.Label($"{entity.ID} - {entity.ObjectDefinition.FileName}");
|
||||
EditorGUILayout.Separator();
|
||||
if (GUILayout.Button("Kill"))
|
||||
{
|
||||
entity.Delete();
|
||||
}
|
||||
GUILayout.EndVertical();
|
||||
}
|
||||
EditorGUI.indentLevel--;
|
||||
}
|
||||
GUILayout.EndVertical();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -57,6 +57,7 @@ namespace OpenTS2.SimAntics
|
|||
SetGlobal(VMGlobals.GameEditionFlags2, epFlags2);
|
||||
var globals = GameGlobals.Instance;
|
||||
SetGlobal(VMGlobals.CurrentLanguage, (short)globals.Language);
|
||||
SetGlobal(VMGlobals.Year, 1997);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
Loading…
Reference in a new issue