using System.Collections; using System.Collections.Generic; using TMPro; using Unity.VisualScripting.Antlr3.Runtime; using UnityEngine; using UnityEngine.UI; /// /// 控制窗户 /// public class Control_Windows : MonoBehaviour { public static Control_Windows Instance; /// /// 开/关窗户 /// //public Button openwindows; /// /// 点击的窗户 /// public Transform window; public Toggle open; public Toggle close; private void Awake() { Instance = this; } void Start() { //openwindows.onClick.AddListener(() => { Openwindows(); }); } // Update is called once per frame void Update() { if (SelectModel.Instance.region != Region.None && window == null) { switch (SelectModel.Instance.region) { case Region.环境控制: window = Furniture_Manager.Instance.FindHome("环境", "窗户"); break; case Region.设备互联与系统控制: window = Furniture_Manager.Instance.FindHome("互联", "窗户"); break; case Region.智能家电与维护: window = Furniture_Manager.Instance.FindHome("家电", "窗户"); break; } } if (window != null) { if (window.GetComponent().GetBlendShapeWeight(0) == 0 || window.GetComponent().GetBlendShapeWeight(0) == 100) { open.interactable = true; close.interactable = true; } } } public void AudiosTalk(string Talk) { if (Talk.Contains("开窗户")) { open.isOn = true; Openwindows(true); } else if (Talk.Contains("关窗户")) { close.isOn = true; Openwindows(false); } } public void Openwindows(bool isopen) { open.interactable = false; close.interactable = false; StartCoroutine(Openwindow(isopen)); } /// /// 开关窗户 /// /// IEnumerator Openwindow(bool isopen) { if (window.GetComponent().GetBlendShapeWeight(0) == 0 && isopen) { //openwindows.GetComponentInChildren().text = "关窗"; for (int i = 1; i < 101; i++) { window.GetComponent().SetBlendShapeWeight(0, i); yield return new WaitForSeconds(0.025f); } } else if (window.GetComponent().GetBlendShapeWeight(0) == 100 && !isopen) { //openwindows.GetComponentInChildren().text = "开窗"; for (int i = 100; i >= 0; i--) { window.GetComponent().SetBlendShapeWeight(0, i); yield return new WaitForSeconds(0.025f); } } } }