示例#1
0
        public Route GetRoute(Vector3 start, Vector3 goal, float minSize)
        {
            Route route = new Route();

            NavTree[] sorted = new NavTree[trees.Count];
            trees.CopyTo(sorted);
            sorted = sorted.OrderBy(t => (t.position - start).sqrMagnitude).ToArray();

            for (int i = 0; i < sorted.Length; i++)
            {
                NavTree   t       = sorted[i];
                Vector3[] clipped = sorted[i].GetIntersectPoints(start, goal);
                if (clipped.Length > 0)
                {
                    Route clipRoute = navigator.GetRoute(t, clipped[0], clipped[1], minSize);
                    clipRoute.points.Reverse();
                    route.Append(clipRoute);
                    // t.DrawNode(t.root, new Color32((byte) (75 + i * 50), 125, 125, 255));
                }
            }

            NavTree endTree = GetTreeAt(goal);

            if (endTree == null)
            {
                Route offTreeEnd = new Route();
                offTreeEnd.points.Add(new NavPoint(goal));
                route.Append(offTreeEnd);
            }

            return(route);
        }
示例#2
0
        public SpatialNode(Vector3 position, float size, int[] path, SpatialNode parent, NavTree tree)
        {
            this.position = position;
            this.size     = size;
            this.path     = path;
            this.parent   = parent;
            this.tree     = tree;

            BuildInitial();

            ancestorPaths = new Dictionary <string, Func <bool> >()
            {
                { "y+", Top },
                { "y-", Bottom },
                { "x+", Right },
                { "x-", Left },
                { "z+", Front },
                { "z-", Back },
            };

            shift = new Dictionary <string, Func <int, int> >()
            {
                { "x+", ShiftX },
                { "x-", ShiftX },
                { "y+", ShiftY },
                { "y-", ShiftY },
                { "z+", ShiftZ },
                { "z-", ShiftZ },
            };
        }
示例#3
0
 void Start()
 {
     // if (tryLoad && FileExists()) {
     //     LoadFromFile();
     // } else {
     //     tree = new NavTree(maxNodeSize, maxTreeDepth, transform.position);
     // }
     tree = new NavTree(maxNodeSize, maxTreeDepth, transform.position);
 }
示例#4
0
 public void LoadFromFile()
 {
     Debug.Log("loading tree from file...");
     using (
         var reader = new BinaryReader(File.Open(savePath, FileMode.Open))
         ) {
         tree = new NavTree(maxNodeSize, maxTreeDepth, transform.position, new NavTreeReader(reader));
         Debug.Log("NavTree loaded from file: " + savePath + "!");
     }
 }
示例#5
0
 public void HighlightChildren(NavTree t, SpatialNode n)
 {
     t.DrawNode(n);
     if (n != null && n.children != null)
     {
         for (int i = 0; i < n.children.Length; i++)
         {
             HighlightChildren(t, n.children[i]);
         }
     }
 }
示例#6
0
        public SpatialNode(Vector3 position, float size, int[] path, SpatialNode parent, NavTree tree, List <Vector3> vertices)
        {
            this.position = position;
            this.size     = size;
            this.path     = path;
            this.parent   = parent;
            this.tree     = tree;

            Build(vertices);

            InitializeAncestors();
        }
示例#7
0
 public void BuildAndSave()
 {
     savePath = Navigation.Config.NavTreeSavePath + fileName + Navigation.Config.NavTreeExtention;
     Debug.Log("Saving NavTree " + name + " to file: " + savePath);
     tree = new NavTree(maxNodeSize, maxTreeDepth, transform.position);
     using (
         var writer = new BinaryWriter(File.Open(savePath, FileMode.Create))
         ) {
         tree.Save(new NavTreeWriter(writer));
         Debug.Log("NavTree Saved!");
     }
 }
示例#8
0
 public SpatialNode(NavTreeReader reader, SpatialNode parent, NavTree tree)
 {
     this.tree = tree;
     if (parent != null)
     {
         Load(reader, parent);
     }
     else
     {
         Load(reader);
     }
     InitializeAncestors();
 }
示例#9
0
 public NavPoint(INavigable node, INavigableCollection tree)
 {
     if (node.GetType() == typeof(SpatialNode))
     {
         this.path     = ((SpatialNode)node).path;
         this.tree     = (NavTree)tree;
         this.position = node.Position();
     }
     else
     {
         this.position = node.Position();
     }
 }
示例#10
0
 public void RemoveNavTree(NavTree tree)
 {
     trees.Remove(tree);
 }
示例#11
0
 public void AddNavTree(NavTree tree)
 {
     trees.Add(tree);
 }
示例#12
0
 public NavPoint(int[] path, NavTree tree)
 {
     this.path = path;
     this.tree = tree;
     position  = this.tree.NodeAtPath(this.path).position;
 }