Roman aa6e1ebe90 任务:创建项目,引入部分将会用到的插件和包
1.引入URP
2.引入InputSystem
3.引入Fungus
4.引入DoTween
5.引入CinemaMachine
6.引入BehaviorTree
7.引入BehaviorTree动作包
8.配置了渲染管线资源

🥵🥵🥵🥵🥵
2021-11-21 15:14:51 +08:00

82 lines
2.8 KiB
C#

using UnityEngine;
namespace BehaviorDesigner.Runtime.Tasks.Movement
{
[TaskDescription("Flee from the target specified using the Unity NavMesh.")]
[TaskCategory("Movement")]
[HelpURL("https://www.opsive.com/support/documentation/behavior-designer-movement-pack/")]
[TaskIcon("Assets/Behavior Designer Movement/Editor/Icons/{SkinColor}FleeIcon.png")]
public class Flee : NavMeshMovement
{
[Tooltip("The agent has fleed when the magnitude is greater than this value")]
public SharedFloat fleedDistance = 20;
[Tooltip("The distance to look ahead when fleeing")]
public SharedFloat lookAheadDistance = 5;
[Tooltip("The GameObject that the agent is fleeing from")]
public SharedGameObject target;
private bool hasMoved;
public override void OnStart()
{
base.OnStart();
hasMoved = false;
SetDestination(Target());
}
// Flee from the target. Return success once the agent has fleed the target by moving far enough away from it
// Return running if the agent is still fleeing
public override TaskStatus OnUpdate()
{
if (Vector3.Magnitude(transform.position - target.Value.transform.position) > fleedDistance.Value) {
return TaskStatus.Success;
}
if (HasArrived()) {
if (!hasMoved) {
return TaskStatus.Failure;
}
if (!SetDestination(Target())) {
return TaskStatus.Failure;
}
hasMoved = false;
} else {
// If the agent is stuck the task shouldn't continue to return a status of running.
var velocityMagnitude = Velocity().sqrMagnitude;
if (hasMoved && velocityMagnitude <= 0f) {
return TaskStatus.Failure;
}
hasMoved = velocityMagnitude > 0f;
}
return TaskStatus.Running;
}
// Flee in the opposite direction
private Vector3 Target()
{
return transform.position + (transform.position - target.Value.transform.position).normalized * lookAheadDistance.Value;
}
// Return false if the position isn't valid on the NavMesh.
protected override bool SetDestination(Vector3 destination)
{
if (!SamplePosition(destination)) {
return false;
}
return base.SetDestination(destination);
}
// Reset the public variables
public override void OnReset()
{
base.OnReset();
fleedDistance = 20;
lookAheadDistance = 5;
target = null;
}
}
}