123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- 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<Vector3, float, bool> 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<NativePlaneColliderStatus>(writer);
- }
- public override void Load(StreamReader reader, Transform parent_search_root)
- {
- base.Load<NativePlaneColliderStatus>(reader, parent_search_root);
- }
- [SerializeField]
- private NativePlaneColliderStatus PlaneStatus = new NativePlaneColliderStatus();
- }
- }
|