protected void Start()
    {
        GameMgr.GetInstance().GetCustomMgrs().Register(this);
        GameObject[] waypoints = GameObject.FindGameObjectsWithTag(WayPointTag);
        _waypointList = new Map(waypoints.Length);
        _navigation   = new List <WayPoint>();
        for (int i = 0; i < waypoints.Length; ++i)
        {
            WayPoint       wp  = waypoints[i].GetComponent <WayPoint>();
            WayPointStruct wps = new WayPointStruct(wp.ID, wp.transform.position);
            _waypointList.Add(ref wps);
            _navigation.Add(wp);
        }

        for (int i = 0; i < waypoints.Length; ++i)
        {
            WayPoint       wp         = waypoints[i].GetComponent <WayPoint>();
            WayPoint[]     neighborns = wp.getNeighbors();
            WayPointStruct wps        = _waypointList[wp.ID];
            for (int j = 0; j < neighborns.Length; ++j)
            {
                WayPoint neighborn = neighborns[j];
                wps.AddNeighborn(neighborn.ID);
                WayPointStruct neighbornStatic = _waypointList[neighborn.ID];
                neighbornStatic.AddNeighborn(wps.ID);
                _waypointList[neighborn.ID] = neighbornStatic;
            }
            _waypointList[wp.ID] = wps;
        }

        /*if (_buildNavigationMapAutomatic)
         *              BuildNavigationPaths();*/
    }
Exemple #2
0
    public float GetCostFromThisPath(int current, int child)
    {
        //float gCostFromThisPath = current.GetG() + current.CalcF(child);
        WayPointStruct wp = _waypoints[current];
        float          f  = wp.CalcF(_waypoints[child].Position);

        return(wp.G + f);
    }
Exemple #3
0
    public void set(int i, float g, int parent, int target)
    {
        WayPointStruct wp = _waypoints[i];

        wp.G          = g;
        wp.Parent     = parent;
        wp.H          = wp.CalcF(_waypoints[target].Position);
        _waypoints[i] = wp;
    }
Exemple #4
0
 private int ReconstructPath(int final, int count)
 {
     if (final > 0)
     {
         WayPointStruct wp = _map[final];
         _path[count] = wp.Position;
         return(ReconstructPath(wp.Parent, count + 1));
     }
     else
     {
         return(count);
     }
 }
Exemple #5
0
    public bool NeedUpdatePath(int current, int child, bool wpChildIsClose, bool wpChildIsOpen, out float gCostFromThisPath)
    {
        WayPointStruct wpCurrent = _waypoints[current];
        WayPointStruct wpChild   = _waypoints[child];
        float          f         = wpCurrent.CalcF(wpChild.Position);

        gCostFromThisPath = wpCurrent.G + f;

        if (!(wpChildIsClose && gCostFromThisPath >= wpChild.G))
        {
            //Si el nodo seleccionado no está en la lista de _abierta o el coste del seleccionado por el camino
            // actual es menor que el coste anterior....
            return((!wpChildIsOpen) || (gCostFromThisPath < wpChild.G));
        }

        return(false);
    }
Exemple #6
0
 public void Add(ref WayPointStruct w)
 {
     _waypoints[w.ID] = w;
 }