Documentation for the Unity C# Library
Loading...
Searching...
No Matches
InteractableDebug.cs
Go to the documentation of this file.
1using System;
2using System.Collections;
3using System.Collections.Generic;
4using PixoVR.Core;
5using TMPro;
6using UnityEngine;
7using UnityEngine.Events;
8using UnityEngine.UI;
9
10namespace PixoVR.Event
11{
12 public class InteractableDebug : MonoBehaviour
13 {
14 //steps
15 [SerializeField] private Dropdown _dropdownSteps;
16
17 [SerializeField] private Button _skipStepButton;
18 [SerializeField] private Button _goToStepButton;
19
20 [SerializeField] private TMP_Text _currentStepText;
21 [SerializeField] private TMP_Text _currentFunctionText;
22
23 //items
24 [SerializeField] private Dropdown _dropdownItems;
25 [SerializeField] private Toggle _isActive;
26 [SerializeField] private Toggle _isBroken;
27 [SerializeField] private Toggle _isInspected;
28
29 [SerializeField] private Button _activateButton;
30 [SerializeField] private Button _deactivateButton;
31
32 [SerializeField] private Button _highlightOnButton;
33 [SerializeField] private Button _highlightOffButton;
34
35 [SerializeField] private Button _turnOnButton;
36 [SerializeField] private Button _turnOffButton;
37
38 [SerializeField] private Button _repairOnButton;
39 [SerializeField] private Button _breakDownButton;
40
41 [SerializeField] private Button _closeButton;
43 //
44
45 private bool isActive;
46 private bool isBroken;
47 private bool isInspected;
49 private string _selectedStep;
53 private List<string> _listOfSteps;
54
55 private Dictionary<ItemsEnum, InteractableClass> _ItemsDictionary;
56 private Dictionary<string, InteractableClass> _StringItemsDictionary;
57
58
59 public event Action CloseDebugUI;
61 void Start()
62 {
63 // _pointerSwitchButtons.Any(button => _thisHand.ButtonPressed(button));
65
66 var stepsData = StatesService.GetState<StepsData>();
67 if (stepsData != null)
68 {
69 _stepsData = stepsData;
70 }
71
72 _dropdownSteps.onValueChanged.AddListener(delegate {StepSelected(_dropdownSteps);});
73
74 _dropdownItems.onValueChanged.AddListener(delegate {ItemSelected(_dropdownItems);});
75
76 StartCoroutine(StartInit());
77
78
79 _stepManager.StepInformationUpdated += UpdateStepInfo;
81 _activateButton.onClick.AddListener(ActivateObject);
82 _deactivateButton.onClick.AddListener(DeactivateObject);
83
85 _highlightOffButton.onClick.AddListener(HighlightOffObject);
86
87 _turnOnButton.onClick.AddListener(TurnOnObject);
88 _turnOffButton.onClick.AddListener(TurnOffObject);
89
90 _repairOnButton.onClick.AddListener(RepairObject);
91 _breakDownButton.onClick.AddListener(BreakDownObject);
93 _skipStepButton.onClick.AddListener(SkipStep);
94 _goToStepButton.onClick.AddListener(GoToSelectedStep);
95
96 _closeButton.onClick.AddListener(() => CloseDebugUI?.Invoke());
97
98 // _currentItem = _stepManager.GetGameObjectByID(ItemsEnum.GAME_MENU);
99 }
100
101 private void OnDestroy()
102 {
103 _stepManager.StepInformationUpdated -= UpdateStepInfo;
104 _dropdownSteps.onValueChanged.RemoveListener(delegate {StepSelected(_dropdownSteps);});
105
106 _activateButton.onClick.RemoveListener(ActivateObject);
107 _deactivateButton.onClick.RemoveListener(DeactivateObject);
109 _highlightOnButton.onClick.RemoveListener(HighlightOnObject);
110 _highlightOffButton.onClick.RemoveListener(HighlightOffObject);
111
112 _turnOnButton.onClick.RemoveListener(TurnOnObject);
113 _turnOffButton.onClick.RemoveListener(TurnOffObject);
114
115 _repairOnButton.onClick.RemoveListener(RepairObject);
116 _breakDownButton.onClick.RemoveListener(BreakDownObject);
117
118 _skipStepButton.onClick.RemoveListener(SkipStep);
119 _goToStepButton.onClick.RemoveListener(GoToSelectedStep);
121 _closeButton.onClick.RemoveListener(() => CloseDebugUI?.Invoke());
123 }
125 private void StepSelected(Dropdown dropdownSteps)
127 int index = dropdownSteps.value;
129 }
131 private void ItemSelected(Dropdown dropdownItems)
132 {
133 _currentItem = _StringItemsDictionary[dropdownItems.itemText.ToString()];
135
136 private void GoToSelectedStep()
137 {
139 }
140
141 private void SkipStep()
142 {
144 {
145 item = ItemsEnum.SKIP_STEP
146 });
147 }
148
149 private void UpdateStepInfo(string step, int function)
150 {
151 _currentStepText.SetText(step);
152 _currentFunctionText.SetText(function.ToString());
153 }
154
155 public void InitDebugUI()
156 {
159 _dropdownItems.options.Clear();
160
161 foreach (var item in _ItemsDictionary)
162 {
163 var itemName = item.Key.ToString();
164 var option = new Dropdown.OptionData(itemName, null);
165 _StringItemsDictionary.Add(itemName, item.Value);
166 _dropdownItems.options.Add(option);
167 }
168
169 _dropdownSteps.options.Clear();
170 foreach (var step in _stepsData.listOfSteps)
171 {
172 var option = new Dropdown.OptionData(step.stepID, null);
173 _listOfSteps.Add(step.stepID);
174 _dropdownSteps.options.Add(option);
175 }
177 _ItemsDictionary.Clear();
178 }
179
180 private void BreakDownObject()
181 {
183 }
184
185 private void RepairObject()
186 {
188 }
189
190 private void TurnOffObject()
191 {
193 }
194
195 private void TurnOnObject()
196 {
198 }
199
200 private void HighlightOffObject()
201 {
202 _currentItem.Highlight(false);
203 }
204
205 private void HighlightOnObject()
207 _currentItem.Highlight(false);
208 }
209
210 private void ActivateObject()
212 _currentItem.Active(true);
213 }
214
215 private void DeactivateObject()
217 _currentItem.Active(false);
218 }
219
220
221 public void ApplyChanges()
222 {
223 var item = _stepManager.GetGameObjectByID(ItemsEnum.GAME_MENU);
224 item.IsActive = _isActive.isOn;
225 item.IsBroken = _isBroken.isOn;
226 item.isInspected = _isInspected.isOn;
227 }
228
229
230 IEnumerator StartInit()
231 {
232 yield return new WaitForSeconds(2f);
233 InitDebugUI();
234 }
235 }
236}
Intentionally made partial, in case you want to extend it easily.
Unity components communication service.
Interactive (true) method call on interactable objects function Often this is used to enable the abil...
s Base class for interactable objects with which the step manager interacts. It also stores a set of ...
virtual void TurnOnOffState(bool turnOn)
virtual void GenerateBreakdown(int percentBroke)
Generate a breakdown on the object with a certain probability.
virtual void Active(bool state)
virtual void Highlight(bool state)
Highlight an object.
Button _deactivateButton
[SerializeField]
Dictionary< string, InteractableClass > _StringItemsDictionary
Dictionary< ItemsEnum, InteractableClass > _ItemsDictionary
Button _turnOnButton
[SerializeField]
TMP_Text _currentFunctionText
[SerializeField]
void StepSelected(Dropdown dropdownSteps)
Toggle _isBroken
[SerializeField]
Button _skipStepButton
[SerializeField]
void UpdateStepInfo(string step, int function)
Dropdown _dropdownItems
[SerializeField]
Button _highlightOffButton
[SerializeField]
Toggle _isInspected
[SerializeField]
Button _closeButton
[SerializeField]
Toggle _isActive
[SerializeField]
Dropdown _dropdownSteps
[SerializeField]
Button _highlightOnButton
[SerializeField]
void ItemSelected(Dropdown dropdownItems)
Button _repairOnButton
[SerializeField]
Button _breakDownButton
[SerializeField]
Button _turnOffButton
[SerializeField]
TMP_Text _currentStepText
[SerializeField]
Button _goToStepButton
[SerializeField]
Button _activateButton
[SerializeField]
Logic for saving and unloading states during project execution.
Main system for working with steps lists.
InteractableClass GetGameObjectByID(ItemsEnum itemId)
Get scene object by item id.
Dictionary< ItemsEnum, InteractableClass > GetDictionary()
void GoToStep(string stepId)
List< StepItem > listOfSteps
Definition StepsData.cs:13
ItemsEnum
Represents a list of ID for interactable objects.
Definition ItemsEnum.cs:11