源战役客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
1.7 KiB

  1. using UnityEngine;
  2. [AddComponentMenu("Dynamic Bone/Dynamic Bone Plane Collider")]
  3. public class DynamicBonePlaneCollider : DynamicBoneColliderBase
  4. {
  5. void OnValidate()
  6. {
  7. }
  8. public override void Collide(ref Vector3 particlePosition, float particleRadius)
  9. {
  10. Vector3 normal = Vector3.up;
  11. switch (m_Direction)
  12. {
  13. case Direction.X:
  14. normal = transform.right;
  15. break;
  16. case Direction.Y:
  17. normal = transform.up;
  18. break;
  19. case Direction.Z:
  20. normal = transform.forward;
  21. break;
  22. }
  23. Vector3 p = transform.TransformPoint(m_Center);
  24. Plane plane = new Plane(normal, p);
  25. float d = plane.GetDistanceToPoint(particlePosition);
  26. if (m_Bound == Bound.Outside)
  27. {
  28. if (d < 0)
  29. particlePosition -= normal * d;
  30. }
  31. else
  32. {
  33. if (d > 0)
  34. particlePosition -= normal * d;
  35. }
  36. }
  37. void OnDrawGizmosSelected()
  38. {
  39. if (!enabled)
  40. return;
  41. if (m_Bound == Bound.Outside)
  42. Gizmos.color = Color.yellow;
  43. else
  44. Gizmos.color = Color.magenta;
  45. Vector3 normal = Vector3.up;
  46. switch (m_Direction)
  47. {
  48. case Direction.X:
  49. normal = transform.right;
  50. break;
  51. case Direction.Y:
  52. normal = transform.up;
  53. break;
  54. case Direction.Z:
  55. normal = transform.forward;
  56. break;
  57. }
  58. Vector3 p = transform.TransformPoint(m_Center);
  59. Gizmos.DrawLine(p, p + normal);
  60. }
  61. }