105 lines
3.1 KiB
C#
105 lines
3.1 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using Unity.VisualScripting.Antlr3.Runtime;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
/// <summary>
|
|
/// 控制窗户
|
|
/// </summary>
|
|
public class Control_Windows : MonoBehaviour
|
|
{
|
|
public static Control_Windows Instance;
|
|
/// <summary>
|
|
/// 开/关窗户
|
|
/// </summary>
|
|
//public Button openwindows;
|
|
/// <summary>
|
|
/// 点击的窗户
|
|
/// </summary>
|
|
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<SkinnedMeshRenderer>().GetBlendShapeWeight(0) == 0 || window.GetComponent<SkinnedMeshRenderer>().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));
|
|
}
|
|
/// <summary>
|
|
/// 开关窗户
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
IEnumerator Openwindow(bool isopen)
|
|
{
|
|
|
|
if (window.GetComponent<SkinnedMeshRenderer>().GetBlendShapeWeight(0) == 0 && isopen)
|
|
{
|
|
//openwindows.GetComponentInChildren<TextMeshProUGUI>().text = "关窗";
|
|
for (int i = 1; i < 101; i++)
|
|
{
|
|
window.GetComponent<SkinnedMeshRenderer>().SetBlendShapeWeight(0, i);
|
|
yield return new WaitForSeconds(0.025f);
|
|
}
|
|
}
|
|
else if (window.GetComponent<SkinnedMeshRenderer>().GetBlendShapeWeight(0) == 100 && !isopen)
|
|
{
|
|
//openwindows.GetComponentInChildren<TextMeshProUGUI>().text = "开窗";
|
|
for (int i = 100; i >= 0; i--)
|
|
{
|
|
window.GetComponent<SkinnedMeshRenderer>().SetBlendShapeWeight(0, i);
|
|
yield return new WaitForSeconds(0.025f);
|
|
}
|
|
}
|
|
}
|
|
}
|