少年修仙传客户端代码仓库
client_Wu Xijin
2019-06-13 033958214c0b16d7e7b93cc821b018c295251867
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
//--------------------------------------------------------
//    [Author]:           第二世界
//    [  Date ]:           Tuesday, July 24, 2018
//--------------------------------------------------------
 
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
 
namespace Snxxz.UI {
 
    public class ChatFloatWin : Window
    {
        [SerializeField] RectTransform m_ContainerFloat;
        [SerializeField] RichText m_Chat;
        [SerializeField] CanvasGroup canvasGroup;
 
        DateTime overdueTime = DateTime.Now;
 
        Coroutine cacheCoroutine;
        #region Built-in
        protected override void BindController()
        {
 
        }
 
        protected override void AddListeners()
        {
        }
 
        protected override void OnPreOpen()
        {
            m_ContainerFloat.gameObject.SetActive(false);
            ChatCtrl.Inst.chatFloatUpdate += ChatFloatUpdate;
        }
 
        protected override void OnAfterOpen()
        {
        }
 
        protected override void OnPreClose()
        {
            ChatCtrl.Inst.chatFloatUpdate -= ChatFloatUpdate;
            if (cacheCoroutine != null)
            {
                StopCoroutine(cacheCoroutine);
                cacheCoroutine = null;
            }
        }
 
        protected override void OnAfterClose()
        {
        }
        #endregion
 
        protected override void LateUpdate()
        {
            base.LateUpdate();
            if (DateTime.Now > overdueTime && m_ContainerFloat.gameObject.activeSelf)
            {
                m_ContainerFloat.gameObject.SetActive(false);
            }
        }
 
        private void ChatFloatUpdate(ChatData data)
        {
            if (cacheCoroutine != null)
            {
                StopCoroutine(cacheCoroutine);
                cacheCoroutine = null;
            }
            if (data == null)
            {
                return;
            }
            if (string.IsNullOrEmpty(data.content))
            {
                return;
            }
            switch (data.type)
            {
                case ChatInfoType.Friend:
                case ChatInfoType.FairyQuestion:
                case ChatInfoType.FairyTip:
                case ChatInfoType.TeamTip:
                    return;
            }
            m_ContainerFloat.gameObject.SetActive(true);
            canvasGroup.alpha = 0;
            m_Chat.text = string.Empty;
            overdueTime = DateTime.Now.AddTicks(3 * TimeSpan.TicksPerSecond);
            if (data.infoList != null)
            {
                m_Chat.SetExtenalData(data.infoList);
            }
            cacheCoroutine = StartCoroutine(Co_SetText(StringUtility.Contact(SetChatExtraInfo(data), data.content)));
        }
 
        IEnumerator Co_SetText(string value)
        {
            yield return null;
            m_Chat.text = value;
            canvasGroup.alpha = 1;
            if (m_Chat.preferredWidth >= 1000)
            {
                m_Chat.alignment = TextAnchor.MiddleLeft;
            }
            else
            {
                m_Chat.alignment = TextAnchor.MiddleCenter;
            }
        }
 
        string SetChatExtraInfo(ChatData data)
        {
            switch (data.type)
            {
                case ChatInfoType.World:
                    {
                        return string.Format("<Img chat={0}/> <color=#109d06>{1}</color>: ", "ChatIcon_World", (data as ChatUeseData).name);
                    }
                case ChatInfoType.Area:
                    return string.Format("<Img chat={0}/> <color=#109d06>{1}</color>: ", "ChatIcon_Area", (data as ChatUeseData).name);
                case ChatInfoType.CrossServer:
                    return string.Format("<Img chat={0}/> <color=#109d06>{1}</color>: ", "ChatIcon_CrossServer", (data as ChatUeseData).name);
                case ChatInfoType.Team:
                    {
                        string playerName = (data as ChatUeseData).name;
                        return string.Format("<Img chat={0}/> <color=#109d06>{1}</color>", "ChatIcon_Team", playerName + (playerName != string.Empty ? ": " : string.Empty));
                    }
                case ChatInfoType.Friend:
                    break;
                case ChatInfoType.Fairy:
                    {
                        string playerName = (data as ChatUeseData).name;
                        return string.Format("<Img chat={0}/> <color=#109d06>{1}</color>", "ChatIcon_Fairy", playerName + (playerName != string.Empty ? ": " : string.Empty));
                    }
                case ChatInfoType.Trumpet:
                    return string.Format("<Img chat={0}/> <color=#109d06>{1}</color>: ", "ChatIcon_Trumpet", (data as ChatTrumpetData).name);
                case ChatInfoType.Invite:
                    return string.Format("<Img chat={0}/> ", "ChatIcon_Invite");
                case ChatInfoType.System:
                    return string.Format("<Img chat={0}/> ", "ChatIcon_System");
            }
            return string.Empty;
        }
    }
 
}