diff options
Diffstat (limited to 'marching/Assets/Scripts/Physics/TestQuadtree.cs')
-rw-r--r-- | marching/Assets/Scripts/Physics/TestQuadtree.cs | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/marching/Assets/Scripts/Physics/TestQuadtree.cs b/marching/Assets/Scripts/Physics/TestQuadtree.cs new file mode 100644 index 0000000..07ed353 --- /dev/null +++ b/marching/Assets/Scripts/Physics/TestQuadtree.cs @@ -0,0 +1,53 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using mh; +using MH; +using Unity.VisualScripting; + +namespace mh +{ + [DefaultExecutionOrder(-1000)] + public class TestQuadtree : MonoBehaviour + { + public static mh.Quadtree m_Quadtree; + public static mh.Quadtree quadtree { get { return m_Quadtree; } } + + private void Awake() + { + m_Quadtree = new Quadtree(0, new Vector4(0, 0, 30, 30)); + } + + // Start is called before the first frame update + void Start() + { + + } + + // Update is called once per frame + void Update() + { + m_Quadtree.Clear(false); + var pos = UnitManager.hero.transform.position; + m_Quadtree.Rebound(new Vector4(pos.x, pos.y, 50, 50)); + var objs = PhysicsManager.quadTreeObjects; + for(int i = 0; i < objs.Count; ++i) + { + TestQuadtree.quadtree.Insert(objs[i]); + } + } + + private void OnDrawGizmos() + { + Color c = Gizmos.color; + Gizmos.color = Color.red; + m_Quadtree?.Iterate((t) => { + Vector3 pos = new Vector3(t.x, t.y, 0); + Vector3 size = new Vector3(t.w, t.h, 1); + Gizmos.DrawWireCube(pos, size); + }); + Gizmos.color = c; + } + } + +} |