From 21e186f75b504d832d9c7bef0456edd7d5d3155e Mon Sep 17 00:00:00 2001 From: chai Date: Wed, 8 Sep 2021 10:52:35 +0800 Subject: +behavior design --- .../Runtime/Basic Tasks/Physics/Raycast.cs | 71 ++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 Assets/ThirdParty/Behavior Designer/Runtime/Basic Tasks/Physics/Raycast.cs (limited to 'Assets/ThirdParty/Behavior Designer/Runtime/Basic Tasks/Physics/Raycast.cs') diff --git a/Assets/ThirdParty/Behavior Designer/Runtime/Basic Tasks/Physics/Raycast.cs b/Assets/ThirdParty/Behavior Designer/Runtime/Basic Tasks/Physics/Raycast.cs new file mode 100644 index 00000000..d79c9ae9 --- /dev/null +++ b/Assets/ThirdParty/Behavior Designer/Runtime/Basic Tasks/Physics/Raycast.cs @@ -0,0 +1,71 @@ +using UnityEngine; + +namespace BehaviorDesigner.Runtime.Tasks.Basic.UnityPhysics +{ + [TaskCategory("Basic/Physics")] + [TaskDescription("Casts a ray against all colliders in the scene. Returns success if a collider was hit.")] + [HelpURL("http://www.opsive.com/assets/BehaviorDesigner/documentation.php?id=117")] + public class Raycast : Action + { + [Tooltip("Starts the ray at the GameObject's position. If null the originPosition will be used")] + public SharedGameObject originGameObject; + [Tooltip("Starts the ray at the position. Only used if originGameObject is null")] + public SharedVector3 originPosition; + [Tooltip("The direction of the ray")] + public SharedVector3 direction; + [Tooltip("The length of the ray. Set to -1 for infinity")] + public SharedFloat distance = -1; + [Tooltip("Selectively ignore colliders")] + public LayerMask layerMask = -1; + [Tooltip("Cast the ray in world or local space. The direction is in world space if no GameObject is specified")] + public Space space = Space.Self; + + [SharedRequired] + [Tooltip("Stores the hit object of the raycast")] + public SharedGameObject storeHitObject; + [SharedRequired] + [Tooltip("Stores the hit point of the raycast")] + public SharedVector3 storeHitPoint; + [SharedRequired] + [Tooltip("Stores the hit normal of the raycast")] + public SharedVector3 storeHitNormal; + [SharedRequired] + [Tooltip("Stores the hit distance of the raycast")] + public SharedFloat storeHitDistance; + + public override TaskStatus OnUpdate() + { + Vector3 position; + Vector3 dir = direction.Value; + if (originGameObject.Value != null) { + position = originGameObject.Value.transform.position; + if (space == Space.Self) { + dir = originGameObject.Value.transform.TransformDirection(direction.Value); + } + } else { + position = originPosition.Value; + } + + RaycastHit hit; + if (Physics.Raycast(position, dir, out hit, distance.Value == -1 ? Mathf.Infinity : distance.Value, layerMask)) { + storeHitObject.Value = hit.collider.gameObject; + storeHitPoint.Value = hit.point; + storeHitNormal.Value = hit.normal; + storeHitDistance.Value = hit.distance; + return TaskStatus.Success; + } + + return TaskStatus.Failure; + } + + public override void OnReset() + { + originGameObject = null; + originPosition = Vector3.zero; + direction = Vector3.zero; + distance = -1; + layerMask = -1; + space = Space.Self; + } + } +} \ No newline at end of file -- cgit v1.1-26-g67d0