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); }
// 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(); }
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)); }