From 6eb915c129fc90c6f4c82ae097dd6ffad5239efc Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 25 Jan 2021 14:28:30 +0800 Subject: +scripts --- .../Scripts/XMainClient/XManipulationComponent.cs | 96 ++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 Client/Assets/Scripts/XMainClient/XManipulationComponent.cs (limited to 'Client/Assets/Scripts/XMainClient/XManipulationComponent.cs') diff --git a/Client/Assets/Scripts/XMainClient/XManipulationComponent.cs b/Client/Assets/Scripts/XMainClient/XManipulationComponent.cs new file mode 100644 index 00000000..7369bd37 --- /dev/null +++ b/Client/Assets/Scripts/XMainClient/XManipulationComponent.cs @@ -0,0 +1,96 @@ +using System; +using System.Collections.Generic; +using UnityEngine; +using XUtliPoolLib; + +namespace XMainClient +{ + internal sealed class XManipulationComponent : XComponent + { + public override uint ID + { + get + { + return XManipulationComponent.uuID; + } + } + + public new static readonly uint uuID = XSingleton.singleton.XHash("XManipulation"); + + private Dictionary _item = new Dictionary(); + + protected override void EventSubscribe() + { + base.RegisterEvent(XEventDefine.XEvent_Manipulation_On, new XComponent.XEventHandler(this.ManipulationOn)); + base.RegisterEvent(XEventDefine.XEvent_Manipulation_Off, new XComponent.XEventHandler(this.ManipulationOff)); + } + + public override void OnAttachToHost(XObject host) + { + base.OnAttachToHost(host); + } + + public override void OnDetachFromHost() + { + this._item.Clear(); + base.OnDetachFromHost(); + } + + public override void Update(float fDeltaT) + { + bool flag = this._item.Count == 0; + if (!flag) + { + foreach (KeyValuePair keyValuePair in this._item) + { + XManipulationData value = keyValuePair.Value; + List list = value.TargetIsOpponent ? XSingleton.singleton.GetOpponent(this._entity) : XSingleton.singleton.GetAlly(this._entity); + Vector3 vector = this._entity.EngineObject.Position + this._entity.EngineObject.Rotation * new Vector3(value.OffsetX, 0f, value.OffsetZ); + for (int i = 0; i < list.Count; i++) + { + XEntity xentity = list[i]; + bool flag2 = !XEntity.ValideEntity(xentity); + if (!flag2) + { + Vector3 vector2 = vector - xentity.EngineObject.Position; + vector2.y = 0f; + float magnitude = vector2.magnitude; + bool flag3 = magnitude < value.Radius && (magnitude == 0f || Vector3.Angle(-vector2, this._entity.EngineObject.Forward) <= value.Degree * 0.5f); + if (flag3) + { + float num = value.Force * Time.deltaTime; + xentity.ApplyMove(vector2.normalized * Mathf.Min(magnitude, num)); + } + } + } + } + } + } + + private bool ManipulationOn(XEventArgs e) + { + XManipulationOnEventArgs xmanipulationOnEventArgs = e as XManipulationOnEventArgs; + bool flag = !this._item.ContainsKey(xmanipulationOnEventArgs.Token); + if (flag) + { + this._item.Add(xmanipulationOnEventArgs.Token, xmanipulationOnEventArgs.data); + } + return true; + } + + private bool ManipulationOff(XEventArgs e) + { + XManipulationOffEventArgs xmanipulationOffEventArgs = e as XManipulationOffEventArgs; + bool flag = xmanipulationOffEventArgs.DenyToken == 0L; + if (flag) + { + this._item.Clear(); + } + else + { + this._item.Remove(xmanipulationOffEventArgs.DenyToken); + } + return true; + } + } +} -- cgit v1.1-26-g67d0