-
Notifications
You must be signed in to change notification settings - Fork 0
/
StateSetPrototyping.cs
61 lines (50 loc) · 1.73 KB
/
StateSetPrototyping.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using App.States;
using System;
using UnityEngine;
using VContainer;
// Used with StateApp to set the states via an on screen GUI.
namespace App.State.Prototyping
{
public class StateSetPrototyping : MonoBehaviour
{
[Inject]
StateApp stateApp;
private void Start()
{
StateApp.OnStateChanged += (currentState) =>
{
state = currentState;
};
}
StateApp.States state;
void OnGUI()
{
// Determine the initial position for the first button
int buttonX = 300;
int buttonY = 10;
int buttonWidth = 150;
int buttonHeight = 20;
int verticalSpacing = 10; // Space between buttons
// Loop through all possible states
foreach (StateApp.States enumValue in Enum.GetValues(typeof(StateApp.States)))
{
// Create a button for this state
if (GUI.Button(new Rect(buttonX, buttonY, buttonWidth, buttonHeight), enumValue.ToString()))
{
stateApp.SetState(enumValue);
}
// Move down for the next button
buttonY += buttonHeight + verticalSpacing;
}
// Create a "Next state" button
if (GUI.Button(new Rect(buttonX, buttonY, buttonWidth, buttonHeight), "Next state"))
{
stateApp.NextState();
}
// Move down to display the current state
buttonY += buttonHeight + verticalSpacing;
// Display the current state
GUI.Label(new Rect(buttonX, buttonY, buttonWidth, buttonHeight), $"Current state: {state}");
}
}
}