//初始化地图 void Init() { List <List <bool> > mark = new List <List <bool> >(); //建立结点 for (int i = 0; i < layerCount; i++) { List <MapNode> floor = new List <MapNode>(); List <bool> floorMark = new List <bool>(); int num = Random.Range(2, 5); for (int j = 0; j < num; j++) { MapNode node = new MapNode(); node.layer = i; //node属性设置TODO NodeType nodeType = (NodeType)Random.Range(0, (int)NodeType.count); node.nodeType = nodeType; floor.Add(node); floorMark.Add(false); } map.Add(floor); mark.Add(floorMark); } //填充结点的子节点 for (int i = 0; i < layerCount - 1; i++) { List <MapNode> floor = map[i]; int childNum = map[i + 1].Count; List <bool> floorMark = mark[i + 1]; float stand = childNum / (floor.Count + 0.0f); for (int j = 0; j < floor.Count; j++) { MapNode node = new MapNode(); if (j == 0) { floor[j].child.Add(0); floorMark[0] = true; if (Random.Range(0.0f, 1.0f) >= 0.5) { floor[j].child.Add(1); floorMark[1] = true; } } else { if (j < childNum - 1) { if (Random.Range(0.0f, 1.0f) >= 0.5) { floor[j].child.Add(j); floorMark[j] = true; } if (Random.Range(0.0f, 1.0f) >= 0.5 && j < childNum - 2) { floor[j].child.Add(j + 1); floorMark[j + 1] = true; } if (!floorMark[j]) { if (floor[j].child.Count == 0) { floor[j].child.Add(j); floorMark[j] = true; } else if (Random.Range(0.0f, 1.0f) >= 0.5) { floor[j].child.Add(j - 1); floorMark[j - 1] = true; } } else { if (floor[j].child.Count == 0) { floor[j].child.Add(j); floorMark[j] = true; } } } else if (floorMark[childNum - 1]) { floor[j].child.Add(childNum - 1); floorMark[childNum - 1] = true; } else { if (Random.Range(0.0f, 1.0f) >= 0.5) { floor[j].child.Add(childNum - 2); floorMark[childNum - 2] = true; if (Random.Range(0.0f, 1.0f) >= 0.5) { floor[j].child.Add(childNum - 1); floorMark[childNum - 1] = true; } } else { floor[j].child.Add(childNum - 1); floorMark[childNum - 1] = true; } if (j == floor.Count - 1) { floor[floor.Count - 1].child.Add(childNum - 1); floorMark[childNum - 1] = true; } } for (int m = 0; m < childNum; m++) { if (!floorMark[m]) { if (m >= floor.Count) { floor[floor.Count - 1].child.Add(m); } else { floor[m].child.Add(m); } } } } } } //指向BOSS List <MapNode> floorTop = map[layerCount - 1]; for (int i = 0; i < floorTop.Count; i++) { floorTop[i].child.Add(0); } ///绘制 int length = 500 / layerCount; for (int i = 0; i < map.Count; i++) { Debug.Log("层"); for (int j = 0; j < map[i].Count; j++) { Debug.Log("节点"); int layerXNum = map[i].Count * -50 + 50; int layerYNum = 0; if (i == map.Count - 1) { layerYNum = 0; } else { layerYNum = map[i + 1].Count * -50 + 50; } MapNode mapNode = map[i][j]; Color color; if (mapNode.nodeType == NodeType.fight) { color = Color.green; } else if (mapNode.nodeType == NodeType.shop) { color = Color.blue; } else { color = Color.red; } ButtonEx button = CreatButton(new Vector2(layerXNum + 100 * j, -250 + length * i), new Vector2(20, 20), sprite, color); map[i][j].button = button; button.onClick.AddListener(delegate() { button.Exit(); this.buttonResponse(mapNode); }); if (i == 0) { mapNode.FatherIsPass = true; } //Button btn = new Button(); for (int m = 0; m < map[i][j].child.Count; m++) { Debug.Log(map[i][j].child[m]); int num = map[i][j].child[m]; mapLine li = new mapLine(); li.x = new Vector2(layerXNum + 100 * j, -250 + length * i); //if(i==map.Count-1) //li.y = new Vector2(0, -260 + length * (i+1)); //else li.y = new Vector2(layerYNum + 100 * num, -260 + length * (i + 1)); render.addLine(li); } } } }