private void EnableObjectsInQuadTree() { QuadTreeStaticObjectsCell[,] cells = this.m_QuadTree.GetCells(); for (int i = 0; i < this.m_QuadTree.GetNumCellsX(); i++) { for (int j = 0; j < this.m_QuadTree.GetNumCellsY(); j++) { QuadTreeStaticObjectsCell quadTreeStaticObjectsCell = cells[i, j]; for (int k = 0; k < quadTreeStaticObjectsCell.m_Objects.Count; k++) { StaticObjectClass staticObjectClass = quadTreeStaticObjectsCell.m_Objects[k]; if (staticObjectClass.m_GameObject != null) { staticObjectClass.m_GameObject.GetComponents <StaticObject>(this.m_StaticObjectTempList); StaticObject staticObject = null; if (this.m_StaticObjectTempList.Count > 0) { staticObject = this.m_StaticObjectTempList[0]; } if (staticObject != null && !staticObject.m_IsBeingDestroyed) { staticObject.gameObject.SetActive(true); } } } } } }
private void OnLoaded() { List <Vector3> allPoints = this.m_DestroyedObjects.GetAllPoints(); for (int i = 0; i < allPoints.Count; i++) { StaticObjectClass objectsInPos = this.m_QuadTree.GetObjectsInPos(allPoints[i]); if (objectsInPos != null && objectsInPos.m_GameObject != null) { GameObject gameObject = objectsInPos.m_GameObject; if (gameObject.transform.parent != null) { gameObject.transform.parent.gameObject.SetActive(false); StaticObjectClass staticObjectClass = objectsInPos; staticObjectClass.m_State |= 1; GameObject gameObject2 = null; if (this.m_ReplacedMap.TryGetValue(objectsInPos, out gameObject2)) { this.m_ReplacedMap.Remove(objectsInPos); this.m_ObjectsRemovedFromStatic.Remove(objectsInPos); } } } } }
public void InsertObject(GameObject obj, bool use_bounds = false) { if (use_bounds) { Vector3 pos = obj.transform.position - obj.transform.localScale * 0.5f; Vector3 pos2 = obj.transform.position + obj.transform.localScale * 0.5f; QuadTreeStaticObjectsCell cellAtPos = this.GetCellAtPos(pos); QuadTreeStaticObjectsCell cellAtPos2 = this.GetCellAtPos(pos2); for (int i = cellAtPos.m_X; i <= cellAtPos2.m_X; i++) { for (int j = cellAtPos.m_Y; j <= cellAtPos2.m_Y; j++) { StaticObjectClass staticObjectClass = new StaticObjectClass(); staticObjectClass.m_GameObject = obj; this.m_Cells[i, j].m_Objects.Add(staticObjectClass); this.m_ObjCellMap[obj] = this.m_Cells[i, j]; } } return; } QuadTreeStaticObjectsCell cellAtPos3 = this.GetCellAtPos(obj.transform.position); StaticObjectClass staticObjectClass2 = new StaticObjectClass(); staticObjectClass2.m_GameObject = obj; cellAtPos3.m_Objects.Add(staticObjectClass2); this.m_ObjCellMap[obj] = cellAtPos3; }
public void Load() { foreach (GameObject obj in this.m_ReplacedMap.Values) { UnityEngine.Object.Destroy(obj); } this.m_ReplacedMap.Clear(); this.m_ObjectsRemovedFromStatic.Clear(); this.EnableObjectsInQuadTree(); List <Vector3> allPoints = this.m_DestroyedObjects.GetAllPoints(); for (int i = 0; i < allPoints.Count; i++) { StaticObjectClass objectsInPos = this.m_QuadTree.GetObjectsInPos(allPoints[i]); if (objectsInPos != null && objectsInPos.m_GameObject != null) { objectsInPos.m_GameObject.SetActive(true); if (objectsInPos.m_GameObject.transform.parent != null) { objectsInPos.m_GameObject.transform.parent.gameObject.SetActive(true); } objectsInPos.m_State = 0; } } this.m_DestroyedObjects.Clear(); int num = 0; SaveGame.LoadVal("SOMDestroyedCount", out num, false); Vector3 zero = Vector3.zero; for (int j = 0; j < num; j++) { SaveGame.LoadVal("SOMPos" + j, out zero, false); StaticObjectClass objectsInPos2 = this.m_QuadTree.GetObjectsInPos(zero); if (objectsInPos2 != null && objectsInPos2.m_GameObject != null) { objectsInPos2.m_GameObject.SetActive(false); if (objectsInPos2.m_GameObject.transform.parent != null) { objectsInPos2.m_GameObject.transform.parent.gameObject.SetActive(false); } } this.m_DestroyedObjects.InsertPoint(zero, false); } ObjectWithTrunk.OnLoad(); this.OnLoaded(); }
public override void OnReplicationDeserialize(P2PNetworkReader reader, bool initial_state) { if (initial_state) { foreach (GameObject obj in this.m_ReplacedMap.Values) { UnityEngine.Object.Destroy(obj); } this.m_ReplacedMap.Clear(); this.m_ObjectsRemovedFromStatic.Clear(); this.EnableObjectsInQuadTree(); List <Vector3> allPoints = this.m_DestroyedObjects.GetAllPoints(); for (int i = 0; i < allPoints.Count; i++) { StaticObjectClass objectsInPos = this.m_QuadTree.GetObjectsInPos(allPoints[i]); if (objectsInPos != null && objectsInPos.m_GameObject != null) { objectsInPos.m_GameObject.SetActive(true); if (objectsInPos.m_GameObject.transform.parent != null) { objectsInPos.m_GameObject.transform.parent.gameObject.SetActive(true); } objectsInPos.m_State = 0; } } this.m_DestroyedObjects.Clear(); ushort num = reader.ReadUInt16(); for (int j = 0; j < (int)num; j++) { Vector3 vector = reader.ReadVector3(); StaticObjectClass objectsInPos2 = this.m_QuadTree.GetObjectsInPos(vector); if (objectsInPos2 != null && objectsInPos2.m_GameObject != null) { objectsInPos2.m_GameObject.SetActive(false); if (objectsInPos2.m_GameObject.transform.parent != null) { objectsInPos2.m_GameObject.transform.parent.gameObject.SetActive(false); } } this.m_DestroyedObjects.InsertPoint(vector, false); } ObjectWithTrunk.OnLoad(); this.OnLoaded(); } }
public void ObjectDestroyed(Vector3 pos) { StaticObjectClass objectsInPos = this.m_QuadTree.GetObjectsInPos(pos); if (objectsInPos != null && objectsInPos.m_GameObject != null) { objectsInPos.m_GameObject.SetActive(false); if (objectsInPos.m_GameObject.transform.parent != null) { objectsInPos.m_GameObject.transform.parent.gameObject.SetActive(false); } GameObject obj = null; if (this.m_ReplacedMap.TryGetValue(objectsInPos, out obj)) { UnityEngine.Object.Destroy(obj); } } this.m_DestroyedObjects.InsertPoint(pos, false); }
private void Update() { if (LoadingScreen.Get().m_Active) { return; } List <StaticObjectClass> objectsInRadius = this.m_QuadTree.GetObjectsInRadius(Player.Get().gameObject.transform.position, 10f, false); for (int i = 0; i < objectsInRadius.Count; i++) { StaticObjectClass staticObjectClass = objectsInRadius[i]; if (staticObjectClass.m_GameObject.activeSelf && staticObjectClass.m_State != 1 && !this.m_ObjectsRemovedFromStatic.Contains(staticObjectClass)) { StaticObjectsReplace staticObjectsReplace = null; if (this.m_ReplaceMap.TryGetValue(staticObjectClass.m_GameObject.name, out staticObjectsReplace)) { staticObjectClass.m_GameObject.SetActive(false); this.m_ObjectsRemovedFromStatic.Add(staticObjectClass); GameObject gameObject; if (this.m_EnablePooling) { if (this.m_Pool[staticObjectsReplace.m_PrefabName].Count > 0) { gameObject = this.m_Pool[staticObjectsReplace.m_PrefabName].ElementAt(0); this.m_Pool[staticObjectsReplace.m_PrefabName].RemoveAt(0); } else { gameObject = UnityEngine.Object.Instantiate <GameObject>(staticObjectsReplace.m_Prefab); this.m_TempItemList.Clear(); gameObject.GetComponents <Item>(this.m_TempItemList); if (this.m_TempItemList.Count > 0) { this.m_TempItemList[0].m_CanSaveNotTriggered = false; } } gameObject.SetActive(true); } else { gameObject = UnityEngine.Object.Instantiate <GameObject>(staticObjectsReplace.m_Prefab); this.m_TempItemList.Clear(); gameObject.GetComponents <Item>(this.m_TempItemList); if (this.m_TempItemList.Count > 0) { this.m_TempItemList[0].m_CanSaveNotTriggered = false; } } this.m_ReplacedMap.Add(staticObjectClass, gameObject); gameObject.transform.position = staticObjectClass.m_GameObject.transform.parent.position; gameObject.transform.rotation = staticObjectClass.m_GameObject.transform.parent.rotation; gameObject.transform.localScale = staticObjectClass.m_GameObject.transform.parent.localScale; Item component = gameObject.GetComponent <Item>(); if (component) { component.Initialize(false); } } } } int j = 0; while (j < this.m_ObjectsRemovedFromStatic.Count) { StaticObjectClass staticObjectClass2 = this.m_ObjectsRemovedFromStatic[j]; if (!objectsInRadius.Contains(staticObjectClass2)) { GameObject gameObject2 = null; if (this.m_ReplacedMap.TryGetValue(staticObjectClass2, out gameObject2)) { if (gameObject2 != null) { if (this.m_EnablePooling) { gameObject2.transform.position = this.m_PoolPosition; gameObject2.SetActive(false); this.m_Pool[this.m_ReplaceMap[staticObjectClass2.m_GameObject.name].m_PrefabName].Add(gameObject2); staticObjectClass2.m_GameObject.SetActive(true); } else { UnityEngine.Object.Destroy(gameObject2); if (staticObjectClass2.m_GameObject == null) { this.m_ObjectsRemovedFromStatic.Remove(staticObjectClass2); continue; } staticObjectClass2.m_GameObject.SetActive(true); } } else { if (staticObjectClass2.m_GameObject == null) { this.m_ObjectsRemovedFromStatic.Remove(staticObjectClass2); continue; } staticObjectClass2.m_State = 1; if (staticObjectClass2.m_GameObject.transform.parent != null) { staticObjectClass2.m_GameObject.transform.parent.gameObject.SetActive(false); } } this.m_ReplacedMap.Remove(staticObjectClass2); this.m_ObjectsRemovedFromStatic.Remove(staticObjectClass2); } else { j++; } } else { j++; } } if (this.m_ReplacedMap.Count > 0) { Dictionary <StaticObjectClass, GameObject> .Enumerator enumerator = this.m_ReplacedMap.GetEnumerator(); if (enumerator.MoveNext()) { KeyValuePair <StaticObjectClass, GameObject> keyValuePair = enumerator.Current; if (keyValuePair.Key.m_GameObject == null) { Dictionary <StaticObjectClass, GameObject> replacedMap = this.m_ReplacedMap; keyValuePair = enumerator.Current; replacedMap.Remove(keyValuePair.Key); } } enumerator.Dispose(); } }