diff options
author | chai <chaifix@163.com> | 2022-07-08 09:22:29 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2022-07-08 09:22:29 +0800 |
commit | d4bc85c8642cfd0c98ef73710aa9202a7d774852 (patch) | |
tree | f7c17b4c1915a14ed60f2b4a253115452df041d0 /Other/Malenia/Assets/DynamicBone/Scripts/DynamicBonePlaneCollider.cs | |
parent | 8110c37b5890035ef73f936b3fc5964bf49bcf11 (diff) |
+ Malenia test
Diffstat (limited to 'Other/Malenia/Assets/DynamicBone/Scripts/DynamicBonePlaneCollider.cs')
-rw-r--r-- | Other/Malenia/Assets/DynamicBone/Scripts/DynamicBonePlaneCollider.cs | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/Other/Malenia/Assets/DynamicBone/Scripts/DynamicBonePlaneCollider.cs b/Other/Malenia/Assets/DynamicBone/Scripts/DynamicBonePlaneCollider.cs new file mode 100644 index 00000000..2f7780e9 --- /dev/null +++ b/Other/Malenia/Assets/DynamicBone/Scripts/DynamicBonePlaneCollider.cs @@ -0,0 +1,76 @@ +using UnityEngine; + +[AddComponentMenu("Dynamic Bone/Dynamic Bone Plane Collider")] +public class DynamicBonePlaneCollider : DynamicBoneColliderBase +{ + void OnValidate() + { + } + + public override bool Collide(ref Vector3 particlePosition, float particleRadius) + { + Vector3 normal = Vector3.up; + switch (m_Direction) + { + case Direction.X: + normal = transform.right; + break; + case Direction.Y: + normal = transform.up; + break; + case Direction.Z: + normal = transform.forward; + break; + } + + Vector3 p = transform.TransformPoint(m_Center); + Plane plane = new Plane(normal, p); + float d = plane.GetDistanceToPoint(particlePosition); + + if (m_Bound == Bound.Outside) + { + if (d < 0) + { + particlePosition -= normal * d; + return true; + } + } + else + { + if (d > 0) + { + particlePosition -= normal * d; + return true; + } + } + return false; + } + + void OnDrawGizmosSelected() + { + if (!enabled) + return; + + if (m_Bound == Bound.Outside) + Gizmos.color = Color.yellow; + else + Gizmos.color = Color.magenta; + + Vector3 normal = Vector3.up; + switch (m_Direction) + { + case Direction.X: + normal = transform.right; + break; + case Direction.Y: + normal = transform.up; + break; + case Direction.Z: + normal = transform.forward; + break; + } + + Vector3 p = transform.TransformPoint(m_Center); + Gizmos.DrawLine(p, p + normal); + } +} |