summaryrefslogtreecommitdiff
path: root/Client/Assets/Scripts/XMainClient/XBubbleComponent.cs
blob: a2d7c7c1f47922f906d3f95f31ee16a404a53228 (plain)
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
using System;
using UILib;
using UnityEngine;
using XMainClient.UI;
using XMainClient.UI.UICommon;
using XUtliPoolLib;

namespace XMainClient
{
	internal class XBubbleComponent : XComponent
	{
		public override uint ID
		{
			get
			{
				return XBubbleComponent.uuID;
			}
		}

		private GameObject _billboard = null;

		private float _heroHeight = 0f;

		public static string BUBBLE_TEMPLATE = "UI/Billboard/Bubble";

		public new static readonly uint uuID = XSingleton<XCommon>.singleton.XHash("Bubble");

		private IXUILabelSymbol _text;

		private IXUILabel _label;

		private IXUISprite _board;

		private uint _timer = 0u;

		private XTimerMgr.ElapsedEventHandler _hideBubbleCb = null;

		private Transform mCameraTrans;

		private float mSrcDistance;

		public XBubbleComponent()
		{
			this._hideBubbleCb = new XTimerMgr.ElapsedEventHandler(this.HideBubble);
		}

		public override void OnAttachToHost(XObject host)
		{
			base.OnAttachToHost(host);
			this._billboard = XSingleton<XResourceLoaderMgr>.singleton.CreateFromPrefab(XBubbleComponent.BUBBLE_TEMPLATE, this._entity.EngineObject.Position, this._entity.EngineObject.Rotation, true, false);
			this._billboard.name = this._entity.ID.ToString();
			bool isNpc = this._entity.IsNpc;
			if (isNpc)
			{
				XSingleton<UiUtility>.singleton.AddChild(XSingleton<XGameUI>.singleton.NpcHpbarRoot.gameObject, this._billboard);
			}
			else
			{
				XSingleton<UiUtility>.singleton.AddChild(XSingleton<XGameUI>.singleton.HpbarRoot.gameObject, this._billboard);
			}
			float val = 0.9f;
			this._heroHeight = Math.Max(this._entity.Height, val);
			this._billboard.transform.localScale = new Vector3(0.01f * this._heroHeight / 1.5f, 0.01f * this._heroHeight / 1.5f, 0.01f * this._heroHeight / 1.5f);
			this._text = (this._billboard.transform.Find("chattext/text/content").GetComponent("XUILabelSymbol") as IXUILabelSymbol);
			this._label = (this._billboard.transform.Find("chattext/text/content").GetComponent("XUILabel") as IXUILabel);
			this._board = (this._billboard.transform.Find("chattext/text/content/board").GetComponent("XUISprite") as IXUISprite);
			this.mCameraTrans = XSingleton<XScene>.singleton.GameCamera.CameraTrans;
			this.mSrcDistance = 8f;
		}

		protected override void EventSubscribe()
		{
			base.RegisterEvent(XEventDefine.XEvent_Bubble, new XComponent.XEventHandler(this.ShowBubble));
		}

		public override void OnDetachFromHost()
		{
			bool flag = this._timer > 0u;
			if (flag)
			{
				XSingleton<XTimerMgr>.singleton.KillTimer(this._timer);
			}
			this.DestroyGameObjects();
			base.OnDetachFromHost();
		}

		protected void DestroyGameObjects()
		{
			XResourceLoaderMgr.SafeDestroy(ref this._billboard, true);
		}

		protected bool ShowBubble(XEventArgs e)
		{
			XBubbleEventArgs xbubbleEventArgs = e as XBubbleEventArgs;
			this._billboard.gameObject.SetActive(true);
			this._text.InputText = xbubbleEventArgs.bubbletext;
			DlgBase<XChatSmallView, XChatSmallBehaviour>.singleton.ShowCurrTempMsg(xbubbleEventArgs.bubbletext, xbubbleEventArgs.speaker);
			bool flag = this._timer > 0u;
			if (flag)
			{
				XSingleton<XTimerMgr>.singleton.KillTimer(this._timer);
			}
			this._timer = XSingleton<XTimerMgr>.singleton.SetTimer(xbubbleEventArgs.existtime, this._hideBubbleCb, null);
			return true;
		}

		protected void HideBubble(object o)
		{
			this._billboard.gameObject.SetActive(false);
			this._timer = 0u;
		}

		public override void PostUpdate(float fDeltaT)
		{
			bool flag = this._billboard == null;
			if (!flag)
			{
				XEntity xentity = this._host as XEntity;
				bool flag2 = xentity == null;
				if (!flag2)
				{
					bool flag3 = !XEntity.ValideEntity(xentity) && !xentity.IsAffiliate;
					if (flag3)
					{
						this._billboard.SetActive(false);
					}
					else
					{
						float num = 0.2f + this._entity.Height;
						bool isAffiliate = this._entity.IsAffiliate;
						if (isAffiliate)
						{
							num = 0.05f + this._entity.Height / 2f;
						}
						this._entity.EngineObject.SyncPos();
						Vector3 position;
						position= new Vector3(this._entity.EngineObject.Position.x, this._entity.EngineObject.Position.y + num, this._entity.EngineObject.Position.z);
						this._billboard.transform.position = position;
						this._billboard.transform.rotation = XSingleton<XScene>.singleton.GameCamera.Rotaton;
						bool flag4 = this.mCameraTrans != null;
						if (flag4)
						{
							float num2 = Vector3.Distance(this._entity.EngineObject.Position, this.mCameraTrans.position);
							float num3 = num2 / this.mSrcDistance;
							this._heroHeight = (this._entity.IsAffiliate ? 1.6f : 2f) * Mathf.Clamp(num3, 0.2f, 1.2f);
							this._billboard.transform.localScale = new Vector3(0.01f * this._heroHeight / 1.5f, 0.01f * this._heroHeight / 1.5f, 0.01f * this._heroHeight / 1.5f);
						}
						bool flag5 = Time.frameCount % 15 == 0;
						if (flag5)
						{
							float billBoardDepth = Vector3.Distance(XSingleton<XScene>.singleton.GameCamera.UnityCamera.transform.position, this._billboard.transform.position);
							this.SetBillBoardDepth(billBoardDepth);
						}
					}
				}
			}
		}

		private void SetBillBoardDepth(float dis = 0f)
		{
			int num = -(int)(dis * 100f);
			bool flag = this._label != null && this._board != null;
			if (flag)
			{
				this._label.spriteDepth = num + 1;
				this._board.spriteDepth = num;
			}
		}
	}
}