-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBrainStateManager.cs
More file actions
166 lines (148 loc) · 5.76 KB
/
Copy pathBrainStateManager.cs
File metadata and controls
166 lines (148 loc) · 5.76 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
namespace NeuroViz
{
/// <summary>
/// Handles the global state of the game <br/>
/// What area is currently selected <br/>
/// Current view mode, etc.
/// </summary>
public class BrainStateManager : MonoBehaviour
{
/// <summary>
/// The brain model
/// </summary>
public GameObject brain;
/// <summary>
/// An internal reference to the current selected area; to be used by every other script to know "what's happening"
/// </summary>
[HideInInspector]
public ClickableBrainArea currentSelectedArea;
/// <summary>
/// The scriptable object that contains all the brain area names and descriptions
/// </summary>
public BrainAreaDatabase brainAreaDatabase;
/// <summary>
/// The left cerebrum from the brain model in the scene
/// </summary>
public GameObject leftCerebrum;
/// <summary>
/// The right cerebrum from the brain model in the scene
/// </summary>
public GameObject rightCerebrum;
/// <summary>
/// The cerebellum from the brain model in the scene
/// </summary>
public GameObject cerebellum;
/// <summary>
/// Used to define what state the view of the brain is in <br/>
/// Default = 0: as is <br/>
/// Cross_Section = 1: right cerebrum deactivated so half of inside can be seen <br/>
/// Internal = 2: right cerebrum, left cerebrum, and cerebellum deactivated so all of inside can be seen
/// </summary>
public enum BrainState
{
Default = 0,
Cross_Section = 1,
Internal = 2,
}
/// <summary>
/// The current state of view the brain is in
/// </summary>
[HideInInspector]
public BrainState currentState = BrainState.Default;
/// <summary>
/// Starting position of brain if camera is at (0,0,0) <br/>
/// Used to re-focus
/// </summary>
private Vector3 brainDistanceFromCamera;
/// <summary>
/// A local store of all the brain areas and corresponding descriptions <br/>
/// Loaded from the scriptable object on Start() to prevent frequent lookups to scriptable object
/// </summary>
private Dictionary<BrainArea, string> brainAreaDescriptions = new Dictionary<BrainArea, string>();
/// <summary>
/// Set the color of clicked area to this instead of outline
/// TODO: Refactor and maybe make this part of ClickableBrainArea
/// </summary>
public Material redMaterial;
// Singleton implementation
[HideInInspector]
public static BrainStateManager Instance { get; private set; }
private void Awake()
{
if (Instance != null && Instance != this)
{
Destroy(this);
return;
}
Instance = this;
}
private void Start()
{
LoadBrainData();
brainDistanceFromCamera = brain.transform.position;
}
/// <summary>
/// Handles clicking of a brain area; updates local references, relays call to UIManager
/// </summary>
/// <param name="selectedArea">The ClickableArea component of the brain area that was clicked on</param>
public void SelectBrainArea(ClickableBrainArea selectedArea)
{
currentSelectedArea = selectedArea;
if (brainAreaDescriptions.ContainsKey(selectedArea.brainArea))
{
UIManager.Instance.DisplayBrainAreaDetails(selectedArea.brainArea.ToString(), brainAreaDescriptions[selectedArea.brainArea]);
}
}
/// <summary>
/// Load the brain area names and descriptions to a local dictionarys
/// </summary>
private void LoadBrainData()
{
foreach (BrainAreaData data in brainAreaDatabase.brainAreas)
{
if (data == null) continue;
brainAreaDescriptions.Add(data.brainArea, data.longDescription);
}
}
/// <summary>
/// Handles transition of brain view states from UI buttons in game
/// </summary>
/// <param name="targetStateEnumInt">An integer representation of the targetState enum because we can't do enums in Unity btn onClick</param>
public void TransitionToBrainState(int targetStateEnumInt)
{
BrainState targetState = (BrainState)targetStateEnumInt;
switch (targetState)
{
case BrainState.Default:
rightCerebrum.SetActive(true);
leftCerebrum.SetActive(true);
cerebellum.SetActive(true);
break;
case BrainState.Cross_Section:
rightCerebrum.SetActive(false);
leftCerebrum.SetActive(true);
cerebellum.SetActive(true);
break;
case BrainState.Internal:
rightCerebrum.SetActive(false);
leftCerebrum.SetActive(false);
cerebellum.SetActive(false);
break;
default:
break;
}
currentState = targetState;
}
/// <summary>
/// Brings the brain back into camera view
/// </summary>
public void ReFocusBrain()
{
brain.transform.position = Camera.main.transform.position + brainDistanceFromCamera;
Camera.main.transform.rotation = Quaternion.identity;
}
}
}