-
Notifications
You must be signed in to change notification settings - Fork 0
/
ObjectState.cs
320 lines (292 loc) · 14 KB
/
ObjectState.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
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>The 'State' abstract class </summary>
abstract class State
{
public abstract void StateIn(VisualStateContext context);
public abstract void StateIn(VisualStateContext context, float duration);
public abstract void StateOut(VisualStateContext context);
public abstract void StateOut(VisualStateContext context, float duration);
}
////////////////////////////////////////////////////////////////////////
///////////// AREA VISUAL STATES /////////////////////////
////////////////////////////////////////////////////////////////////////
/// <summary> Idle State class</summary>
class Idle_State : State
{
public override void StateIn(VisualStateContext context)
{
// StateIn(context, 0.0f);
context.parent.SetMaterialInitialColor(); //Init material
}
public override void StateIn(VisualStateContext context, float duration)
{
//context.parent.SetMaterialInitialColor(); //Init material
//context.parent.SetMaterialInitialConditions(duration); //Init material
//context.parent.ProcessFadeInEffect(0, duration, ObjectStateMaterialUtils.TMaterialState.Visible); //Make the material visible
}
public override void StateOut(VisualStateContext context) { }
public override void StateOut(VisualStateContext context, float duration) { }
}
/// <summary> Indicated State class </summary>
class Indicated_State : State
{
public override void StateIn(VisualStateContext context)
{
hom3r.coreLink.EmitEvent(new CCoreEvent(TCoreEvent.ObjectState_AreaIndicateOn, context.parent.gameObject)); //Emit and event: I'm indicated
ObjectStateMaterialUtils.SetColourToMaterial(context.parent.GetComponent<Renderer>().material, context.parent.indicatedColour); //Change color of the material
}
public override void StateIn(VisualStateContext context, float duration) { }
public override void StateOut(VisualStateContext context)
{
hom3r.coreLink.EmitEvent(new CCoreEvent(TCoreEvent.ObjectState_AreaIndicateOff, context.parent.gameObject)); //Emit and event: I'm not indicated anymore
context.parent.ProcessFadeInEffect(0, 0.0f, ObjectStateMaterialUtils.TMaterialState.Visible);
}
public override void StateOut(VisualStateContext context, float duration) { }
}
/// <summary> Confirmed State class</summary>
class Confirmed_State : State
{
public override void StateIn(VisualStateContext context)
{
this.StateIn(context, 0.0f);
////Add to the list of confirmed objects
//hom3r.quickLinks.scriptsObject.GetComponent<SelectionManager>().ConfirmGameObjectON(context.parent.gameObject);
////Change color of the material
//ObjectStateMaterialUtils.SetColourToMaterial(context.parent.GetComponent<Renderer>().material, context.parent.confirmedColour);
////Add label to the area if proceed
//hom3r.quickLinks.scriptsObject.GetComponent<Core>().EmitEvent(new CCoreEvent(TCoreEvent.ObjectState_AreaConfirmationOn, context.parent.gameObject));
}
public override void StateIn(VisualStateContext context, float duration) {
context.parent.SetConfirmedState(duration); //Init material
}
public override void StateOut(VisualStateContext context)
{
//Delete from the list of confirmed GameObjects
hom3r.quickLinks.scriptsObject.GetComponent<SelectionManager>().ConfirmSingleGameObjectOFF(context.parent.gameObject);
hom3r.quickLinks.scriptsObject.GetComponent<Core>().EmitEvent(new CCoreEvent(TCoreEvent.ObjectState_AreaConfirmationOff, context.parent.gameObject));
}
public override void StateOut(VisualStateContext context, float duration) { }
}
/// <summary> TransparentIdle State class</summary>
class TransparentIdle_State : State
{
public override void StateIn(VisualStateContext context)
{
StateIn(context, 0.0f);
}
public override void StateIn(VisualStateContext context, float duration)
{
context.parent.SetMaterialInitialColor(); // Set Initial color. testing
context.parent.ProcessFadeOutEffect(0.0f, duration, ObjectStateMaterialUtils.TMaterialState.Transparent); //Make the material transparent
hom3r.coreLink.EmitEvent(new CCoreEvent(TCoreEvent.ObjectState_AreaTransparencyOn, context.parent.gameObject)); //Emit and event telling we are going to be transparent
}
public override void StateOut(VisualStateContext context)
{
StateOut(context, 0.0f);
}
public override void StateOut(VisualStateContext context, float duration)
{
hom3r.coreLink.EmitEvent(new CCoreEvent(TCoreEvent.ObjectState_AreaTransparencyOff, context.parent.gameObject)); //Emit and event telling we are not going to be transparent anymore
context.parent.ProcessFadeInEffect(0, duration, ObjectStateMaterialUtils.TMaterialState.Visible); //Make the material visible
}
}
/// <summary> TransparentIndicated State class</summary>
class TransparentIndicated_State : State
{
public override void StateIn(VisualStateContext context)
{
context.parent.ProcessFadeOutEffect(0.0f, 0.0f, ObjectStateMaterialUtils.TMaterialState.Transparent); //Make the material transparent
hom3r.coreLink.EmitEvent(new CCoreEvent(TCoreEvent.ObjectState_AreaTransparencyOn, context.parent.gameObject)); //Emit and event telling we are going to be transparent
//Get new the color of the material
Color temp = context.parent.indicatedColour;
//temp.a = UIMaterialTransparency.GetMaterialAlphaLevel();
temp.a = hom3r.state.smartTransparencyAlphaLevel;
ObjectStateMaterialUtils.SetColourToMaterial(context.parent.GetComponent<Renderer>().material, temp); //Change color of the material
hom3r.coreLink.EmitEvent(new CCoreEvent(TCoreEvent.ObjectState_AreaIndicateOn, context.parent.gameObject)); //Emit and event: I'm indicated
}
public override void StateIn(VisualStateContext context, float duration) { }
public override void StateOut(VisualStateContext context)
{
hom3r.coreLink.EmitEvent(new CCoreEvent(TCoreEvent.ObjectState_AreaTransparencyOff, context.parent.gameObject));
hom3r.coreLink.EmitEvent(new CCoreEvent(TCoreEvent.ObjectState_AreaIndicateOff, context.parent.gameObject)); //Emit and event: I'm not indicated anymore
}
public override void StateOut(VisualStateContext context, float duration) { }
}
/// <summary> HiddenCollider State class</summary>
class HiddenColliderOn_State : State
{
public override void StateIn(VisualStateContext context)
{
//Add to the list of hidden objects
//hom3r.quickLinks.scriptsObject.GetComponent<Hidden_Script>().GameObjectHiddenOn(context.parent.gameObject);
hom3r.coreLink.EmitEvent(new CCoreEvent(TCoreEvent.ObjectState_AreaHiddenOn, context.parent.gameObject));
//We Activate the mesh collider, we can select
context.parent.GetComponent<MeshCollider>().enabled = true;
}
public override void StateIn(VisualStateContext context, float duration) { }
public override void StateOut(VisualStateContext context)
{
//Delete from the list of hidden GameObjects
//hom3r.quickLinks.scriptsObject.GetComponent<Hidden_Script>().GameObjectHiddenOff(context.parent.gameObject);
hom3r.coreLink.EmitEvent(new CCoreEvent(TCoreEvent.ObjectState_AreaHiddenOff, context.parent.gameObject));
//We deactivate the mesh collider, we cannot select it any more
context.parent.GetComponent<MeshCollider>().enabled = false;
}
public override void StateOut(VisualStateContext context, float duration) { }
}
/// <summary> HiddenCollider State class</summary>
class RemoveIdle_State : State
{
public override void StateIn(VisualStateContext context)
{
StateIn(context, 0.0f);
}
public override void StateIn(VisualStateContext context, float duration)
{
context.parent.ProcessFadeOutEffect(0.0f, duration, ObjectStateMaterialUtils.TMaterialState.Hide); //Make the material Hide
hom3r.coreLink.EmitEvent(new CCoreEvent(TCoreEvent.ObjectState_AreaRemoveOn, context.parent.gameObject)); //Add to the list of hidden objects
}
public override void StateOut(VisualStateContext context)
{
StateOut(context, 0.0f);
}
public override void StateOut(VisualStateContext context, float duration)
{
context.parent.ProcessFadeInEffect(0, duration, ObjectStateMaterialUtils.TMaterialState.Visible);
hom3r.coreLink.EmitEvent(new CCoreEvent(TCoreEvent.ObjectState_AreaRemoveOff, context.parent.gameObject)); //Delete from the list of confirmed GameObjects
}
}
////////////////////////////////////////////////////////////////////////
///////////// AREA VISUAL STATE MACHINE /////////////////////////
////////////////////////////////////////////////////////////////////////
/// <summary> The 'Context' class </summary>
class VisualStateContext
{
public State state { get; set; }
public ObjectStateManager parent { get; set; }
public VisualStateContext(ObjectStateManager _parent, State _state)
{
this.state = _state;
this.parent = _parent;
this.state.StateIn(this);
}
public void ChangeState_toIdle()
{
if (this.state.GetType().Name == "Idle_State" || this.state.GetType().Name == "Indicated_State" || this.state.GetType().Name == "Confirmed_State" || this.state.GetType().Name == "TransparentIdle_State" || this.state.GetType().Name == "RemoveIdle_State")
{
//Finish current state
state.StateOut(this);
//Start new state
state = new Idle_State();
state.StateIn(this);
}
}
public void ChangeState_toIdle(float duration)
{
if (this.state.GetType().Name == "TransparentIdle_State" || this.state.GetType().Name == "RemoveIdle_State")
{
//Finish current state
state.StateOut(this, duration);
//Start new state
state = new Idle_State();
state.StateIn(this, duration);
}
}
public void ChangeState_toIndicate(bool multiple)
{
if (this.state.GetType().Name == "Idle_State")
{
//Finish current state
state.StateOut(this);
if (!multiple)
{
hom3r.quickLinks.scriptsObject.GetComponent<SelectionManager>().IndicationGameObjectAllOFF();
}
//Start new state
state = new Indicated_State();
state.StateIn(this);
}
}
public void ChangeState_toTransparentIdle()
{
if (this.state.GetType().Name == "TransparentIndicated_State")
{
//Finish current state
state.StateOut(this);
//Start new state
state = new TransparentIdle_State();
state.StateIn(this);
}
}
public void ChangeState_toTransparentIndicated()
{
if (this.state.GetType().Name == "TransparentIdle_State")
{
//Finish current state
state.StateOut(this);
//Start new state
state = new TransparentIndicated_State();
state.StateIn(this);
}
}
public void ChangeState_toConfirmed(bool multiple, float duration = 0.0f)
{
//Finish current state
state.StateOut(this, duration);
if (!multiple)
{
//2. Des-confirm all previous objects
hom3r.quickLinks.scriptsObject.GetComponent<SelectionManager>().ConfirmALLGameObjectOFF();
}
//Change to the new state
state = new Confirmed_State();
state.StateIn(this, duration);
}
public void ChangeState_toTransparent(float duration)
{
if (this.state.GetType().Name == "Idle_State")
{
//Finish current state
state.StateOut(this);
//Change to the new state
state = new TransparentIdle_State();
state.StateIn(this, duration);
}
else if (this.state.GetType().Name == "HiddenIdle_State")
{
//Finish current state
state.StateOut(this, duration);
//Change to the new state
state = new TransparentIdle_State();
state.StateIn(this, duration);
}
}
public void ChangeState_toColliderOn()
{
// Finish current state
state.StateOut(this);
//Start new state
state = new HiddenColliderOn_State();
state.StateIn(this);
}
public void ChangeState_toRemove(float duration)
{
if (this.state.GetType().Name == "Idle_State" || this.state.GetType().Name == "Indicated_State" || this.state.GetType().Name == "Confirmed_State" || this.state.GetType().Name == "TransparentIdle_State")
{
//Finish current state
state.StateOut(this);
//Change to the new state
state = new RemoveIdle_State();
state.StateIn(this, duration);
}
}
}
/// <summary> Enum to return the current visual state of the area </summary>
public enum TObjectVisualStates { Idle, Indicated, Confirmed, Transparent_Idle, Transparent_Indicated, Hidden_Idle, Hidden_Collider_On, Remove_Idle };
//////////////////////////////////////////////////////////////////////////
//////////// AREA EXPLOSION STATE MACHINE /////////////////////////
//////////////////////////////////////////////////////////////////////////
public enum ObjectExplosionState_Type { No_Explode, Explode };
public enum ObjectExplosionStateEvents_Type { Explode, Implode };