[Player] Add AI Pathfinding on a 2D grid to the player character

This commit is contained in:
Michal Pikulski
2025-09-02 11:42:25 +02:00
parent 3d3b72f04d
commit e53b5a0034
663 changed files with 148320 additions and 66 deletions

View File

@@ -0,0 +1,89 @@
using UnityEngine;
namespace Pathfinding {
/// <summary>
/// Base for all path modifiers.
/// See: MonoModifier
/// Modifier
/// </summary>
public interface IPathModifier {
int Order { get; }
void Apply(Path path);
void PreProcess(Path path);
}
/// <summary>
/// Base class for path modifiers which are not attached to GameObjects.
/// See: MonoModifier
/// </summary>
[System.Serializable]
public abstract class PathModifier : IPathModifier {
[System.NonSerialized]
public Seeker seeker;
/// <summary>
/// Modifiers will be executed from lower order to higher order.
/// This value is assumed to stay constant.
/// </summary>
public abstract int Order { get; }
public void Awake (Seeker seeker) {
this.seeker = seeker;
if (seeker != null) {
seeker.RegisterModifier(this);
}
}
public void OnDestroy (Seeker seeker) {
if (seeker != null) {
seeker.DeregisterModifier(this);
}
}
public virtual void PreProcess (Path path) {
// Required by IPathModifier
}
/// <summary>Main Post-Processing function</summary>
public abstract void Apply(Path path);
}
/// <summary>
/// Base class for path modifiers which can be attached to GameObjects.
/// See: Menubar -> Component -> Pathfinding -> Modifiers
/// </summary>
[System.Serializable]
public abstract class MonoModifier : VersionedMonoBehaviour, IPathModifier {
[System.NonSerialized]
public Seeker seeker;
/// <summary>Alerts the Seeker that this modifier exists</summary>
protected virtual void OnEnable () {
seeker = GetComponent<Seeker>();
if (seeker != null) {
seeker.RegisterModifier(this);
}
}
protected virtual void OnDisable () {
if (seeker != null) {
seeker.DeregisterModifier(this);
}
}
/// <summary>
/// Modifiers will be executed from lower order to higher order.
/// This value is assumed to stay constant.
/// </summary>
public abstract int Order { get; }
public virtual void PreProcess (Path path) {
// Required by IPathModifier
}
/// <summary>Called for each path that the Seeker calculates after the calculation has finished</summary>
public abstract void Apply(Path path);
}
}