Exemplo n.º 1
0
        // Use this for initialization
        void Start()
        {
            Tree4 tree4Root = new Tree4(new Rect(-50, -50, 100, 100), 0);

            tree4Root.build();
            tree4Root.buildNode8All();

            GameObject go = new GameObject("go0");

            go.transform.position = new Vector3(20f, 0, 13f);
            tree4Root.addGameObject(go);
            go = new GameObject("go1");
            go.transform.position = new Vector3(-20f, 0, 13f);
            tree4Root.addGameObject(go);

            tree4Root.log();

            Tree4 t = tree4Root.findTree4Node(go);

            Debug.LogWarning("find = " + t.rect);

            Tree4 Treebyp = tree4Root.findByPot(new Vector3(0f, 5f, 0f));

            Treebyp.log8();
        }
Exemplo n.º 2
0
        public void build()
        {
            if (curDepth >= depth)
            {
                tile_w = rect.width;
                tile_h = rect.height;

                root.leavesNode.Add(this);

                return;
            }

            int chDepth = curDepth + 1;

            Rect rect0 = new Rect(rect.x, rect.y, rect.width * .5f, rect.height * .5f);
            Rect rect1 = new Rect(rect.x, rect.y + rect.height * .5f, rect.width * .5f, rect.height * .5f);
            Rect rect2 = new Rect(rect.x + rect.width * .5f, rect.y, rect.width * .5f, rect.height * .5f);
            Rect rect3 = new Rect(rect.x + rect.width * .5f, rect.y + rect.height * .5f, rect.width * .5f, rect.height * .5f);

            if (node0 != null)
            {
                node0.destroy();
                node0 = null;
            }
            if (node1 != null)
            {
                node1.destroy();
                node1 = null;
            }
            if (node2 != null)
            {
                node2.destroy();
                node2 = null;
            }
            if (node3 != null)
            {
                node3.destroy();
                node3 = null;
            }

            node0 = new Tree4(rect0, chDepth, this, root);
            node1 = new Tree4(rect1, chDepth, this, root);
            node2 = new Tree4(rect2, chDepth, this, root);
            node3 = new Tree4(rect3, chDepth, this, root);

            node0.build();
            node1.build();
            node2.build();
            node3.build();
        }