示例#1
0
    public Vector3 GetTargetPosition()
    {
        PFStaticMap map   = _staticMaps[0];
        PFPosition  pfPos = map.WorldToMap(transform.position);

        int minX = Mathf.Max(0, pfPos.x - 1);
        int maxX = Mathf.Min(map.width - 1, pfPos.x + 1);
        int minY = Mathf.Max(0, pfPos.y - 1);
        int maxY = Mathf.Min(map.height - 1, pfPos.y + 1);

        PFPosition pfTargetPos  = pfPos;
        int        maxPotential = -100;

        // looping through the neibouring and the current grids
        for (int x = minX; x <= maxX; x++)
        {
            for (int y = minY; y <= maxY; y++)
            {
                int potential = GetStaticPotentialSum(x, y) + GetTrailPotentialSum(x, y);
                if (potential > maxPotential)
                {
                    maxPotential = potential;
                    pfTargetPos  = new PFPosition(x, y);
                }
            }
        }

        if (trailLength > 0)
        {
            _trail.Insert(0, new PFTrail(pfTargetPos.x, pfTargetPos.y, trailPotential));
            if (_trail.Count > trailLength)
            {
                _trail.RemoveAt(trailLength - 1);
            }
        }

        return(map.MapToWorld(pfTargetPos));
    }
示例#2
0
 void Awake()
 {
     instance   = this;
     _pfMap     = GetComponent <PFStaticMap>();
     _obstacles = new List <PFField>();
 }
示例#3
0
 public void AddStaticMap(PFStaticMap staticMap)
 {
     _staticMaps.Add(staticMap);
     _staticMapSwitches.Add(true);
 }