少年修仙传客户端代码仓库
client_linchunjie
2019-04-17 f1f2599ba0e6b64358ffef7ae5c9f9af3ed8b8b4
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
//--------------------------------------------------------
//    [Author]:           第二世界
//    [  Date ]:           Tuesday, April 10, 2018
//--------------------------------------------------------
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
 
namespace Snxxz.UI
{
 
    public class UGUITypewriter : MonoBehaviour
    {
        [SerializeField] Text m_text;
        public float SPEED = 0.1f;
        private float fSpeed = 0.1f;
        string sContent=string.Empty;
        //void Start()
        //{
        //    SetContent();
        //}
        public void SetContent()
        {
            fSpeed = SPEED;
            sContent = m_text.text;
            curPos = 0;
            fDelta = 0;
        }
 
        float fDelta;
        int curPos = -1;
        private void LateUpdate()
        {
            if (string.IsNullOrEmpty(sContent) && string.IsNullOrEmpty(m_text.text))
            {
                return;
            }
            if (!sContent.Contains(m_text.text))
            {
                SetContent();
                return;
            }
            if (curPos == sContent.Length)
            {
                return;
            }
            fDelta += Time.deltaTime;
            if (fDelta < fSpeed)
            {
                return;
            }
            fDelta -= fSpeed;
 
            curPos++;
            m_text.text = sContent.Substring(0, curPos);
 
        }
        public bool IsNext()
        {
            if (string.IsNullOrEmpty(sContent) && string.IsNullOrEmpty(m_text.text))
            {
                return true;
            }
            else if (curPos == sContent.Length)
            {
                return true;
            }
            else
            {
                fSpeed = 0;
                return false;
            }
        }
    }
 
}