using System.Collections;
using System.Collections.Generic;
using TMPro;
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 (window != null )
{
if (window.GetComponent().GetBlendShapeWeight(0) == 0 || window.GetComponent().GetBlendShapeWeight(0) == 100)
{
open.interactable = true;
close.interactable = true;
}
}
}
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);
}
}
}
}