using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
///
/// 设置联动/设置一键模式
///
public class Control_Linkage : MonoBehaviour
{
///
/// 打开电视时联动
///
public List OpenTV = new List();
///
/// 关闭电视时联动
///
public List CloseTV = new List();
///
/// 打开空调时联动
///
public List OpenAir = new List();
///
/// 关闭空调时联动
///
public List CloseAir = new List();
///
/// 保存选择
///
public Button Enter;
///
/// 选择条件
///
public TMP_Dropdown Choosecondition;
///
/// 选择结果
///
public TMP_Dropdown Chooseoutcome;
///
/// 输入的名称
///
public TMP_InputField InputName;
///
/// 设置面板
///
public GameObject SetPanel;
///
/// 保存后显示的面板
///
public GameObject ClickPanel;
///
/// 克隆的按钮
///
public GameObject CloneButton;
///
/// 克隆的父物体
///
public Transform CloneParent;
///
/// 返回按钮
///
public GameObject Backbt;
///
/// 创建数量上限提示
///
public GameObject Tips;
///
/// 离家
///
public Button LeftHome;
///
/// 回家
///
public Button GoHome;
void Start()
{
LeftHome.onClick.AddListener(() =>
{
LeftHome.interactable = false;
GoHome.interactable = false;
Control_Air.Instance.AudiosTalk("关空调");
Control_Windows.Instance.AudiosTalk("开窗户");
Control_Curtain.Instance.AudiosTalk("关窗帘");
StartCoroutine(WiatClick());
});
GoHome.onClick.AddListener(() =>
{
LeftHome.interactable = false;
GoHome.interactable = false;
Control_Air.Instance.AudiosTalk("开空调");
Control_Windows.Instance.AudiosTalk("关窗户");
Control_Curtain.Instance.AudiosTalk("开窗帘");
StartCoroutine(WiatClick());
});
InputName.characterLimit = 6;
Chooseoutcome.AddOptions(OpenAir);
Choosecondition.onValueChanged.AddListener((value) =>
{
Chooseoutcome.options = new List();
switch (Choosecondition.captionText.text)
{
case "开空调":
Chooseoutcome.AddOptions(OpenAir);
break;
case "关空调":
Chooseoutcome.AddOptions(CloseAir);
break;
case "开电视":
Chooseoutcome.AddOptions(OpenTV);
break;
case "关电视":
Chooseoutcome.AddOptions(CloseTV);
break;
}
});
Enter.onClick.AddListener(() =>
{
if (CloneParent.childCount > 7)
{
Tips.GetComponentInChildren().text = "创建联动数量超过上限,请删除";
StartCoroutine(WaitHide());
}
else
{
EnterChoose();
}
});
}
IEnumerator WiatClick()
{
yield return new WaitForSeconds(2.5f);
LeftHome.interactable = true;
GoHome.interactable = true;
}
public void EnterChoose()
{
bool issame = false;
for (int i = 0; i < CloneParent.childCount; i++)
{
if (CloneParent.GetChild(i).name == Choosecondition.captionText.text + "|" + Chooseoutcome.captionText.text
|| CloneParent.GetChild(i).GetChild(0).GetComponent().text == InputName.text
|| InputName.text == "")
{
issame = true;
}
}
if (!issame)
{
Backbt.SetActive(true);
GameObject go = Instantiate(CloneButton, CloneParent.transform);
go.name = Choosecondition.captionText.text + "|" + Chooseoutcome.captionText.text;
go.GetComponentInChildren().text = InputName.text;
go.SetActive(true);
SetPanel.SetActive(false);
ClickPanel.SetActive(true);
}
else
{
Tips.GetComponentInChildren().text = "输入的名称为空、重复或创建的联动与已创建的联动相同,请修改!";
StartCoroutine(WaitHide());
}
}
IEnumerator WaitHide()
{
Tips.SetActive(true);
yield return new WaitForSeconds(1.5f);
Tips.SetActive(false);
}
}