ObjectRemover

Updated on August 4, 2022

public void RemoveObject(GameObject objToRemove, GridObject.Data gridObjectData)

This function removes the given objToRemove using the gridObjectData to find the grid and checkPositions to unblock.

Currently gridObjectData is formulated at placement time and fairly troublesome to replicate. If you want to remove objects from the grid via code, consider using the below method.

public void RemoveObject(GameObject objToRemove, List checkPositions, GridSquare grid)

This version of the RemoveObject unblocks the cell at the checkPositions on grid and destroys the objToRemove.

public Button btn;
public ObjectRemover objectRemover;

btn.onClick.AddListener(() =>
{
    objectRemover.RemoveObject(removeObj, 
    removeObj.GetComponent<GridObject>().data.CheckPositions, 
    removeObj.GetComponent<GridObject>().data.GridSquare);
});

public void RemoveObjectsOfType(int prefabId = 0)

Given a prefabId, which is set via the SelectObject btn, will destroy all objects placed with that prefabId.

Note, this method does not unblock cells, only destroys the GameObjects. You will need to call ObjectStorage.GetObjectsOfType to get a List of all the GameObjects first and unblock all cells before calling this method.

public Button btn;
public ObjectRemover objectRemover;

btn.onClick.AddListener(() =>
{
    //Removes all placed objects with given prefabId of 1
    objectRemover.RemoveObjectsOfType(1);
});

public void RemoveObjectByInstanceId(string id)

Given a unique id which is set upon object creation via the ObjectPlacer, destroys that particular object.

Note, this method does not unblock cells, only destroys the GameObject. You will need to call search the Dictionary GOInstanceList in ObjectStorage to get the GameObject first and unblock all cells before calling this method.

public Button btn;
public ObjectRemover objectRemover;
GameObject objToRemove;

btn.onClick.AddListener(() =>
{
    //Removes the object with the given InstanceId
    objectRemover.RemoveObjectByInstanceId(objectToRemove.getComponent<GridObject>().data.InstanceId);
});

public void UnblockCells(List checkPositions, GridSquare grid)

Unblocks the cells with the given checkPositions on the given grid.

Still need help? Contact support at support@golemitegames.com

Please describe your issue in detail and if possible, provide screenshots to help us understand your problem better and answer your question more effectively.