Files
3d-fengji/Assets/Scripts/Sluices/OneKeyOperation.cs
2026-05-20 17:05:47 +08:00

64 lines
1.6 KiB
C#

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;
}
}