Demo代码:
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 |
using System.Collections; using System.Collections.Generic; using UnityEngine; namespace WCC.QuadTree { public class Demo : MonoBehaviour { public Bounds bounds; private Tree tree; [SerializeField] int objCount = 10000; [SerializeField] float viewRatio = 1; // Start is called before the first frame update void Start() { tree = new Tree(bounds); for (int i = 0; i < objCount; i++) { Vector3 randomPosition = new Vector3(Random.Range(-1000f, 1000f), 0, Random.Range(-1000f, 1000f)); Vector3 randomScale = Vector3.one * Random.Range(0.5f, 2f); ObjData objData = new ObjData("Cube", randomPosition, Quaternion.identity, randomScale, Vector3.one); objData.uid = i; tree.InsertObjData(objData); } } // Update is called once per frame void Update() { tree.viewRatio = viewRatio; tree.Inside(Camera.main); } private void OnDrawGizmos() { if (tree != null) { tree.DrawBound(); } else { Gizmos.DrawWireCube(bounds.center, bounds.size); } } } } |
地址:https://github.com/654306663/QuadTreeMap
- 本文固定链接: http://www.u3d8.com/?p=2260
- 转载请注明: 网虫虫 在 u3d8.com 发表过