From 6eb915c129fc90c6f4c82ae097dd6ffad5239efc Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 25 Jan 2021 14:28:30 +0800 Subject: +scripts --- .../XMainClient/XCameraCollisonComponent.cs | 282 +++++++++++++++++++++ 1 file changed, 282 insertions(+) create mode 100644 Client/Assets/Scripts/XMainClient/XCameraCollisonComponent.cs (limited to 'Client/Assets/Scripts/XMainClient/XCameraCollisonComponent.cs') diff --git a/Client/Assets/Scripts/XMainClient/XCameraCollisonComponent.cs b/Client/Assets/Scripts/XMainClient/XCameraCollisonComponent.cs new file mode 100644 index 00000000..874f4805 --- /dev/null +++ b/Client/Assets/Scripts/XMainClient/XCameraCollisonComponent.cs @@ -0,0 +1,282 @@ +using System; +using System.Collections.Generic; +using UnityEngine; +using XUtliPoolLib; + +namespace XMainClient +{ + internal class XCameraCollisonComponent : XComponent + { + public override uint ID + { + get + { + return XCameraCollisonComponent.uuID; + } + } + + public Vector3 HitNormal + { + get + { + return this._hit_normal; + } + } + + public new static readonly uint uuID = XSingleton.singleton.XHash("Camera_Basic_Collison"); + + private XCameraEx _camera_host = null; + + private float _collision_radius = 0.2f; + + private Vector3 _real_pos = Vector3.zero; + + private float _tdis = 0f; + + private List _invisible = new List(); + + private List _hit_collider = new List(); + + private List _last_hit_collider = new List(); + + private int _layer_mask = 0; + + private Vector3 _hit_normal = Vector3.zero; + + private static int _transparent_frequence = 10; + + private int _transparent_update_count = 0; + + public override void OnAttachToHost(XObject host) + { + base.OnAttachToHost(host); + this._camera_host = (host as XCameraEx); + this._transparent_update_count = 0; + } + + public override void OnDetachFromHost() + { + base.OnDetachFromHost(); + this._camera_host = null; + } + + private void InvisibleOn() + { + bool quality = XQualitySetting.GetQuality(EFun.ESceneFade); + bool flag = this._invisible != null; + if (flag) + { + for (int i = 0; i < this._invisible.Count; i++) + { + SceneMat sceneMat = this._invisible[i]; + bool flag2 = quality; + if (flag2) + { + sceneMat.Fade(true); + this._invisible[i] = sceneMat; + } + else + { + sceneMat.render.gameObject.layer = 31; + } + } + } + } + + private void InvisibleOff() + { + bool quality = XQualitySetting.GetQuality(EFun.ESceneFade); + bool flag = this._invisible != null; + if (flag) + { + int i = 0; + int count = this._invisible.Count; + while (i < count) + { + SceneMat sceneMat = this._invisible[i]; + bool flag2 = sceneMat.render != null; + if (flag2) + { + bool flag3 = quality; + if (flag3) + { + sceneMat.Fade(false); + } + else + { + sceneMat.render.gameObject.layer = 0; + } + } + i++; + } + } + this._invisible.Clear(); + } + + public override void PostUpdate(float fDeltaT) + { + this.UpdateCamera(fDeltaT); + this.UpdateSceneTransparent(); + } + + protected void UpdateCamera(float fDeltaT) + { + this._hit_normal = Vector3.zero; + this._real_pos = this._camera_host.CameraTrans.position; + Vector3 vector = this._real_pos - this._camera_host.Anchor; + float magnitude = vector.magnitude; + this._layer_mask = 513; + bool flag = XSingleton.singleton.OperationMode == XOperationMode.X25D; + if (flag) + { + this._layer_mask |= 4096; + } + RaycastHit raycastHit; + bool flag2 = Physics.SphereCast(this._camera_host.Anchor, this._collision_radius, vector.normalized, out raycastHit, magnitude, this._layer_mask); + if (flag2) + { + XOperationMode operationMode = XSingleton.singleton.OperationMode; + if (operationMode != XOperationMode.X25D) + { + if (operationMode - XOperationMode.X3D <= 1) + { + this._real_pos = raycastHit.point + raycastHit.normal * this._collision_radius; + this._camera_host.Offset = Mathf.Min((this._camera_host.Anchor - this._real_pos).magnitude, magnitude); + this._hit_normal = raycastHit.normal; + } + } + else + { + bool flag3 = raycastHit.collider.gameObject.layer == 0 && XSingleton.singleton.CurrentStage.Stage != EXStage.Hall && !Physics.SphereCast(this._camera_host.Anchor, this._collision_radius, vector.normalized, out raycastHit, magnitude, 512); + if (flag3) + { + this._tdis = Mathf.Max((this._camera_host.Anchor - this._real_pos).magnitude, magnitude); + this._camera_host.Offset += (this._tdis - this._camera_host.Offset) * Mathf.Min(1f, fDeltaT * 4f); + } + else + { + this._real_pos = raycastHit.point + raycastHit.normal * this._collision_radius; + this._camera_host.Offset = Mathf.Min((this._camera_host.Anchor - this._real_pos).magnitude, magnitude); + this._hit_normal = raycastHit.normal; + } + } + } + else + { + this._tdis = magnitude; + this._camera_host.Offset += (this._tdis - this._camera_host.Offset) * Mathf.Min(1f, fDeltaT * 4f); + } + this._camera_host.CameraTrans.position = this._camera_host.Anchor - this._camera_host.CameraTrans.forward * this._camera_host.Offset; + bool isLookAt = this._camera_host.IsLookAt; + if (isLookAt) + { + this._camera_host.LookAtTarget(); + } + } + + protected void UpdateSceneTransparent() + { + bool flag = this._transparent_update_count <= 0; + if (flag) + { + this._transparent_update_count = XCameraCollisonComponent._transparent_frequence; + this._layer_mask = 1 << LayerMask.NameToLayer("45Transparent"); + this._real_pos = this._camera_host.Anchor - this._camera_host.CameraTrans.forward * this._camera_host.TargetOffset; + Vector3 vector = this._real_pos - this._camera_host.Anchor; + RaycastHit[] array = Physics.SphereCastAll(this._camera_host.Anchor, this._collision_radius, vector.normalized, vector.magnitude, this._layer_mask); + bool flag2 = array.Length != 0 && !XSingleton.singleton.IsPlaying; + if (flag2) + { + this._hit_collider.Clear(); + for (int i = 0; i < array.Length; i++) + { + bool flag3 = array[i].collider.gameObject.layer == LayerMask.NameToLayer("45Transparent"); + if (flag3) + { + this._hit_collider.Add(array[i].collider); + } + } + bool flag4 = !this.IsColliderSetEqual(this._hit_collider, this._last_hit_collider); + if (flag4) + { + this.InvisibleOff(); + for (int j = 0; j < this._hit_collider.Count; j++) + { + IColliderRenderLinker colliderRenderLinker = this._hit_collider[j].gameObject.GetComponent("XColliderRenderLinker") as IColliderRenderLinker; + bool flag5 = colliderRenderLinker != null; + if (flag5) + { + foreach (Renderer renderer in colliderRenderLinker.GetLinkedRender()) + { + bool flag6 = renderer != null && !this.InVisibleContains(renderer); + if (flag6) + { + SceneMat item = default(SceneMat); + item.InitRender(renderer); + this._invisible.Add(item); + } + } + } + } + this.InvisibleOn(); + } + this.CloneColliderSet(this._last_hit_collider, this._hit_collider); + } + else + { + this.InvisibleOff(); + this._last_hit_collider.Clear(); + } + } + else + { + this._transparent_update_count--; + } + } + + private bool InVisibleContains(Renderer r) + { + for (int i = 0; i < this._invisible.Count; i++) + { + bool flag = this._invisible[i].render == r; + if (flag) + { + return true; + } + } + return false; + } + + private bool IsColliderSetEqual(List s, List t) + { + bool flag = s.Count != t.Count; + bool result; + if (flag) + { + result = false; + } + else + { + for (int i = 0; i < s.Count; i++) + { + bool flag2 = !t.Contains(s[i]); + if (flag2) + { + return false; + } + } + result = true; + } + return result; + } + + private void CloneColliderSet(List s, List t) + { + s.Clear(); + for (int i = 0; i < t.Count; i++) + { + s.Add(t[i]); + } + } + } +} -- cgit v1.1-26-g67d0