breakpoint
before update unity version
This commit is contained in:
@@ -13,19 +13,16 @@ namespace BITKit.Scene
|
||||
[SerializeField] private IEntitiesService _entitiesService;
|
||||
[SerializeField] private CinemachineTargetGroup targetGroup;
|
||||
[SerializeField] private Optional<Entity[]> initialEntities;
|
||||
[SerializeField] private bool removeOnEliminate;
|
||||
private void Update()
|
||||
{
|
||||
// foreach (var x in initialEntities.IfNotAllow(()=>_entitiesService.Query<IHealth>().Cast<Entity>().ToArray()))
|
||||
// {
|
||||
//
|
||||
// }
|
||||
targetGroup.m_Targets =
|
||||
initialEntities.IfNotAllow(() => _entitiesService.Query<IHealth>().Cast<Entity>().ToArray())
|
||||
.Select(x => new CinemachineTargetGroup.Target()
|
||||
{
|
||||
target = x.transform,
|
||||
radius = 1,
|
||||
weight = x.TryGetComponent<IHealth>(out var heal) ? heal.IsAlive ? 1 : 0 : 0
|
||||
weight =removeOnEliminate ? x.TryGetComponent<IHealth>(out var heal) ? heal.IsAlive ? 1 : 0 : 0 : 1
|
||||
})
|
||||
.ToArray();
|
||||
if (targetGroup.m_Targets.Length is 0)
|
||||
|
@@ -0,0 +1,12 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace BITKit.NodeCanvas
|
||||
{
|
||||
|
||||
}
|
||||
public class FindCoverPoint : MonoBehaviour
|
||||
{
|
||||
|
||||
}
|
@@ -0,0 +1,130 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using NodeCanvas.Framework;
|
||||
using ParadoxNotion.Design;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AI;
|
||||
|
||||
namespace BITKit.NodeCanvas.Pathfinding
|
||||
{
|
||||
[Category("Movement/Pathfinding")]
|
||||
[Description("Makes the agent wander randomly within the navigation map")]
|
||||
public class AIWander : ActionTask<NavMeshAgent>
|
||||
{
|
||||
[Tooltip("The speed to wander with.")]
|
||||
public BBParameter<float> speed = 4;
|
||||
[Tooltip("The distance to keep from each wander point.")]
|
||||
public BBParameter<float> keepDistance = 0.1f;
|
||||
[Tooltip("A wander point can't be closer than this distance")]
|
||||
public BBParameter<float> minWanderDistance = 5;
|
||||
[Tooltip("A wander point can't be further than this distance")]
|
||||
public BBParameter<float> maxWanderDistance = 20;
|
||||
[Tooltip("If enabled, will keep wandering forever. If not, only one wander point will be performed.")]
|
||||
public bool repeat = true;
|
||||
[Tooltip("If enabled,will execute a move and exit")]
|
||||
public bool forget;
|
||||
|
||||
private Vector3? lastPosition;
|
||||
private readonly IntervalUpdate newPositionInterval=new (1);
|
||||
|
||||
private int newTargetCount;
|
||||
|
||||
protected override void OnExecute() {
|
||||
agent.speed = speed.value;
|
||||
|
||||
if (IsArrived is false)
|
||||
{
|
||||
if (lastPosition.HasValue &&
|
||||
Vector3.Distance(agent.pathEndPosition, lastPosition.Value) <= keepDistance.value)
|
||||
{
|
||||
newPositionInterval.Reset();
|
||||
EndAction();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
DoWander();
|
||||
}
|
||||
|
||||
protected override string info
|
||||
{
|
||||
get
|
||||
{
|
||||
reportBuilder.Clear();
|
||||
|
||||
reportBuilder.AppendLine(nameof(AIWander));
|
||||
reportBuilder.AppendLine($"NewTargetCount:{newTargetCount}");
|
||||
reportBuilder.AppendLine($"LastPosition:{lastPosition}");
|
||||
reportBuilder.AppendLine($"RemainDistance:{agent.remainingDistance}");
|
||||
return reportBuilder.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
private readonly StringBuilder reportBuilder = new();
|
||||
|
||||
protected override void OnUpdate() {
|
||||
if ( IsArrived ) {
|
||||
if ( repeat ) {
|
||||
DoWander();
|
||||
} else {
|
||||
EndAction();
|
||||
}
|
||||
|
||||
lastPosition = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (forget)
|
||||
{
|
||||
EndAction();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool IsArrived => !agent.pathPending && agent.remainingDistance <= agent.stoppingDistance + keepDistance.value;
|
||||
|
||||
void DoWander() {
|
||||
var min = minWanderDistance.value;
|
||||
var max = maxWanderDistance.value;
|
||||
min = Mathf.Clamp(min, 0.01f, max);
|
||||
max = Mathf.Clamp(max, min, max);
|
||||
var wanderPos = agent.transform.position;
|
||||
|
||||
if (lastPosition.HasValue && newPositionInterval.AllowUpdateWithoutReset is false)
|
||||
{
|
||||
wanderPos = lastPosition.Value;
|
||||
|
||||
agent.SetDestination(wanderPos);
|
||||
}
|
||||
else
|
||||
{
|
||||
while ((wanderPos - agent.transform.position).magnitude < min)
|
||||
{
|
||||
wanderPos = (Random.insideUnitSphere * max) + agent.transform.position;
|
||||
}
|
||||
|
||||
NavMeshHit hit;
|
||||
if ( NavMesh.SamplePosition(wanderPos, out hit, agent.height * 2, NavMesh.AllAreas) ) {
|
||||
agent.SetDestination(hit.position);
|
||||
lastPosition = hit.position;
|
||||
newTargetCount++;
|
||||
newPositionInterval.Reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnPause() { OnStop(); }
|
||||
|
||||
protected override void OnStop()
|
||||
{
|
||||
if (agent.gameObject.activeSelf && agent.isOnNavMesh)
|
||||
{
|
||||
if (forget is false)
|
||||
agent.ResetPath();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user