summaryrefslogtreecommitdiff
path: root/Client/Assets/Scripts/XMainClient/XManipulationComponent.cs
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2021-01-25 14:28:30 +0800
committerchai <chaifix@163.com>2021-01-25 14:28:30 +0800
commit6eb915c129fc90c6f4c82ae097dd6ffad5239efc (patch)
tree7dd2be50edf41f36b60fac84696e731c13afe617 /Client/Assets/Scripts/XMainClient/XManipulationComponent.cs
+scripts
Diffstat (limited to 'Client/Assets/Scripts/XMainClient/XManipulationComponent.cs')
-rw-r--r--Client/Assets/Scripts/XMainClient/XManipulationComponent.cs96
1 files changed, 96 insertions, 0 deletions
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<XCommon>.singleton.XHash("XManipulation");
+
+ private Dictionary<long, XManipulationData> _item = new Dictionary<long, XManipulationData>();
+
+ 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<long, XManipulationData> keyValuePair in this._item)
+ {
+ XManipulationData value = keyValuePair.Value;
+ List<XEntity> list = value.TargetIsOpponent ? XSingleton<XEntityMgr>.singleton.GetOpponent(this._entity) : XSingleton<XEntityMgr>.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;
+ }
+ }
+}