From 8722a9920c1f6119bf6e769cba270e63097f8e25 Mon Sep 17 00:00:00 2001
From: chai <215380520@qq.com>
Date: Thu, 23 May 2024 10:08:29 +0800
Subject: + astar project
---
.../com.arongranberg.astar/Modifiers/Modifiers.cs | 89 ++++++++++++++++++++++
1 file changed, 89 insertions(+)
create mode 100644 Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/Modifiers/Modifiers.cs
(limited to 'Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/Modifiers/Modifiers.cs')
diff --git a/Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/Modifiers/Modifiers.cs b/Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/Modifiers/Modifiers.cs
new file mode 100644
index 0000000..23295f1
--- /dev/null
+++ b/Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/Modifiers/Modifiers.cs
@@ -0,0 +1,89 @@
+using UnityEngine;
+
+namespace Pathfinding {
+ ///
+ /// Base for all path modifiers.
+ /// See: MonoModifier
+ /// Modifier
+ ///
+ public interface IPathModifier {
+ int Order { get; }
+
+ void Apply(Path path);
+ void PreProcess(Path path);
+ }
+
+ ///
+ /// Base class for path modifiers which are not attached to GameObjects.
+ /// See: MonoModifier
+ ///
+ [System.Serializable]
+ public abstract class PathModifier : IPathModifier {
+ [System.NonSerialized]
+ public Seeker seeker;
+
+ ///
+ /// Modifiers will be executed from lower order to higher order.
+ /// This value is assumed to stay constant.
+ ///
+ 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
+ }
+
+ /// Main Post-Processing function
+ public abstract void Apply(Path path);
+ }
+
+ ///
+ /// Base class for path modifiers which can be attached to GameObjects.
+ /// See: Menubar -> Component -> Pathfinding -> Modifiers
+ ///
+ [System.Serializable]
+ public abstract class MonoModifier : VersionedMonoBehaviour, IPathModifier {
+ [System.NonSerialized]
+ public Seeker seeker;
+
+ /// Alerts the Seeker that this modifier exists
+ protected virtual void OnEnable () {
+ seeker = GetComponent();
+
+ if (seeker != null) {
+ seeker.RegisterModifier(this);
+ }
+ }
+
+ protected virtual void OnDisable () {
+ if (seeker != null) {
+ seeker.DeregisterModifier(this);
+ }
+ }
+
+ ///
+ /// Modifiers will be executed from lower order to higher order.
+ /// This value is assumed to stay constant.
+ ///
+ public abstract int Order { get; }
+
+ public virtual void PreProcess (Path path) {
+ // Required by IPathModifier
+ }
+
+ /// Called for each path that the Seeker calculates after the calculation has finished
+ public abstract void Apply(Path path);
+ }
+}
--
cgit v1.1-26-g67d0