yyl
2025-06-04 a7f4c5ecc5268c49f6a6caf769b3ebee6f237662
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
 
public class LoadingWin : UIBase
{
    protected int currentProgress = 0;
    protected int targetProgress = 0;
 
    protected Text titleText;
    protected Text tipsText;
    protected Image progressBar;
    protected Text progressText;
 
    protected override void InitComponent()
    {
        base.InitComponent();
        titleText = transform.Find("Text_Loading").GetComponent<Text>();
        tipsText = transform.Find("Text_Tips").GetComponent<Text>();
        progressBar = transform.Find("Img_Progress/Img_Foreground").GetComponent<Image>();
        progressText = transform.Find("Text_Progress").GetComponent<Text>();
    }
 
    protected override void OnPreOpen()
    {
        base.OnPreOpen();
        currentProgress = targetProgress = 0;
        Refresh();
    }
 
    protected override void OnPreClose()
    {
        base.OnPreClose();
    }
 
    public override void Refresh()
    {
        base.Refresh();
        UpdateProgress();
    }
 
    public void SetProgress(float value, bool directly = false)
    {
        if (directly)
        {
            currentProgress = targetProgress = (int)(value * 100);
            UpdateProgress();
        }
        else
        {
            currentProgress = (int)(value * 100);
        }
 
        
    }
 
    protected void UpdateProgress()
    {
        progressText.text = currentProgress + "%";
        progressBar.fillAmount = currentProgress / 100f;
    }
 
    protected void Update()
    {
        if (currentProgress < targetProgress)
        {
            currentProgress = (int)Mathf.Lerp(currentProgress, targetProgress, 0.1f);
            UpdateProgress();
        }
    }
}