diff options
author | chai <215380520@qq.com> | 2023-05-08 02:29:25 +0800 |
---|---|---|
committer | chai <215380520@qq.com> | 2023-05-08 02:29:25 +0800 |
commit | b5aeebf4835ba0d7335113dd3f320a4af5b6d148 (patch) | |
tree | 8bd28d8c7f08de90718b1aab12bc64de9d4f40f1 /marching/Assets/Scripts/Physics/TestQuadtree.cs | |
parent | 373acc2d0761e178c5c35d36006c28d57c8a1739 (diff) |
* quadtree
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; + } + } + +} |