123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- using UnityEngine;
- using System.Collections.Generic;
- using Pathfinding.Util;
- namespace Pathfinding {
- [AddComponentMenu("Pathfinding/Modifiers/Funnel")]
- [System.Serializable]
-
-
-
-
-
-
-
-
-
-
-
-
- [HelpURL("http://arongranberg.com/astar/documentation/stable/class_pathfinding_1_1_funnel_modifier.php")]
- public class FunnelModifier : MonoModifier {
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- public bool unwrap = true;
-
-
-
-
-
-
- public bool splitAtEveryPortal;
- #if UNITY_EDITOR
- [UnityEditor.MenuItem("CONTEXT/Seeker/Add Funnel Modifier")]
- public static void AddComp (UnityEditor.MenuCommand command) {
- (command.context as Component).gameObject.AddComponent(typeof(FunnelModifier));
- }
- #endif
- public override int Order { get { return 10; } }
- public override void Apply (Path p) {
- if (p.path == null || p.path.Count == 0 || p.vectorPath == null || p.vectorPath.Count == 0) {
- return;
- }
- List<Vector3> funnelPath = ListPool<Vector3>.Claim();
-
-
- var parts = Funnel.SplitIntoParts(p);
- if (parts.Count == 0) {
-
-
-
-
-
-
- return;
- }
- for (int i = 0; i < parts.Count; i++) {
- var part = parts[i];
- if (!part.isLink) {
- var portals = Funnel.ConstructFunnelPortals(p.path, part);
- var result = Funnel.Calculate(portals, unwrap, splitAtEveryPortal);
- funnelPath.AddRange(result);
- ListPool<Vector3>.Release(ref portals.left);
- ListPool<Vector3>.Release(ref portals.right);
- ListPool<Vector3>.Release(ref result);
- } else {
-
-
-
- if (i == 0 || parts[i-1].isLink) {
- funnelPath.Add(part.startPoint);
- }
- if (i == parts.Count - 1 || parts[i+1].isLink) {
- funnelPath.Add(part.endPoint);
- }
- }
- }
- UnityEngine.Assertions.Assert.IsTrue(funnelPath.Count >= 1);
- ListPool<Funnel.PathPart>.Release(ref parts);
-
- ListPool<Vector3>.Release(ref p.vectorPath);
- p.vectorPath = funnelPath;
- }
- }
- }
|