Beispiel #1
0
 public override void OnEnter()
 {
     if (graph.Value != null && (graph.Value as FsmNavGraph).Value != null)
     {
         var g = (graph.Value as FsmNavGraph).Value as NavGraph;
         AstarPathExtensions.ScanGraph(g);
     }
     Finish();
 }
Beispiel #2
0
        public void DoStuff()
        {
            var go = gameObject.OwnerOption == OwnerDefaultOption.UseOwner ? Owner : gameObject.GameObject.Value;

            g.root           = go.transform;      // set the root so the scan will turn it into nodes
            g.maxDistance    = maxDistance.Value; // set max distance for connection
            g.initialPenalty = (uint)cost.Value;
            g.name           = name.Value;
            AstarPathExtensions.ScanGraph(g);              // turn the gameObjects into ndoes.

            Nodes.Value = FsmConverter.SetNodes(FsmConverter.NodeListToArray(g.nodes));
            AstarPath.active.FloodFill();
            return;
        }
        public void DoStuff()
        {
            var a = g.CreateNodes(number.Value);

            nodes.Value = new FsmNodes();

            (nodes.Value as FsmNodes).Value = (List <Node>)FsmConverter.NodeListToArray(a);

            //	g.nodes += a;

            //	AstarPath.active.NodeCountChanged() ;

            AstarPathExtensions.ScanGraph(g);
        }
        public void DoStuff()
        {
            var go = gameObject.OwnerOption == OwnerDefaultOption.UseOwner ? Owner : gameObject.GameObject.Value;

            g.root           = go.transform; // set the root so the scan will turn it into nodes
            g.maxDistance    = -1;           // no autoconnect
            g.initialPenalty = (uint)cost.Value;
            g.name           = name.Value;
            AstarPathExtensions.ScanGraph(g);              // turn the gameObjects into ndoes.

            if (width.Value <= 1)
            {
                for (var i = 1; i < g.nodes.Length; i++)
                {
                    // connect the node with the previously created node
                    g.nodes[i].AddConnection(g.nodes[i - 1], cost.Value);
                    g.nodes[i - 1].AddConnection(g.nodes[i], cost.Value);
                }

                if (connectStart.Value || connectEnd.Value)
                {
                    // You would want to use an NNConstraint to ignore this graph when searching (graphMask)
                    // Since it currently will find g.nodes[0] when searching
                    nnc = NNConstraint.Default;
                    var nncSave = nnc.graphMask;
                    var index   = AstarPath.active.astarData.GetGraphIndex(g);
                    nnc.graphMask = ~(1 << index);

                    if (connectStart.Value)
                    {
                        connectEm(0);
                    }
                    if (connectEnd.Value)
                    {
                        connectEm(g.nodes.Length - 1);
                    }
                    nnc.graphMask = nncSave;
                }
            }
            else
            {
                for (var i = 0; i < g.nodes.Length; i++)
                {
                    // connect the node with the previously created node
                    //g.nodes[i].AddConnection(g.nodes[i-1], cost.Value);
                    //g.nodes[i-1].AddConnection(g.nodes[i], cost.Value);
                    //if(i + width.Value <= g.nodes.Length)
                    //{
                    //connect the node with the next node in line
                    //g.nodes[i-1].AddConnection(g.nodes[i-1+width.Value], cost.Value);
                    //g.nodes[i-1+width.Value].AddConnection(g.nodes[i-1], cost.Value);
                    //}

                    // there are 3 scenarios: Either a node is in the middle or at either of the ends of the row.
                    if (i % width.Value == width.Value - 1)                     //2
                    {
                        if (i + width.Value < g.nodes.Length)
                        {
                            g.nodes[i].AddConnection(g.nodes[i + width.Value], cost.Value);
                            g.nodes[i + width.Value].AddConnection(g.nodes[i], cost.Value);
                        }

                        if (i + width.Value - 1 < g.nodes.Length)
                        {
                            g.nodes[i].AddConnection(g.nodes[i + width.Value - 1], cost.Value);
                            g.nodes[i + width.Value - 1].AddConnection(g.nodes[i], cost.Value);
                        }
                    }
                    else if (i == 0 || 0 == i % width.Value)                 //1 // if i is 0 or a multiple of width
                    {
                        if (i + width.Value < g.nodes.Length)
                        {
                            g.nodes[i].AddConnection(g.nodes[i + width.Value], cost.Value);
                            g.nodes[i + width.Value].AddConnection(g.nodes[i], cost.Value);
                        }
                        if (i + 1 < g.nodes.Length)
                        {
                            g.nodes[i].AddConnection(g.nodes[i + 1], cost.Value);
                            g.nodes[i + 1].AddConnection(g.nodes[i], cost.Value);
                        }
                        if (i + width.Value + 1 < g.nodes.Length)
                        {
                            g.nodes[i].AddConnection(g.nodes[i + width.Value + 1], cost.Value);
                            g.nodes[i + width.Value + 1].AddConnection(g.nodes[i], cost.Value);
                        }
                    }
                    else                     //3
                    {
                        if (i + width.Value < g.nodes.Length)
                        {
                            g.nodes[i].AddConnection(g.nodes[i + width.Value], cost.Value);
                            g.nodes[i + width.Value].AddConnection(g.nodes[i], cost.Value);
                        }

                        if (i + 1 < g.nodes.Length)
                        {
                            g.nodes[i].AddConnection(g.nodes[i + 1], cost.Value);
                            g.nodes[i + 1].AddConnection(g.nodes[i], cost.Value);
                        }

                        if (i + width.Value + 1 < g.nodes.Length)
                        {
                            g.nodes[i].AddConnection(g.nodes[i + width.Value + 1], cost.Value);
                            g.nodes[i + width.Value + 1].AddConnection(g.nodes[i], cost.Value);
                        }

                        if (i + width.Value - 1 < g.nodes.Length)
                        {
                            g.nodes[i].AddConnection(g.nodes[i + width.Value - 1], cost.Value);
                            g.nodes[i + width.Value - 1].AddConnection(g.nodes[i], cost.Value);
                        }
                    }
                }

                if (connectStart.Value || connectEnd.Value)
                {
                    // You would want to use an NNConstraint to ignore this graph when searching (graphMask)
                    // Since it currently will find g.nodes[0] when searching
                    nnc = NNConstraint.Default;
                    var nncSave = nnc.graphMask;
                    var index   = AstarPath.active.astarData.GetGraphIndex(g);
                    nnc.graphMask = ~(1 << index);

                    if (connectStart.Value)
                    {
                        connectEm(0);
                    }
                    if (connectEnd.Value)
                    {
                        connectEm(g.nodes.Length - width.Value);
                    }

                    nnc.graphMask = nncSave;
                }
            }

            Nodes.Value = FsmConverter.SetNodes(FsmConverter.NodeListToArray(g.nodes));

            //Required since the graph connections have been updated
            AstarPath.active.FloodFill();

            //g.AddChildren(Count, go.transform);
            return;
        }