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/XShadowComponent.cs | 176 +++++++++++++++++++++ 1 file changed, 176 insertions(+) create mode 100644 Client/Assets/Scripts/XMainClient/XShadowComponent.cs (limited to 'Client/Assets/Scripts/XMainClient/XShadowComponent.cs') diff --git a/Client/Assets/Scripts/XMainClient/XShadowComponent.cs b/Client/Assets/Scripts/XMainClient/XShadowComponent.cs new file mode 100644 index 00000000..ea68dea0 --- /dev/null +++ b/Client/Assets/Scripts/XMainClient/XShadowComponent.cs @@ -0,0 +1,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.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(); + 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.singleton.TerrainY(position) - position.y)) / this._entity.Scale + 0.025f; + this._shadow.SetLocalPRS(zero, true, XSingleton.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, ""); + } + } + } +} -- cgit v1.1-26-g67d0