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); } } } } } }
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 StaticObjectClass GetObjectsInPos(Vector3 pos) { QuadTreeStaticObjectsCell cellAtPos = this.GetCellAtPos(pos); foreach (StaticObjectClass staticObjectClass in cellAtPos.m_Objects) { if (staticObjectClass.m_GameObject.transform.position == pos) { return(staticObjectClass); } } return(null); }
public List <StaticObjectClass> GetObjectsInRadius(Vector3 pos, float radius, bool use_bounds = false) { this.m_ObjectsInRadius.Clear(); if (use_bounds) { QuadTreeStaticObjectsCell cellAtPos = this.GetCellAtPos(pos); for (int i = 0; i < cellAtPos.m_Objects.Count; i++) { Bounds bounds = default(Bounds); GameObject gameObject = cellAtPos.m_Objects[i].m_GameObject; bounds.Encapsulate(new Vector3(1f, 1f, 1f)); bounds.center = new Vector3(0f, 0f, 0f); Vector3 point = gameObject.transform.InverseTransformPoint(pos); if (bounds.Contains(point)) { this.m_ObjectsInRadius.Add(cellAtPos.m_Objects[i]); } } } else { Vector3 pos2 = pos; pos2.x -= radius; pos2.z -= radius; QuadTreeStaticObjectsCell cellAtPos2 = this.GetCellAtPos(pos2); Vector3 pos3 = pos; pos3.x += radius; pos3.z += radius; QuadTreeStaticObjectsCell cellAtPos3 = this.GetCellAtPos(pos3); for (int j = cellAtPos2.m_X; j <= cellAtPos3.m_X; j++) { for (int k = cellAtPos2.m_Y; k <= cellAtPos3.m_Y; k++) { QuadTreeStaticObjectsCell quadTreeStaticObjectsCell = this.m_Cells[j, k]; for (int l = 0; l < quadTreeStaticObjectsCell.m_Objects.Count; l++) { GameObject gameObject2 = quadTreeStaticObjectsCell.m_Objects[l].m_GameObject; if (gameObject2 == null) { Debug.Log("Quad tree GetObjectsInRadius - obj is null : GameObject obj = cell.m_Objects[i];"); } if (gameObject2 && (gameObject2.transform.position - pos).magnitude < radius) { this.m_ObjectsInRadius.Add(quadTreeStaticObjectsCell.m_Objects[l]); } } } } } return(this.m_ObjectsInRadius); }
public void RemoveObject(GameObject go) { if (!this.m_ObjCellMap.ContainsKey(go)) { return; } QuadTreeStaticObjectsCell quadTreeStaticObjectsCell = null; if (this.m_ObjCellMap.TryGetValue(go, out quadTreeStaticObjectsCell)) { quadTreeStaticObjectsCell.RemoveObject(go); this.m_ObjCellMap.Remove(go); return; } DebugUtils.Assert(false, true); }
public void OnObjectMoved(GameObject go) { QuadTreeStaticObjectsCell quadTreeStaticObjectsCell = null; if (!this.m_ObjCellMap.TryGetValue(go, out quadTreeStaticObjectsCell)) { return; } QuadTreeStaticObjectsCell cellAtPos = this.GetCellAtPos(go.transform.position); if (quadTreeStaticObjectsCell != cellAtPos) { quadTreeStaticObjectsCell.RemoveObject(go); this.InsertObject(go, false); } }
private QuadTreeStaticObjectsCell FindObjectCell(GameObject go) { for (int i = 0; i < this.m_NumCellsX; i++) { for (int j = 0; j < this.m_NumCellsY; j++) { QuadTreeStaticObjectsCell quadTreeStaticObjectsCell = this.m_Cells[i, j]; for (int k = 0; k < quadTreeStaticObjectsCell.m_Objects.Count; k++) { GameObject gameObject = quadTreeStaticObjectsCell.m_Objects[k].m_GameObject; if (go == gameObject) { return(quadTreeStaticObjectsCell); } } } } return(null); }
public void DrawDebug() { bool flag = false; bool flag2 = true; bool flag3 = true; for (int i = 0; i < this.m_NumCellsX; i++) { for (int j = 0; j < this.m_NumCellsY; j++) { QuadTreeStaticObjectsCell quadTreeStaticObjectsCell = this.m_Cells[i, j]; if (flag || (flag3 && quadTreeStaticObjectsCell.m_Objects.Count > 0)) { Vector3 zero = Vector3.zero; zero.x = quadTreeStaticObjectsCell.m_Pos.x; zero.z = quadTreeStaticObjectsCell.m_Pos.y; Vector3 end = zero; end.x += quadTreeStaticObjectsCell.m_Size.x; DebugRender.DrawLine(zero, end, Color.white, 0f); end = zero; end.z += quadTreeStaticObjectsCell.m_Size.y; DebugRender.DrawLine(zero, end, Color.white, 0f); } if (flag2) { for (int k = 0; k < quadTreeStaticObjectsCell.m_Objects.Count; k++) { GameObject gameObject = quadTreeStaticObjectsCell.m_Objects[k].m_GameObject; if (gameObject) { DebugRender.DrawPoint(gameObject.transform.position, gameObject.activeSelf ? Color.red : Color.green, 0.3f, 0f); } } } } } }