Would anyone be able to explain the approach of creating a list in this function within the SpinAction script? I’ve never seen, nor used this way before.
public override List<GridPosition> GetValidActionGridPositionList()
{
GridPosition unitGridPosition = unit.GetGridPosition();
return new List<GridPosition>
{
unitGridPosition
};
}
Am I right in thinking that it’s another form of:
listName.Add(value);
Any help would be appreciated, and I apologise if this is such a basic thing.
Yup exactly, that’s just the syntax for creating and immediately adding elements to the list, it constructs the object then adds any elements inside the { } code block, you can even add multiple and separate them with a comma { element1, element2 }
The end result is the exact same as
List<GridPosition> gridPositionList = new List<GridPosition>();
gridPositionList.Add(unitGridPosition);
return gridPositionList;