From 4056f06baea18d3c5ae23c4a022fc6ae6b135bb2 Mon Sep 17 00:00:00 2001 From: chai Date: Wed, 14 Oct 2020 10:15:19 +0800 Subject: +dynamic bone --- .../Scripts/DynamicBonePlaneCollider.cs | 76 ++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 Assets/ThirdParty/DynamicBone/Scripts/DynamicBonePlaneCollider.cs (limited to 'Assets/ThirdParty/DynamicBone/Scripts/DynamicBonePlaneCollider.cs') diff --git a/Assets/ThirdParty/DynamicBone/Scripts/DynamicBonePlaneCollider.cs b/Assets/ThirdParty/DynamicBone/Scripts/DynamicBonePlaneCollider.cs new file mode 100644 index 00000000..7265d26a --- /dev/null +++ b/Assets/ThirdParty/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); + } +} -- cgit v1.1-26-g67d0