Files
2026-07-10 10:24:29 +08:00

101 lines
2.7 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
namespace XGame
{
public class XProgress
{
Transform m_trLoading = null;
Slider m_Slider;
int m_Aim = 0;
int m_Cur = 0;
float m_fLastTime = 0;
//float m_fTimePerOne;
bool m_bShow = false;
public XProgress()
{
GameObject obj = GameObject.Find("Main");
Transform tr = obj.transform;
for (int i = 0; i < tr.childCount; ++i)
{
Transform child = tr.GetChild(i);
if (child.name == "Loading")
{
m_trLoading = child;
break;
}
}
m_trLoading.gameObject.SetActive(m_bShow);
if (m_trLoading != null)
{
for (int i = 0; i < m_trLoading.childCount; ++i)
{
Transform child = m_trLoading.GetChild(i);
m_Slider = child.GetComponent<Slider>();
if (m_Slider != null)
{
m_Slider.maxValue = 100;
m_Slider.minValue = 0;
break;
}
}
}
}
// Start is called before the first frame update
public void Show(bool bShow)
{
m_bShow = bShow;
}
public void ChangeSlider(Slider slider)
{
m_Slider = slider;
}
//1-100
public void Set(int percent)
{
if (!m_bShow)
return;
if (m_Cur == 0 && percent > 0)
{//µÚÒ»´Î
m_trLoading.gameObject.SetActive(true);
m_fLastTime = Time.realtimeSinceStartup;
//m_fTimePerOne = 0.1f;
m_Cur = 1;
}
else if (percent < m_Cur)
{
m_Cur = percent;
}
m_Aim = percent;
}
// Update is called once per frame
public void Update()
{
if (m_Cur >= 100)
{
m_trLoading.gameObject.SetActive(false);
m_Cur = 0;
m_Aim = 0;
}
else if (m_Aim > 0)
{//½øÐÐÖÐ
if (m_Aim > m_Cur)
{
if (m_Aim - m_Cur > 10)
m_Cur += (m_Aim - m_Cur)/10;
else
m_Cur++;
if (m_Slider != null)
{
m_Slider.value = m_Cur;
}
}
}
}
}
}