summaryrefslogtreecommitdiff
path: root/Client/Assets/Scripts/XMainClient/XCameraActionComponent.cs
blob: 9942eec44f25c5e7040ee45d9eb2e65c0f1535f5 (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
using System;
using UnityEngine;
using XUtliPoolLib;

namespace XMainClient
{
	internal class XCameraActionComponent : XComponent
	{
		public override uint ID
		{
			get
			{
				return XCameraActionComponent.uuID;
			}
		}

		public new static readonly uint uuID = XSingleton<XCommon>.singleton.XHash("Camera_Common_Action");

		private XCameraEx _camera_host = null;

		private Vector3 _last_pos = Vector3.zero;

		private bool _began = false;

		private float _auto_x = 0f;

		private float _auto_y = 0f;

		private float _manual_x = 0f;

		private float _manual_y = 0f;

		private float _dis = 0f;

		private float _tx = 0f;

		private float _ty = 0f;

		private bool _auto = true;

		private bool _world_stage = false;

		private XCameraActionEventArgs.FinishHandler _handler = null;

		public override void OnAttachToHost(XObject host)
		{
			base.OnAttachToHost(host);
			this._camera_host = (host as XCameraEx);
			this._world_stage = (XSingleton<XGame>.singleton.CurrentStage.Stage == EXStage.World);
		}

		public override void OnDetachFromHost()
		{
			base.OnDetachFromHost();
			this._camera_host = null;
		}

		protected override void EventSubscribe()
		{
			base.RegisterEvent(XEventDefine.XEvent_CameraAction, new XComponent.XEventHandler(this.OnAction));
		}

		protected bool OnAction(XEventArgs e)
		{
			XCameraActionEventArgs xcameraActionEventArgs = e as XCameraActionEventArgs;
			bool flag = this._handler != null;
			if (flag)
			{
				this._handler();
				this._handler = null;
			}
			this._tx = xcameraActionEventArgs.XRotate;
			this._ty = xcameraActionEventArgs.YRotate;
			this._manual_x = this._camera_host.Root_R_X;
			this._manual_y = XSingleton<XCommon>.singleton.AngleNormalize(this._ty, this._camera_host.Root_R_Y);
			this._dis = ((xcameraActionEventArgs.Dis > 0f) ? xcameraActionEventArgs.Dis : this._camera_host.TargetOffset);
			this._handler = xcameraActionEventArgs.Finish;
			this._auto = false;
			return true;
		}

		public override void Update(float fDeltaT)
		{
			bool flag = base.Enabled && XSingleton<XGesture>.singleton.Working && !this._camera_host.IsDuringCloseUp;
			if (flag)
			{
				bool began = this._began;
				if (began)
				{
					this._tx = 0f;
					this._auto_x = 0f;
					this._ty = 0f;
					this._auto_y = 0f;
				}
				else
				{
					bool operationH = XCameraEx.OperationH;
					if (operationH)
					{
						this._tx = (XSingleton<XGesture>.singleton.GesturePosition.x - this._last_pos.x) * (this._world_stage ? XSingleton<XOperationData>.singleton.ManualCameraSpeedXInBattle : XSingleton<XOperationData>.singleton.ManualCameraSpeedXInHall);
					}
					bool operationV = XCameraEx.OperationV;
					if (operationV)
					{
						this._ty = (XSingleton<XGesture>.singleton.GesturePosition.y - this._last_pos.y) * (this._world_stage ? XSingleton<XOperationData>.singleton.ManualCameraSpeedYInBattle : XSingleton<XOperationData>.singleton.ManualCameraSpeedYInHall);
					}
				}
				this._last_pos = XSingleton<XGesture>.singleton.GesturePosition;
				this._began = false;
				this._auto = true;
			}
			else
			{
				this._began = true;
				bool auto = this._auto;
				if (auto)
				{
					this._tx = 0f;
					this._ty = 0f;
				}
			}
			bool auto2 = this._auto;
			if (auto2)
			{
				this._auto_x += (this._tx - this._auto_x) * Mathf.Min(1f, fDeltaT * (this._world_stage ? XSingleton<XOperationData>.singleton.ManualCameraDampXInBattle : XSingleton<XOperationData>.singleton.ManualCameraDampXInHall));
				this._auto_y += (this._ty - this._auto_y) * Mathf.Min(1f, fDeltaT * (this._world_stage ? XSingleton<XOperationData>.singleton.ManualCameraDampYInBattle : XSingleton<XOperationData>.singleton.ManualCameraDampYInHall));
				bool flag2 = this._auto_y != 0f;
				if (flag2)
				{
					this._camera_host.XRotate(-this._auto_y);
				}
				bool flag3 = this._auto_x != 0f;
				if (flag3)
				{
					this._camera_host.YRotate(this._auto_x);
				}
			}
			else
			{
				this._manual_x += (this._tx - this._manual_x) * Mathf.Min(1f, fDeltaT * XSingleton<XGlobalConfig>.singleton.CloseUpCameraSpeed);
				this._manual_y += (this._ty - this._manual_y) * Mathf.Min(1f, fDeltaT * XSingleton<XGlobalConfig>.singleton.CloseUpCameraSpeed);
				this._camera_host.XRotateEx(this._manual_x);
				this._camera_host.YRotateEx(this._manual_y);
				this._camera_host.Offset += (this._dis - this._camera_host.Offset) * Mathf.Min(1f, fDeltaT * XSingleton<XGlobalConfig>.singleton.CloseUpCameraSpeed);
				bool flag4 = Mathf.Abs(this._tx - this._manual_x) < 1f && Mathf.Abs(this._ty - this._manual_y) < 1f && this._handler != null;
				if (flag4)
				{
					this._handler();
					this._handler = null;
				}
			}
		}
	}
}