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); }
public void ReleaseSpot(Spot spot) { Surrounder released = spot.Occupier; spot.GetReleased(); if (released != null && OnSpotFreed != null) { OnSpotFreed(spot, released); } }
public void SetOccupier(Surrounder occupier) { if (Occupier != null) { Debug.LogWarning("spot was not empty"); } else { Occupier = occupier; } }
public void GetReleased() { Occupier = null; }