95 lines
2.4 KiB
C#
95 lines
2.4 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
/// <summary>
|
|
/// 打开窗帘/窗户
|
|
/// </summary>
|
|
public class Control_Curtain : MonoBehaviour
|
|
{
|
|
public static Control_Curtain Instance;
|
|
/// <summary>
|
|
/// 开/关窗帘
|
|
/// </summary>
|
|
public Button opencurtain;
|
|
/// <summary>
|
|
/// 点击的窗帘
|
|
/// </summary>
|
|
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<Animation>().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);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 开关窗帘
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
void Opencurtain(bool isopen)
|
|
{
|
|
if (curtain.GetComponent<SkinnedMeshRenderer>().GetBlendShapeWeight(0) == 0&& !isopen)
|
|
{
|
|
curtain.GetComponent<Animation>().Play("窗帘开");
|
|
}
|
|
else if (curtain.GetComponent<SkinnedMeshRenderer>().GetBlendShapeWeight(0) == 100&& isopen)
|
|
{
|
|
curtain.GetComponent<Animation>().Play("窗帘关");
|
|
}
|
|
}
|
|
|
|
}
|