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/XMountComponent.cs | 160 +++++++++++++++++++++ 1 file changed, 160 insertions(+) create mode 100644 Client/Assets/Scripts/XMainClient/XMountComponent.cs (limited to 'Client/Assets/Scripts/XMainClient/XMountComponent.cs') diff --git a/Client/Assets/Scripts/XMainClient/XMountComponent.cs b/Client/Assets/Scripts/XMainClient/XMountComponent.cs new file mode 100644 index 00000000..4e4203b1 --- /dev/null +++ b/Client/Assets/Scripts/XMainClient/XMountComponent.cs @@ -0,0 +1,160 @@ +using System; +using UnityEngine; +using XUtliPoolLib; + +namespace XMainClient +{ + internal class XMountComponent : XComponent + { + public override uint ID + { + get + { + return XMountComponent.uuID; + } + } + + public XEntity Copilot + { + get + { + return this._mount_copilotMainBody; + } + } + + public new static readonly uint uuID = XSingleton.singleton.XHash("MountComponent"); + + private XEntity _mountMainBody = null; + + private XEntity _mount_copilotMainBody = null; + + public void PreMount(XEntity entity) + { + bool flag = XEntity.ValideEntity(entity); + if (flag) + { + bool flag2 = this._mountMainBody != null; + if (!flag2) + { + this._mountMainBody = entity; + this._mountMainBody.OnMount(this._entity as XMount, false); + } + } + } + + public void RealMount(Transform mountPoint, Vector3 pos, ref Quaternion basic_rotation, float mountScale) + { + bool flag = mountPoint == null || !XEntity.ValideEntity(this._mountMainBody); + if (!flag) + { + XMountComponent._Mount(this._mountMainBody, mountPoint, pos, ref basic_rotation, mountScale); + } + } + + public bool PreMountCopilot(XEntity entity) + { + bool flag = XEntity.ValideEntity(entity); + bool result; + if (flag) + { + bool flag2 = this._mount_copilotMainBody != null; + if (flag2) + { + result = false; + } + else + { + bool flag3 = entity.Machine != null; + if (flag3) + { + entity.Machine.ForceToDefaultState(false); + } + entity.LookTo(this._entity.MoveObj.Forward); + this._mount_copilotMainBody = entity; + this._mount_copilotMainBody.OnMount(this._entity as XMount, true); + result = true; + } + } + else + { + result = false; + } + return result; + } + + public void RealMountCopilot(Transform mountPoint, Vector3 pos, ref Quaternion basic_rotation, float mountScale) + { + bool flag = mountPoint == null || !XEntity.ValideEntity(this._mount_copilotMainBody); + if (!flag) + { + XMountComponent._Mount(this._mount_copilotMainBody, mountPoint, pos, ref basic_rotation, mountScale); + } + } + + public void UnMount(XEntity entity) + { + bool flag = this._mountMainBody == entity; + if (flag) + { + bool flag2 = this._mountMainBody == null; + if (!flag2) + { + this.UnMountAll(); + } + } + else + { + bool flag3 = this._mount_copilotMainBody == entity; + if (flag3) + { + bool flag4 = this._mount_copilotMainBody == null; + if (!flag4) + { + this._UnMount(ref this._mount_copilotMainBody); + } + } + } + } + + public void UnMountAll() + { + bool flag = this._mount_copilotMainBody != null; + if (flag) + { + this._UnMount(ref this._mount_copilotMainBody); + } + bool flag2 = this._mountMainBody != null; + if (flag2) + { + this._UnMount(ref this._mountMainBody); + } + } + + private static void _Mount(XEntity mainBody, Transform mountPoint, Vector3 pos, ref Quaternion basic_rotation, float mountScale) + { + bool flag = mountScale > 0f; + if (flag) + { + mountScale = 1f / mountScale; + } + mainBody.EngineObject.SetParentTrans(mountPoint); + mainBody.EngineObject.SetLocalPRS(pos, true, Quaternion.Inverse(basic_rotation), true, Vector3.one * mountScale, true); + } + + private void _UnMount(ref XEntity mountEntity) + { + bool flag = !mountEntity.Destroying; + if (flag) + { + Vector3 position = this._entity.EngineObject.Position; + position.y += 0.5f; + mountEntity.EngineObject.SetParent(null); + mountEntity.EngineObject.Position = position; + mountEntity.EngineObject.Rotation = this._entity.EngineObject.Rotation; + mountEntity.EngineObject.LocalScale = Vector3.one; + mountEntity.OnMount(null, false); + } + mountEntity = null; + } + } +} -- cgit v1.1-26-g67d0