fix:风机初始化代码提交
This commit is contained in:
63
Assets/Scripts/Sluices/OneKeyOperation.cs
Normal file
63
Assets/Scripts/Sluices/OneKeyOperation.cs
Normal file
@@ -0,0 +1,63 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class OneKeyOperation : MonoBehaviour
|
||||
{
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
public void AllOpen()
|
||||
{
|
||||
foreach(Transform child in transform.Find("Sliders").transform)
|
||||
{
|
||||
StartCoroutine(SmoothIncreaseToTwo(0.3f, child));
|
||||
}
|
||||
|
||||
}
|
||||
public void AllClose()
|
||||
{
|
||||
foreach (Transform child in transform.Find("Sliders").transform)
|
||||
{
|
||||
StartCoroutine(SmoothDecreaseToZero(0.3f, child));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
IEnumerator SmoothDecreaseToZero(float duration,Transform child )
|
||||
{
|
||||
float startValue = child.GetComponent<Slider>().value;
|
||||
float time = 0f;
|
||||
while (time < duration)
|
||||
{
|
||||
time += Time.deltaTime;
|
||||
startValue = Mathf.Lerp(startValue, 0f, time / duration);
|
||||
child.GetComponent<Slider>().value = startValue;
|
||||
yield return null;
|
||||
}
|
||||
child.GetComponent<Slider>().value = 0f;
|
||||
}
|
||||
|
||||
IEnumerator SmoothIncreaseToTwo(float duration, Transform child)
|
||||
{
|
||||
float startValue = child.GetComponent<Slider>().value;
|
||||
float time = 0f;
|
||||
while (time < duration)
|
||||
{
|
||||
time += Time.deltaTime;
|
||||
startValue = Mathf.Lerp(startValue, 2f, time / duration);
|
||||
child.GetComponent<Slider>().value = startValue;
|
||||
yield return null;
|
||||
}
|
||||
child.GetComponent<Slider>().value = 2f;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user