chenxin
2020-10-30 716a9646286c6a571966b8ab2af37d57ea7a4af8
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
105
106
107
108
109
110
111
112
113
114
using Core.Utilities;
using DG.Tweening;
using System;
using System.Collections;
using System.Collections.Generic;
using TMPro;
using TowerDefense.UI.HUD;
using UnityEngine;
using UnityEngine.UI;
 
public class TextMoveDoTween : MonoBehaviour
{
    public TextMeshProUGUI bloodText;
 
    // Start is called before the first frame update
    void Start()
    {
 
    }
 
    // Update is called once per frame
    void Update()
    {
    }
 
    /// <summary>
    /// 当前的
    /// </summary>
    /// <param name="x"></param>
    /// <param name="y"></param>
    /// <param name="text"></param>
    public void moveBloodText( float x,float y,string text,bool crit = false )
    {
        // 先设置Text的位置到一个标准位置
        Vector3 pos = bloodText.transform.position;
        pos.x = x;
        pos.y = y;
        pos.z = 0;
        bloodText.transform.position = pos;
 
        Vector3 sval = bloodText.transform.localScale;
        sval.x = 1.0f;
        sval.y = 1.0f;
        sval.z = 1.0f;
        bloodText.transform.localScale = sval;
 
        bloodText.text = text;
        this.TextMove(bloodText,crit );
    }
 
    /// <summary>
    /// 清空当前的DoTweenMove数据并把数据放到Pool中.
    /// </summary>
    protected void Remove()
    {
        Poolable.TryPool(gameObject);
    }
 
    private void TextMove( Graphic graphic,bool crit = false )
    {
        //获得Text的rectTransform,和颜色,并设置颜色微透明
        RectTransform rect = graphic.rectTransform;
 
        Color color = graphic.color;
 
        graphic.color = new Color(color.r, color.g, color.b, 0);
 
        //设置一个DOTween队列
        Sequence textMoveSequence = DOTween.Sequence();
 
        System.Random rd = new System.Random();
 
 
        //设置Text移动和透明度的变化值\
        float baseTime = 0.3f;
        if (crit)
            baseTime = 0.2f;
        float scaleUp = 1.8f;
        if (crit)
            scaleUp = 2.2f;
        float scaleVec = Screen.height / 2400f;
        int basey = rd.Next( (int)(100*scaleVec),(int)(180*scaleVec) );
        if( crit )
            basey = rd.Next((int)(150 * scaleVec), (int)(210 * scaleVec));
 
        int basex;
        if (crit)
            basex = rd.Next(-30, 30);
        else
            basex = rd.Next(35, 55);
 
        Tweener textMove01 = rect.DOMoveY(rect.position.y + basey, baseTime);
        Tweener textMovex = rect.DOMoveX(rect.position.x + basex, baseTime);
        Tweener textMove02 = rect.DOMoveY(rect.position.y + basey + (int)(60*scaleVec), baseTime);
        Tweener textColor01 = graphic.DOColor(new Color(color.r, color.g, color.b, 1), baseTime);
        Tweener textColor02 = graphic.DOColor(new Color(color.r, color.g, color.b, 0), baseTime);
        Tweener textScale = rect.DOScale(scaleUp, 0.25f);
 
        //Append 追加一个队列,Join 添加一个队列
        //中间间隔一秒
        //Append 再追加一个队列,再Join 添加一个队列
        textMoveSequence.Append(textMove01);
        textMoveSequence.Join(textMovex);
        textMoveSequence.Join(textColor01);
        // 中断一下.   
        textMoveSequence.AppendInterval(0.3f + (float)rd.NextDouble() * 0.3f);
        // 向上变大淡出
        textMoveSequence.Append(textMove02);
        textMoveSequence.Join(textColor02);
        textMoveSequence.Join(textScale);
        textMoveSequence.AppendCallback(Remove);
        
    }
}