wangguan
2020-11-17 7ab9310ebe5ca5449ed7dca56d8383846393c2f1
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
92
93
94
95
96
97
98
99
100
101
102
103
104
using DG.Tweening;
using Protobuf;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
 
/// <summary>
/// 子弹充能对应的数据结构.
/// </summary>
public class BulletUICtl : MonoBehaviour
{
    public SpriteRenderer bulletScaleMask;
 
    public float fAdjValue;
 
    /// <summary>
    /// 最大子弹数目.
    /// </summary>
    public int maxBulletNum;
 
    /// <summary>
    /// 当前的子弹数目.
    /// </summary>
    protected int curBulletNum;
 
    private float[] scaleArr = { 0, 0.16f, 0.32f, 0.48f, 0.64f, 0.8f, 1f };
 
    private float[] yArr = { 0.4f, 0.377f, 0.307f, 0.227f, 0.153f, 0.074f, 0 };
 
    private float gap = 0.15f;
 
    // Start is called before the first frame update
    void Start()
    {
        resetToMaxBullet();
    }
 
 
    /// <summary>
    /// 获取进度条进度.
    /// </summary>
    /// <returns></returns>
    public int GetCtlProgress()
    {
        return this.curBulletNum;
    }
 
    /// <summary>
    /// 设置进度.
    /// </summary>
    /// <param name="pro"></param>
    public void SetCtlProcess( int pro)
    {
        this.curBulletNum = pro;
        this.updateBulletUI(pro, maxBulletNum);
    }
 
    /// <summary>
    /// 重设子弹数目到最大.
    /// </summary>
    public void resetToMaxBullet()
    {
        if (this.curBulletNum == maxBulletNum) return;
    
        this.curBulletNum = maxBulletNum;
        this.updateBulletUI(curBulletNum, maxBulletNum);
    }
 
    /// <summary>
    /// 减少子弹,返回减少后的子弹数目。
    /// </summary>
    /// <returns></returns>
    public int decBullet()
    {
        if (this.curBulletNum <= 0) return 0;
        this.curBulletNum--;
        this.updateBulletUI(curBulletNum, maxBulletNum);
        return curBulletNum;
    }
 
    /// <summary>
    /// 更新子弹界面对应的缩放信息
    /// </summary>
    /// <param name="curBNum"></param>
    /// <param name="totalBNum"></param>
    public void updateBulletUI( int curBNum,int totalBNum)
    {
        if (bulletScaleMask == null) return;
 
        Vector3 pos = bulletScaleMask.transform.localPosition;
        pos.y = yArr[maxBulletNum - curBulletNum];
        bulletScaleMask.transform.localPosition = pos;
        Vector3 s = bulletScaleMask.transform.localScale;
        s.y = scaleArr[maxBulletNum - curBulletNum];
        bulletScaleMask.transform.localScale = s;
    }
 
    // Update is called once per frame
    void Update()
    {
 
    }
}