Пример #1
0
        public Spot AssignSpot(Surrounder surrounder)
        {
            Vector3 arrivalPosition = surrounder.transform.position - transform.position;
            float   angle           = Util.FullAngle(new Vector2(arrivalPosition.x, arrivalPosition.z));
            int     closest         = (int)Mathf.Round((angle / (Mathf.PI * 2)) * Spots.Length) % Spots.Length;

            for (int i = 0; i <= Spots.Length; i++)
            {
                int index = (closest + i) % Spots.Length;
                if (!Spots[index].IsOccupied)
                {
                    Spots[index].SetOccupier(surrounder);
                    if (OnSpotTaken != null)
                    {
                        OnSpotTaken(Spots[index], surrounder);
                    }
                    return(Spots[index]);
                }

                index = ((closest - i) + Spots.Length) % Spots.Length;
                if (!Spots[index].IsOccupied)
                {
                    Spots[index].SetOccupier(surrounder);
                    if (OnSpotTaken != null)
                    {
                        OnSpotTaken(Spots[index], surrounder);
                    }
                    return(Spots[index]);
                }
            }

            return(null);
        }
Пример #2
0
        public void ReleaseSpot(Spot spot)
        {
            Surrounder released = spot.Occupier;

            spot.GetReleased();
            if (released != null && OnSpotFreed != null)
            {
                OnSpotFreed(spot, released);
            }
        }
Пример #3
0
 public void SetOccupier(Surrounder occupier)
 {
     if (Occupier != null)
     {
         Debug.LogWarning("spot was not empty");
     }
     else
     {
         Occupier = occupier;
     }
 }
Пример #4
0
 public void GetReleased()
 {
     Occupier = null;
 }