You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
131 lines
3.7 KiB
131 lines
3.7 KiB
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
/// <summary>
|
|
/// 交通灯功能设置
|
|
/// </summary>
|
|
public class TraficLightSet : MonoBehaviour
|
|
{
|
|
|
|
public Sprite upTImg, downTImg, leftTImg, rightTImg,crossRoadImg;
|
|
|
|
public TraficTimeSet upSet, downSet, leftSet, rightSet;
|
|
[Header("UI组件")]
|
|
public Button setOverBtn;
|
|
public Image roadBGImg;
|
|
|
|
|
|
private TraficLightPut currentPut;
|
|
|
|
private void Start()
|
|
{
|
|
setOverBtn.onClick.AddListener(CheckSet);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 检查设置是否完成
|
|
/// </summary>
|
|
private void CheckSet()
|
|
{
|
|
|
|
PutTraficLight();
|
|
this.gameObject.SetActive(false);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 放置红绿灯模型和UI
|
|
/// </summary>
|
|
private void PutTraficLight()
|
|
{
|
|
switch (currentPut.traficType)
|
|
{
|
|
case TraficRoadType.十:
|
|
|
|
int num = 4;
|
|
GameObject[] group = new GameObject[num];
|
|
TraficLightUI[] uiGroup = new TraficLightUI[num];
|
|
for (int i = 0; i < num; i++)
|
|
{
|
|
GameObject go = new GameObject();
|
|
group[i] = go;
|
|
GameObject ui = GameObject.Instantiate(Resources.Load<GameObject>("Prefab/TraficLightUI"));
|
|
uiGroup[i] = ui.GetComponent<TraficLightUI>();
|
|
}
|
|
group[0].transform.position = currentPut.upPoint.position;
|
|
group[1].transform.position = currentPut.downPoint.position;
|
|
group[2].transform.position = currentPut.leftPoint.position;
|
|
group[3].transform.position = currentPut.rightPoint.position;
|
|
|
|
float random = Random.Range(0f, 1f);
|
|
bool isGreen = random > 0.5f ? true : false;
|
|
uiGroup[0].Init(isGreen,upSet, currentPut.upPoint,LightDir.up, uiGroup[2]);//上
|
|
uiGroup[1].Init(isGreen, downSet, currentPut.downPoint,LightDir.down, uiGroup[3]);//下
|
|
uiGroup[2].Init(!isGreen, leftSet, currentPut.leftPoint,LightDir.left, uiGroup[0]);//左
|
|
uiGroup[3].Init(!isGreen, rightSet, currentPut.rightPoint,LightDir.right, uiGroup[1]);//右
|
|
|
|
|
|
break;
|
|
case TraficRoadType.leftT:
|
|
|
|
break;
|
|
case TraficRoadType.rightT:
|
|
|
|
break;
|
|
case TraficRoadType.upT:
|
|
|
|
break;
|
|
case TraficRoadType.downT:
|
|
|
|
break;
|
|
}
|
|
|
|
}
|
|
|
|
public void ShowTraficSetPanel(TraficRoadType type,TraficLightPut put)
|
|
{
|
|
|
|
|
|
switch (type)
|
|
{
|
|
case TraficRoadType.十:
|
|
upSet.gameObject.SetActive(true);
|
|
downSet.gameObject.SetActive(true);
|
|
leftSet.gameObject.SetActive(true);
|
|
rightSet.gameObject.SetActive(true);
|
|
|
|
upSet.SetPaterner(downSet);
|
|
leftSet.SetPaterner(rightSet);
|
|
//道路背景图设置
|
|
roadBGImg.sprite = crossRoadImg;
|
|
break;
|
|
case TraficRoadType.leftT:
|
|
|
|
break;
|
|
case TraficRoadType.rightT:
|
|
|
|
break;
|
|
case TraficRoadType.upT:
|
|
|
|
break;
|
|
case TraficRoadType.downT:
|
|
|
|
upSet.gameObject.SetActive(false);
|
|
downSet.gameObject.SetActive(true);
|
|
leftSet.gameObject.SetActive(true);
|
|
rightSet.gameObject.SetActive(true);
|
|
|
|
|
|
leftSet.SetPaterner(rightSet);
|
|
//道路背景图设置
|
|
roadBGImg.sprite = downTImg;
|
|
break;
|
|
}
|
|
|
|
this.gameObject.SetActive(true);
|
|
|
|
currentPut = put;
|
|
|
|
}
|
|
}
|