DynamicBonePlaneCollider.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. using System;
  2. using System.IO;
  3. using UnityEngine;
  4. [AddComponentMenu("Dynamic Bone/Dynamic Bone Plane Collider")]
  5. public class DynamicBonePlaneCollider : DynamicBoneColliderBase
  6. {
  7. public override string TypeName
  8. {
  9. get
  10. {
  11. return "dpc";
  12. }
  13. }
  14. public override void Serialize(BinaryWriter f_bw, int f_nVersion)
  15. {
  16. base.Serialize(f_bw, f_nVersion);
  17. }
  18. public override void Deserialize(BinaryReader f_br, int f_nVersion, Transform f_trBodyBoneRoot)
  19. {
  20. base.Deserialize(f_br, f_nVersion, f_trBodyBoneRoot);
  21. }
  22. private void OnValidate()
  23. {
  24. }
  25. public override bool Collide(ref Vector3 particlePosition, float particleRadius)
  26. {
  27. Vector3 vector = Vector3.up;
  28. DynamicBoneColliderBase.Direction direction = this.m_Direction;
  29. if (direction != DynamicBoneColliderBase.Direction.X)
  30. {
  31. if (direction != DynamicBoneColliderBase.Direction.Y)
  32. {
  33. if (direction == DynamicBoneColliderBase.Direction.Z)
  34. {
  35. vector = base.transform.forward;
  36. }
  37. }
  38. else
  39. {
  40. vector = base.transform.up;
  41. }
  42. }
  43. else
  44. {
  45. vector = base.transform.right;
  46. }
  47. Vector3 inPoint = base.transform.TransformPoint(this.m_Center);
  48. Plane plane = new Plane(vector, inPoint);
  49. float distanceToPoint = plane.GetDistanceToPoint(particlePosition);
  50. if (this.m_Bound == DynamicBoneColliderBase.Bound.Outside)
  51. {
  52. if (distanceToPoint < 0f)
  53. {
  54. particlePosition -= vector * distanceToPoint;
  55. return true;
  56. }
  57. }
  58. else if (distanceToPoint > 0f)
  59. {
  60. particlePosition -= vector * distanceToPoint;
  61. return true;
  62. }
  63. return false;
  64. }
  65. }