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 Tree4 findByPot(Vector2 p)
 {
     if (node0 == null)
     {
         if (isInRect(p))
         {
             return(this);
         }
     }
     else
     {
         Tree4 treeNode = node0.findByPot(p);
         if (treeNode != null)
         {
             return(treeNode);
         }
         treeNode = node1.findByPot(p);
         if (treeNode != null)
         {
             return(treeNode);
         }
         treeNode = node2.findByPot(p);
         if (treeNode != null)
         {
             return(treeNode);
         }
         treeNode = node3.findByPot(p);
         if (treeNode != null)
         {
             return(treeNode);
         }
     }
     return(null);
 }
Exemplo n.º 3
0
        //public List<GameObject> goList = new List<GameObject>();
        public Tree4(Rect rectp, int curDepthp, Tree4 parentp = null, Tree4 rootp = null)
        {
            rect     = rectp;
            curDepth = curDepthp;
            parent   = parentp;
            root     = rootp;
            if (parent == null)
            {
                root = this;
            }

            nodeGameObject = new GameObject(rect.ToString());
        }
Exemplo n.º 4
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();
        }
Exemplo n.º 5
0
        void destroy()
        {
            root   = null;
            parent = null;

            goDic.Clear();

            if (node0 == null)
            {
                return;
            }

            node0.destroy();
            node1.destroy();
            node2.destroy();
            node3.destroy();
        }
Exemplo n.º 6
0
        public void build8()
        {
            if (tile_w == 0 || tile_h == 0)
            {
                Debug.LogError("Error !!! tile_w == 0 || tile_h == 0");
                return;
            }
            if (root == null)
            {
                Debug.LogError("Error !!! root == null");
                return;
            }

            node_0000 = root.findByPot(new Vector2(rect.x + rect.width * .5f, rect.y + rect.height * 1.5f));
            node_0130 = root.findByPot(new Vector2(rect.x + rect.width * 1.5f, rect.y + rect.height * 1.5f));
            node_0300 = root.findByPot(new Vector2(rect.x + rect.width * 1.5f, rect.y + rect.height * .5f));
            node_0430 = root.findByPot(new Vector2(rect.x + rect.width * 1.5f, rect.y - rect.height * .5f));

            node_0600 = root.findByPot(new Vector2(rect.x + rect.width * .5f, rect.y - rect.height * .5f));
            node_0730 = root.findByPot(new Vector2(rect.x - rect.width * .5f, rect.y - rect.height * .5f));
            node_0900 = root.findByPot(new Vector2(rect.x - rect.width * .5f, rect.y + rect.height * .5f));
            node_1030 = root.findByPot(new Vector2(rect.x - rect.width * .5f, rect.y + rect.height * 1.5f));
        }