private void ReturnInternalOccupant(InternalOccupant occupant) { _occupants.Remove(occupant); occupant.DestroyVisuals(); occupant.Vacate(); occupant.Track(null); _occupantPool.ReturnObject(occupant); }
private InternalOccupant CreateInternalOccupant(Vector3 pos, GameObject tracked, int magnitude) { InternalOccupant o = _occupantPool.GetObject(); using (IntVector2 grid = _intVectorPool.GetObject()) { PositionToGrid(pos, grid); o.Track(tracked); o.SetMagnitude(magnitude); o.Update(grid, (tracked == null) ? DestinationTilePrefab : OccupiedTilePrefab); } _occupants.Add(o); return(o); }
public int GridDistanceBetweenOccupants(Occupant a, Occupant b, int maxDistance) { int distance = 0; InternalOccupant occupantA = a as InternalOccupant; InternalOccupant occupantB = b as InternalOccupant; if (occupantA == null || occupantB == null) { Debug.LogWarning("One of these occupants is null wtf!"); } if (occupantA.TrackedGameObject == null || occupantB.TrackedGameObject == null) { Debug.LogWarning("Unable to calculate grid distances between two occupants that do not track GameObjects"); return(-1); } distance = GridDistanceBetweenVectors(occupantA.TrackedGameObject.transform.position, occupantB.TrackedGameObject.transform.position, maxDistance); return(distance); }
private bool IsOccupied(int sig, params object[] filters) { List <int> occupants = null; bool exists = _occupantBuckets.TryGetValue(sig, out occupants); if (!exists) { return(false); } int numOccupants = occupants.Count; for (int i = 0; i < filters.Length; ++i) { InternalOccupant occupant = filters [i] as InternalOccupant; if (occupant != null && occupants.Contains(occupant.ID)) { numOccupants--; } } return(numOccupants > 0); }
// Create a reservation on a single grid space in the grid // pos - The position in world space of the grid you want to reserve public Reservation CreateReservation(Vector3 pos) { InternalOccupant o = CreateInternalOccupant(pos, null, 0); return((Reservation)o); }
// Create an occupant on the grid with a given magnitude (number of rings to occupy) // Occupants track the position of the given GameObject, and will send the "OnGridChanged" message // to the GameObject if its grid position changes. // thing - The GameObject that this Occupant is tracking // magnitude - The number of rings to occupy around the central hex public Occupant CreateOccupant(GameObject thing, int magnitude) { InternalOccupant o = CreateInternalOccupant(thing.transform.position, thing, magnitude); return((Occupant)o); }