using System; using System.IO; using UnityEngine; namespace kt.Physics { public class NativeSphereCollider : ANativeColliderBase { public NativeSphereColliderStatus sphereStatus { get { return this.SphereStatus; } } public override NativeColliderStatus status { get { return this.SphereStatus; } protected set { this.SphereStatus = (value as NativeSphereColliderStatus); } } public float radius { get { return this.sphereStatus.radius * base.GetLossyScale(); } } public override bool Collide(ref Vector3 position, float radius) { Vector3 a = position - this.worldCenter; if (this.status.bound == NativeColliderStatus.Bound.Outside) { float num = this.radius + radius; if (a.sqrMagnitude > num * num) { return false; } float magnitude = a.magnitude; if (magnitude > 0f) { position += a / magnitude * num; } } else { float num2 = Mathf.Max(radius - radius, 0f); if (a.sqrMagnitude < num2 * num2) { return false; } float magnitude2 = a.magnitude; if (magnitude2 > 0f) { position = a / magnitude2 * num2; } } return true; } protected override bool CollideCapsule(NativeCapsuleCollider capsule, ref Vector3 normal) { bool flag = capsule.Collide(this, out normal); if (flag) { normal = -normal; } return flag; } 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 NativeSphereColliderStatus SphereStatus = new NativeSphereColliderStatus(); } }