示例#1
0
    /// <summary>
    /// Efficient way of iterating through the register tiles at a particular position which
    /// also is safe against modifications made to the list of tiles while the action is running.
    /// The limitation compared to Get<> is it can only get RegisterTiles, but the benefit is it avoids
    /// GetComponent so there's no GC. The OTHER benefit is that normally iterating through these
    /// would throw an exception if the RegisterTiles at this position were modified, such as
    /// being destroyed are created within the specified action. This method uses a locking mechanism to avoid
    /// such issues - it's safe to add / remove register tiles.
    /// </summary>
    /// <param name="localPosition"></param>
    /// <returns></returns>
    public void ForEachSafe(IRegisterTileAction action, Vector3Int localPosition)
    {
        if (lockedPosition != null && lockedPosition != localPosition)
        {
            Logger.LogErrorFormat("Tried to lock tile at position {0} while position {1} is currently locked." +
                                  " TileList only supports locking one position at a time. Please add this locking capability" +
                                  " to TileList if it is really necessary. Action will be skipped", Category.Matrix, localPosition, lockedPosition);
            return;
        }

        lockedPosition = localPosition;
        foreach (var registerTile in Get(localPosition))
        {
            action.Invoke(registerTile);
        }
        lockedPosition = null;

        foreach (var queuedOp in queuedOps)
        {
            if (queuedOp.Remove)
            {
                Remove(queuedOp.Position, queuedOp.RegisterTile);
            }
            else
            {
                Add(queuedOp.Position, queuedOp.RegisterTile);
            }
        }

        queuedOps.Clear();
    }
示例#2
0
 public void InvokeOnObjects(IRegisterTileAction action, Vector3Int localPosition)
 {
     TempRegisterTiles.Clear();
     TempRegisterTiles.AddRange(Get(localPosition));
     foreach (var registerTile in TempRegisterTiles)
     {
         if (registerTile != null)             //explosions can delete many objects in this tile!
         {
             action.Invoke(registerTile);
         }
     }
 }
示例#3
0
    public void InvokeOnObjects(IRegisterTileAction action, Vector3Int localPosition)
    {
        TempRegisterTiles.Clear();
        TempRegisterTiles.AddRange(Get(localPosition));

        for (int i = TempRegisterTiles.Count - 1; i >= 0; i--)
        {
            if (TempRegisterTiles[i] != null)             //explosions can delete many objects in this tile!
            {
                action.Invoke(TempRegisterTiles[i]);
            }
        }
    }