chenxin
2020-12-11 c1ef6cbe7088df7eb236272db0621d5f51c02e5f
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
using DG.Tweening;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
 
public class EnergyUICtl : MonoBehaviour
{
    /// <summary>
    /// 用于显示能量条进度
    /// </summary>
    public Image energyScaleMask;
 
    /// <summary>
    /// 充能条满后,在场景内播放的特效
    /// </summary>
    public GameObject energyEffPrefab;
 
    /// <summary>
    /// 当前的能量条进度.10份进度.
    /// </summary>
    protected int currentProgress;
 
    protected Vector3 vec3EffectPlay;
 
    // Start is called before the first frame update
    void Start()
    {
        currentProgress = 0;
        //this.SetEnergyProgress(0);
    }
 
    /// <summary>
    /// 设置要播放特效的位置信息.
    /// </summary>
    /// <param name="vec"></param>
    public void SetEffectPlayPos( Vector3 vec)
    {
        vec3EffectPlay.x = vec.x;
        vec3EffectPlay.y = vec.y;
        vec3EffectPlay.z = vec.z;
    }
 
    /// <summary>
    /// 获取进度条进度.
    /// </summary>
    /// <returns></returns>
    public int GetCtlProgress()
    {
        return currentProgress;
    }
 
    /// <summary>
    /// 设置进度.
    /// </summary>
    /// <param name="pro"></param>
    public void SetCtlProcess(int pro)
    {
        if (pro == 10)
            pro = 0;
        energyScaleMask.rectTransform.DOKill();
        this.SetEnergyProgress(pro,false);
    }
 
    /// <summary>
    /// 显示并更新能量条进度.
    /// </summary>
    /// <param name="pro"></param>
    public void SetEnergyProgress(int pro,bool ani = true)
    {
        if (pro == currentProgress) return;
 
        if( ani )
            energyScaleMask.rectTransform.DOScaleY( pro / 10.0f, 0.3f );
        else
            energyScaleMask.rectTransform.DOScaleY(pro / 10.0f, 0.0f);
        currentProgress = pro;
    }
 
    public void SetEnergyProcessFloat( float fpro)
    {
        energyScaleMask.rectTransform.DOScaleY(fpro / 10.0f, 0.0f);
        currentProgress = (int)Mathf.Floor(fpro);
    }
 
    // Update is called once per frame
    void Update()
    {
        
    }
}