12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- using System;
- using System.IO;
- using UnityEngine;
- [AddComponentMenu("Dynamic Bone/Dynamic Bone Plane Collider")]
- public class DynamicBonePlaneCollider : DynamicBoneColliderBase
- {
- public override string TypeName
- {
- get
- {
- return "dpc";
- }
- }
- public override void Serialize(BinaryWriter f_bw, int f_nVersion)
- {
- base.Serialize(f_bw, f_nVersion);
- }
- public override void Deserialize(BinaryReader f_br, int f_nVersion, Transform f_trBodyBoneRoot)
- {
- base.Deserialize(f_br, f_nVersion, f_trBodyBoneRoot);
- }
- private void OnValidate()
- {
- }
- public override bool Collide(ref Vector3 particlePosition, float particleRadius)
- {
- Vector3 vector = Vector3.up;
- DynamicBoneColliderBase.Direction direction = this.m_Direction;
- if (direction != DynamicBoneColliderBase.Direction.X)
- {
- if (direction != DynamicBoneColliderBase.Direction.Y)
- {
- if (direction == DynamicBoneColliderBase.Direction.Z)
- {
- vector = base.transform.forward;
- }
- }
- else
- {
- vector = base.transform.up;
- }
- }
- else
- {
- vector = base.transform.right;
- }
- Vector3 inPoint = base.transform.TransformPoint(this.m_Center);
- Plane plane = new Plane(vector, inPoint);
- float distanceToPoint = plane.GetDistanceToPoint(particlePosition);
- if (this.m_Bound == DynamicBoneColliderBase.Bound.Outside)
- {
- if (distanceToPoint < 0f)
- {
- particlePosition -= vector * distanceToPoint;
- return true;
- }
- }
- else if (distanceToPoint > 0f)
- {
- particlePosition -= vector * distanceToPoint;
- return true;
- }
- return false;
- }
- }
|