summaryrefslogtreecommitdiff
path: root/Client/Assets/Scripts/XMainClient/XShadowComponent.cs
blob: ea68dea0cdbdd09c0aafd3605b4e05eabb8e62be (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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
using System;
using UnityEngine;
using XUtliPoolLib;

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

		private XGameObject Shadow
		{
			get
			{
				return this._shadow;
			}
		}

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

		private XGameObject _shadow = null;

		private bool _showRealTimeShadow = false;

		private static CommandCallback _initCb = new CommandCallback(XShadowComponent._Init);

		private static void _Init(XGameObject gameObject, object o, int commandID)
		{
			XShadowComponent xshadowComponent = o as XShadowComponent;
			GameObject gameObject2 = gameObject.Get();
			Renderer componentInChildren = gameObject2.GetComponentInChildren<Renderer>();
			componentInChildren.enabled = (!xshadowComponent.Entity.IsDisappear && xshadowComponent.Entity.IsVisible);
			componentInChildren.gameObject.layer = xshadowComponent._entity.DefaultLayer;
			XRenderComponent.AddShadowObj(xshadowComponent._entity, gameObject2, componentInChildren);
		}

		private void LoadShadow()
		{
			bool flag = this._shadow == null;
			if (flag)
			{
				this._shadow = XGameObject.CreateXGameObject("Prefabs/Shadow", true, true);
				this._shadow.SetParent(this._entity.MoveObj);
				this._shadow.SetLocalPRS(Vector3.zero, true, Quaternion.identity, true, Vector3.one, false);
				this._shadow.CallCommand(XShadowComponent._initCb, this, -1, false);
			}
		}

		private void ProcessRealtimeShadow()
		{
			this._showRealTimeShadow = false;
			bool flag = this._entity != null;
			if (flag)
			{
				this._showRealTimeShadow = this._entity.ProcessRealTimeShadow();
			}
		}

		private void ProcessFakeShadow()
		{
			bool flag = XEntity.ValideEntity(this._entity.Transformee);
			bool flag2;
			if (flag)
			{
				flag2 = this._entity.Transformee.CastFakeShadow();
			}
			else
			{
				flag2 = this._entity.CastFakeShadow();
			}
			bool enable = !this._showRealTimeShadow && flag2;
			bool flag3 = !this._showRealTimeShadow && flag2;
			if (flag3)
			{
				this.LoadShadow();
			}
			bool flag4 = this._shadow != null;
			if (flag4)
			{
				this._shadow.SetActive(enable, "");
			}
		}

		public void ProcessShadow()
		{
			this.ProcessRealtimeShadow();
			this.ProcessFakeShadow();
		}

		protected override void EventSubscribe()
		{
			base.RegisterEvent(XEventDefine.XEvent_OnMounted, new XComponent.XEventHandler(this.OnMountEvent));
			base.RegisterEvent(XEventDefine.XEvent_OnUnMounted, new XComponent.XEventHandler(this.OnMountEvent));
		}

		public override void Attached()
		{
			base.Attached();
			this.ProcessShadow();
			bool showRealTimeShadow = this._showRealTimeShadow;
			if (!showRealTimeShadow)
			{
				bool flag = this._shadow != null;
				if (flag)
				{
					Vector3 localScale = Vector3.one * this._entity.Radius * 2.5f;
					this._shadow.LocalScale = localScale;
				}
			}
		}

		public override void OnDetachFromHost()
		{
			bool flag = this._shadow != null;
			if (flag)
			{
				XRenderComponent.RemoveObj(this._entity, this._shadow.Get());
				XGameObject.DestroyXGameObject(this._shadow);
				this._shadow = null;
			}
			base.OnDetachFromHost();
		}

		protected bool OnMountEvent(XEventArgs e)
		{
			bool showRealTimeShadow = this._showRealTimeShadow;
			bool result;
			if (showRealTimeShadow)
			{
				result = true;
			}
			else
			{
				bool flag = this._shadow != null;
				if (flag)
				{
					this._shadow.SetParent(this._entity.MoveObj);
					this._shadow.SetLocalPRS(Vector3.zero, true, Quaternion.identity, true, Vector3.one, e is XOnUnMountedEventArgs);
				}
				result = true;
			}
			return result;
		}

		public override void PostUpdate(float fDeltaT)
		{
			bool showRealTimeShadow = this._showRealTimeShadow;
			if (!showRealTimeShadow)
			{
				bool flag = this._shadow != null;
				if (flag)
				{
					Vector3 zero = Vector3.zero;
					Vector3 position = this._entity.MoveObj.Position;
					zero.y = (this._entity.StandOn ? 0f : (XSingleton<XScene>.singleton.TerrainY(position) - position.y)) / this._entity.Scale + 0.025f;
					this._shadow.SetLocalPRS(zero, true, XSingleton<XCommon>.singleton.RotateToGround(position, Vector3.forward), true, Vector3.one, false);
				}
			}
		}

		public void SetActive(bool active)
		{
			bool flag = this._shadow != null;
			if (flag)
			{
				this._shadow.SetActive(active, "");
			}
		}
	}
}