using System; using System.IO; using kt.Utility; using Newtonsoft.Json.Serialization; using UnityEngine; namespace kt.Physics { public class NativePlaneCollider : ANativeColliderBase { public NativePlaneColliderStatus planeStatus { get { return this.PlaneStatus; } } public override NativeColliderStatus status { get { return this.PlaneStatus; } protected set { this.PlaneStatus = (value as NativePlaneColliderStatus); } } public Vector3 localDirection { get { Vector3 vector = MathUtility.GetPrimitiveVector(this.planeStatus.direction); if (this.planeStatus.isDirectionInverse) { vector = -vector; } return vector; } } public Vector3 worldDirection { get { return base.transform.TransformDirection(this.localDirection); } } public override bool Collide(ref Vector3 position, float radius) { Plane plane = new Plane(this.worldDirection, this.worldCenter); float num = plane.GetDistanceToPoint(position) - radius; if (this.status.bound == NativeColliderStatus.Bound.Outside) { if (num < 0f) { position -= this.worldDirection * num; return true; } } else if (num > 0f) { position -= this.worldDirection * num; return true; } return false; } protected override bool CollidePlane(NativePlaneCollider plane, ref Vector3 normal) { Vector3 worldCenter = plane.worldCenter; bool flag = this.Collide(ref worldCenter, 0f, NativeColliderStatus.Bound.Outside); if (flag) { normal = worldCenter - plane.worldCenter; } return flag; } protected override bool CollideCapsule(NativeCapsuleCollider capsule, ref Vector3 normal) { float hit_diff = -1f; Vector3 hit_normal = Vector3.zero; Newtonsoft.Json.Serialization.Func func = delegate(Vector3 pos, float radius) { Vector3 hit_normal = Vector3.zero; Vector3 b = pos; if (this.Collide(ref pos, radius, NativeColliderStatus.Bound.Outside)) { hit_normal = pos - b; if (hit_diff < 0f || hit_diff < hit_normal.sqrMagnitude) { hit_diff = hit_normal.sqrMagnitude; hit_normal = hit_normal; } return true; } return false; }; bool flag = func(capsule.startPos, capsule.capsuleStatus.startRadius); bool flag2 = func(capsule.endPos, capsule.capsuleStatus.endRadius); if (flag || flag2) { normal = hit_normal; return true; } return false; } public override void Save(StreamWriter writer) { base.Save(writer); } public override void Load(StreamReader reader, Transform parent_search_root) { base.Load(reader, parent_search_root); } [SerializeField] private NativePlaneColliderStatus PlaneStatus = new NativePlaneColliderStatus(); } }