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