From 6eb915c129fc90c6f4c82ae097dd6ffad5239efc Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 25 Jan 2021 14:28:30 +0800 Subject: +scripts --- .../Assets/Scripts/XMainClient/XBubbleComponent.cs | 170 +++++++++++++++++++++ 1 file changed, 170 insertions(+) create mode 100644 Client/Assets/Scripts/XMainClient/XBubbleComponent.cs (limited to 'Client/Assets/Scripts/XMainClient/XBubbleComponent.cs') diff --git a/Client/Assets/Scripts/XMainClient/XBubbleComponent.cs b/Client/Assets/Scripts/XMainClient/XBubbleComponent.cs new file mode 100644 index 00000000..a2d7c7c1 --- /dev/null +++ b/Client/Assets/Scripts/XMainClient/XBubbleComponent.cs @@ -0,0 +1,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.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.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.singleton.AddChild(XSingleton.singleton.NpcHpbarRoot.gameObject, this._billboard); + } + else + { + XSingleton.singleton.AddChild(XSingleton.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.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.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.singleton.ShowCurrTempMsg(xbubbleEventArgs.bubbletext, xbubbleEventArgs.speaker); + bool flag = this._timer > 0u; + if (flag) + { + XSingleton.singleton.KillTimer(this._timer); + } + this._timer = XSingleton.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.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.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; + } + } + } +} -- cgit v1.1-26-g67d0