Exemplo n.º 1
0
        void Update()
        {
            if (!autoUpdate)
            {
                return;
            }

            float move = speedMax * Time.deltaTime;

            foreach (var pws in managed)
            {
                AVector2 pos = pws.pos;
                pos.x  += (Random.value - 0.5f) * 2 * move;
                pos.y  += (Random.value - 0.5f) * 2 * move;
                pws.pos = pos;
            }

            BuildKDTree();
            QueryInTree();
        }
Exemplo n.º 2
0
        private void DrawKDNode(KDNode node)
        {
            if (node == null)
            {
                return;
            }

            if (node.leftLeaf == null && node.rightLeaf == null)
            {
                // 真leaf
                AVector2 min = node.min;
                AVector2 max = node.max;

                Vector3 p00 = new Vector3(min.x, min.y, 0);
                Vector3 p01 = new Vector3(min.x, max.y, 0);
                Vector3 p10 = new Vector3(max.x, min.y, 0);
                Vector3 p11 = new Vector3(max.x, max.y, 0);

                Gizmos.DrawLine(p00, p01);
                Gizmos.DrawLine(p01, p11);
                Gizmos.DrawLine(p11, p10);
                Gizmos.DrawLine(p10, p00);
            }
        }