summaryrefslogtreecommitdiff
path: root/Client/Assets/Scripts/XMainClient/XMountComponent.cs
blob: 4e4203b1e3967ba6affa615d825ec0ea47df4c8e (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
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<XCommon>.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;
		}
	}
}