172 lines
5.1 KiB
C#
172 lines
5.1 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
/// <summary>
|
|
/// 设置联动/设置一键模式
|
|
/// </summary>
|
|
public class Control_Linkage : MonoBehaviour
|
|
{
|
|
/// <summary>
|
|
/// 打开电视时联动
|
|
/// </summary>
|
|
public List<string> OpenTV = new List<string>();
|
|
/// <summary>
|
|
/// 关闭电视时联动
|
|
/// </summary>
|
|
public List<string> CloseTV = new List<string>();
|
|
/// <summary>
|
|
/// 打开空调时联动
|
|
/// </summary>
|
|
public List<string> OpenAir = new List<string>();
|
|
/// <summary>
|
|
/// 关闭空调时联动
|
|
/// </summary>
|
|
public List<string> CloseAir = new List<string>();
|
|
/// <summary>
|
|
/// 保存选择
|
|
/// </summary>
|
|
public Button Enter;
|
|
/// <summary>
|
|
/// 选择条件
|
|
/// </summary>
|
|
public TMP_Dropdown Choosecondition;
|
|
/// <summary>
|
|
/// 选择结果
|
|
/// </summary>
|
|
public TMP_Dropdown Chooseoutcome;
|
|
/// <summary>
|
|
/// 输入的名称
|
|
/// </summary>
|
|
public TMP_InputField InputName;
|
|
/// <summary>
|
|
/// 设置面板
|
|
/// </summary>
|
|
public GameObject SetPanel;
|
|
/// <summary>
|
|
/// 保存后显示的面板
|
|
/// </summary>
|
|
public GameObject ClickPanel;
|
|
/// <summary>
|
|
/// 克隆的按钮
|
|
/// </summary>
|
|
public GameObject CloneButton;
|
|
/// <summary>
|
|
/// 克隆的父物体
|
|
/// </summary>
|
|
public Transform CloneParent;
|
|
/// <summary>
|
|
/// 返回按钮
|
|
/// </summary>
|
|
public GameObject Backbt;
|
|
/// <summary>
|
|
/// 创建数量上限提示
|
|
/// </summary>
|
|
public GameObject Tips;
|
|
/// <summary>
|
|
/// 离家
|
|
/// </summary>
|
|
public Button LeftHome;
|
|
/// <summary>
|
|
/// 回家
|
|
/// </summary>
|
|
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<TMP_Dropdown.OptionData>();
|
|
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<TextMeshProUGUI>().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<TextMeshProUGUI>().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<TextMeshProUGUI>().text = InputName.text;
|
|
go.SetActive(true);
|
|
SetPanel.SetActive(false);
|
|
ClickPanel.SetActive(true);
|
|
}
|
|
else
|
|
{
|
|
Tips.GetComponentInChildren<TextMeshProUGUI>().text = "输入的名称为空、重复或创建的联动与已创建的联动相同,请修改!";
|
|
StartCoroutine(WaitHide());
|
|
}
|
|
}
|
|
|
|
IEnumerator WaitHide()
|
|
{
|
|
Tips.SetActive(true);
|
|
yield return new WaitForSeconds(1.5f);
|
|
Tips.SetActive(false);
|
|
}
|
|
}
|