using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; namespace BuildSystem { public class SetPanel : MonoBehaviour { GridUI grid; PlaceObject_SO placeObject; public Image img; public Transform road; public Transform[] dir; public GameObject cansetPre; public GameObject notsetPre; public GameObject roadPre; public Button close; public Button sure; private void Awake() { close.onClick.AddListener(() => { gameObject.SetActive(false); }); sure.onClick.AddListener(SetData); } public void Init(GridUI grid,PlaceObject_SO placeObject_SO,Sprite sprite) { this.grid = grid; placeObject = placeObject_SO; this.img.sprite = sprite; CreatePanel(); } void CreatePanel() { // int i = 1; foreach (object[] r in placeObject.roadGoInfo) { //判断该车道是否存在 bool flag = false; foreach (object o in r) { if (o != null) { flag = true; break; } } //对存在车道的道路进行ui创建 if (flag) { GameObject text = Instantiate(roadPre, road); text.GetComponent().text = i.ToString(); for (int l=0;l().isOn = isCanStraight; } //奇数 左右 if (l % 2 != 0) { if (r[l] == null) { Instantiate(notsetPre, dir[l]); } else { GameObject toggle = Instantiate(cansetPre, dir[l]); toggle.GetComponent().isOn = (bool)r[l]; } } } i++; } } } void SetData() { int i = 0; foreach (object[] r in placeObject.roadGoInfo) { //判断车道是否存在 bool flag = false; foreach (object o in r) { if (o != null) { flag = true; break; } } if (flag) { for (int d = 0;d < 4;d++) { //对左右进行数据写入 if (d % 2 != 0) { if (dir[d].GetChild(i).GetComponent()) { r[d] = dir[d].GetChild(i).GetComponent().isOn; } else { r[d] = null; } } //对上下数据进行写入 else { if (r[d] != null) { r[d] = dir[0].GetChild(i).GetComponent().isOn; } } } i++; } } grid.SetData(placeObject.roadGoInfo); } private void OnDisable() { //清空之前设置的显示 for (int t = 0; t < road.childCount; t++) { Destroy(road.GetChild(t).gameObject); } foreach (Transform trans in dir) { for (int t = 0; t < trans.childCount; t++) { Destroy(trans.GetChild(t).gameObject); } } } } }