-
Notifications
You must be signed in to change notification settings - Fork 0
/
RemoveManager.cs
140 lines (117 loc) · 5.48 KB
/
RemoveManager.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
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class RemoveManager : MonoBehaviour {
List<GameObject> gameObjectRemoveList; //In this list will be stored the game-objects that have been made hidden
private void Awake()
{
// hom3r.quickLinks.scriptsObject.GetComponent<OcclusionCommandReceiver>().removeManager = this.GetComponent<RemoveManager>();
gameObjectRemoveList = new List<GameObject>(); //We create a list in which will be stored the game-objects that are hidden
}
/////////////////////////////
///// Public Methods
////////////////////////////
/// <summary>Check if an object has been removed</summary>
public bool IsRemovedGameObject(GameObject obj)
{
return gameObjectRemoveList.Contains(obj);
}
/// <summary>Check if an area has been removed</summary>
public bool IsRemovedArea(string _areaId)
{
if (!hom3r.quickLinks.scriptsObject.GetComponent<ModelManager>().IsArea(_areaId)) { return false; }
GameObject obj = hom3r.quickLinks.scriptsObject.GetComponent<ModelManager>().GetAreaGameObject_ByAreaID(_areaId);
if (obj == null ) { return false; }
return this.IsRemovedGameObject(obj);
}
/// <summary>Add an object to Remove list.</summary>
public void AddToRemovedList(GameObject obj )
{
if (!IsRemovedGameObject(obj)) {
gameObjectRemoveList.Add(obj);
string _areaID = obj.GetComponent<ObjectStateManager>().areaID;
hom3r.coreLink.EmitEvent(new CCoreEvent(TCoreEvent.Occlusion_Removed_Area, _areaID));
}
}
/// <summary> Remove an object from removed list.</summary>
public void RemoveFromRemovedList(GameObject obj)
{
if (IsRemovedGameObject(obj)) {
gameObjectRemoveList.Remove(obj);
string _areaID = obj.GetComponent<ObjectStateManager>().areaID;
hom3r.coreLink.EmitEvent(new CCoreEvent(TCoreEvent.Occlusion_Shown_Area, _areaID));
}
}
/// <summary>Reveals all hidden game objects.</summary>
public void RevealAllRemovedGameObjects()
{
//Reveal all hidden objects
List<GameObject> temp = new List<GameObject>(gameObjectRemoveList);
List<string> areaIdList = new List<string>();
float duration = hom3r.quickLinks.scriptsObject.GetComponent<ConfigurationManager>().GetDurationRemoveAnimation();
foreach (GameObject obj in temp) {
if (obj.GetComponent<ObjectStateManager>() != null) {
//obj.GetComponent<ObjectStateManager>().SendEvent(TObjectVisualStateCommands.Remove_Off, duration);
obj.GetComponent<ObjectStateManager>().Do(new CObjectVisualStateCommand(TObjectVisualStateCommands.Remove_Off, duration));
areaIdList.Add(obj.GetComponent<ObjectStateManager>().areaID);
}
}
if (areaIdList.Count != 0)
{
hom3r.coreLink.EmitEvent(new CCoreEvent(TCoreEvent.RemovedPart_Deactivated, areaIdList));
}
}
/// <summary>Make hidden all the objects not confirmed.</summary>
public void RemoveNotCorfirmedNodes()
{
List<GameObject> removedAreas = new List<GameObject>();
//Call the recursive algorithm with the Turbine Father
removedAreas = RemoveNotCorfirmedNodesRecursive(hom3r.quickLinks._3DModelRoot);
//Emit event with removes areas
this.EmitRemovedAreaEvent(removedAreas);
}
/// <summary>Recursively runs through the turbine and becomes transparent objects that are unconfirmed
private List<GameObject> RemoveNotCorfirmedNodesRecursive(GameObject obj)
{
List<GameObject> _removedAreas = new List<GameObject>();
float duration = hom3r.quickLinks.scriptsObject.GetComponent<ConfigurationManager>().GetDurationRemoveAnimation();
//If the object is not in the list of confirmed we make it transparent
if (obj.GetComponent<Renderer>())
{
if (!this.GetComponent<SelectionManager>().IsConfirmedNodeLeaf(obj))
{
obj.GetComponent<ObjectStateManager>().Do(new CObjectVisualStateCommand(TObjectVisualStateCommands.Remove_On, duration));
_removedAreas.Add(obj);
return _removedAreas;
//}
}
}
//Call again to itself with one child
for (int i = obj.transform.childCount - 1; i >= 0; i--)
{
GameObject newChild = obj.transform.GetChild(i).gameObject;
_removedAreas.AddRange(RemoveNotCorfirmedNodesRecursive(newChild));
}
return _removedAreas;
}
private void EmitRemovedAreaEvent(List<GameObject> objList)
{
List<string> areaIDList = new List<string>();
foreach (GameObject obj in objList)
{
if (obj != null) {
if (obj.GetComponent<ObjectStateManager>().areaID != null || obj.GetComponent<ObjectStateManager>().areaID != "")
{
areaIDList.Add(obj.GetComponent<ObjectStateManager>().areaID);
}
}
}
if (areaIDList.Count != 0)
{
hom3r.coreLink.EmitEvent(new CCoreEvent(TCoreEvent.RemovedPart_Activate, areaIDList));
}
}
public List<GameObject> GetRemovedList() {
return gameObjectRemoveList;
}
}