using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
///
/// 打开窗帘/窗户
///
public class Control_Curtain : MonoBehaviour
{
public static Control_Curtain Instance;
///
/// 开/关窗帘
///
public Button opencurtain;
///
/// 点击的窗帘
///
public Transform curtain;
public Toggle Open;
public Toggle Close;
private void Awake()
{
Instance = this;
}
void Start()
{
//opencurtain.onClick.AddListener(() =>
//{
// Opencurtains();
//});
}
private void Update()
{
if (SelectModel.Instance.region != Region.None && curtain == null)
{
switch (SelectModel.Instance.region)
{
case Region.环境控制:
curtain = Furniture_Manager.Instance.FindHome("环境", "窗帘");
break;
case Region.设备互联与系统控制:
curtain = Furniture_Manager.Instance.FindHome("互联", "窗帘");
break;
case Region.智能家电与维护:
curtain = Furniture_Manager.Instance.FindHome("家电", "窗帘");
break;
}
}
//如果没在播放动画 则可以继续点击按钮
if (curtain != null && !curtain.GetComponent().isPlaying)
{
Open.interactable = true;
Close.interactable = true;
}
}
public void AudiosTalk(string Talk)
{
if (Talk.Contains("开窗帘"))
{
Open.isOn = true;
Opencurtains(true);
}
else if (Talk.Contains("关窗帘"))
{
Open.isOn = false;
Opencurtains(false);
}
}
public void Opencurtains(bool isopen)
{
Open.interactable = false;
Close.interactable = false;
Opencurtain(isopen);
}
///
/// 开关窗帘
///
///
void Opencurtain(bool isopen)
{
if (curtain.GetComponent().GetBlendShapeWeight(0) == 0&& !isopen)
{
curtain.GetComponent().Play("窗帘开");
}
else if (curtain.GetComponent().GetBlendShapeWeight(0) == 100&& isopen)
{
curtain.GetComponent().Play("窗帘关");
}
}
}