From 97da432c35b8c7aaf9dd2c39e2aa4b1f55f36065 Mon Sep 17 00:00:00 2001 From: chai Date: Wed, 27 Jan 2021 16:15:06 +0800 Subject: +behaviour designer --- .../Runtime/Basic Tasks/Physics2D/Circlecast.cs | 73 ++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 Client/Assets/Behavior Designer/Runtime/Basic Tasks/Physics2D/Circlecast.cs (limited to 'Client/Assets/Behavior Designer/Runtime/Basic Tasks/Physics2D/Circlecast.cs') diff --git a/Client/Assets/Behavior Designer/Runtime/Basic Tasks/Physics2D/Circlecast.cs b/Client/Assets/Behavior Designer/Runtime/Basic Tasks/Physics2D/Circlecast.cs new file mode 100644 index 00000000..516abc72 --- /dev/null +++ b/Client/Assets/Behavior Designer/Runtime/Basic Tasks/Physics2D/Circlecast.cs @@ -0,0 +1,73 @@ +using UnityEngine; + +namespace BehaviorDesigner.Runtime.Tasks.Basic.UnityPhysics2D +{ + [TaskCategory("Basic/Physics2D")] + [TaskDescription("Casts a circle against all colliders in the scene. Returns success if a collider was hit.")] + [HelpURL("http://www.opsive.com/assets/BehaviorDesigner/documentation.php?id=118")] + public class Circlecast : Action + { + [Tooltip("Starts the circlecast at the GameObject's position. If null the originPosition will be used.")] + public SharedGameObject originGameObject; + [Tooltip("Starts the circlecast at the position. Only used if originGameObject is null.")] + public SharedVector2 originPosition; + [Tooltip("The radius of the circlecast")] + public SharedFloat radius; + [Tooltip("The direction of the circlecast")] + public SharedVector2 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("Use 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 circlecast.")] + public SharedGameObject storeHitObject; + [SharedRequired] + [Tooltip("Stores the hit point of the circlecast.")] + public SharedVector2 storeHitPoint; + [SharedRequired] + [Tooltip("Stores the hit normal of the circlecast.")] + public SharedVector2 storeHitNormal; + [SharedRequired] + [Tooltip("Stores the hit distance of the circlecast.")] + public SharedFloat storeHitDistance; + + public override TaskStatus OnUpdate() + { + Vector2 position; + Vector2 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; + } + + var hit = Physics2D.CircleCast(position, radius.Value, dir, distance.Value == -1 ? Mathf.Infinity : distance.Value, layerMask); + if (hit.collider != null) { + 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 = Vector2.zero; + direction = Vector2.zero; + radius = 0; + distance = -1; + layerMask = -1; + space = Space.Self; + } + } +} \ No newline at end of file -- cgit v1.1-26-g67d0