ObjectPlacer

Updated on August 2, 2022

public GameObject PlaceObject(GameObject obj, GridObject.Data gridObjectData, int layer)

Uses all of the data passed from the GridSelector to place an object on the grid.

This function is primarily used by the GridSelector and currently the class GridObject.Data is very tricky to replicate the relevant information publicly.

If your goal is to place objects with a single cell size only, you could potentially use the below overloaded version of this method.

public void PlaceObject(GameObject obj, Vector3 placePos, GridSquare grid, int layer)

This function places the object on the grid and changes the layer back to the original layer the object was on. You will need the obj, its position to place it, the grid to change the cell status and the object’s original layer.

It also adds the GridObject script to it, to keep a reference to the grid it is on.

Note – This overloaded version of PlaceObject only supports placing objects a single cell big and is also not added to the ObjectStorage.

//Places an obj on left mouse click
ObjectPlacer objectPlacer;
GridSquare grid;
public GameObject myObject;

void Update()
{
    if (Input.GetMouseButton(0)) 
    {
        objectPlacer.PlaceObject(myObject, posToPlace, grid, myObject.layer)
    }
}

public GameObject DelayBuildStart(GameObject obj, GridObject.Data gridObjectData, int layer, int buildTime)

Uses all of the data passed from the GridSelector to place a temperory timed object on the grid. This only works if the time set in the SelectObject button is more than 0.

This function is primarily used by the GridSelector and currently the class GridObject.Data is very tricky to replicate the relevant information publicly.

public void MoveObject(GameObject obj, GridObject.Data gridObjectData, int layer)

Uses all of the data passed from the GridSelector to move an object on the grid.

This function is primarily used by the GridSelector and currently the class GridObject.Data is very tricky to replicate the relevant information publicly.

If you would like to move objects to a particular position on the grid, consider using the below version of MoveObject.

public void MoveObject(GameObject obj, Vector3 pos, GridSquare grid, int layer)

Moves the given obj to position pos on grid. It will also place the given layer on it and its children.

Please note that when moving an object, you are only moving it visually. To move it on the system as well you will need to call BlockCells.

ObjectPlacer objectPlacer;
GridSquare grid;
public GameObject myObject;
public GameObject placedObj;

//Moves the placed object if its position matches your current objects pos
void Update()
{
    if (myObject.transorm.position == placedObj.transform.position) 
    {
        objectPlacer.MoveObject(placedObj, posToMoveTo, grid, myObject.layer)
    }
}

public List GetSpecificCheckPositions(Vector3[] checkPositions, SelectObject.ObjectSize objectSize)

This function returns a List<Vector3> of the objects check positions that actually need blocking.

From the GridSelector there is an array called gridCheckPositions for all current check positions of up to 5×5 grid. There is also the SelectObject.ObjectSize which holds that objects physical size. Because we only want to block that objects size on those particular check positions, this function sorts and returns that List.

public void BlockCells(List checkPositions, GameObject obj, GridSquare grid)

Given an array of checkPositions to block, loops through them all, and changes that grid cell’s status to be marked with the given obj.

public void HidePlacedObjCells(GridSquare gridSquare, List checkPositions)

Hides the given checkPositions cells on gridSquare.

This method does not work for grid types Simple, Points or Lines.

public void ShowRemovedObjCells(GridSquare gridSquare, List checkPositions)

Shows the given checkPositions cells on gridSquare.

This method does not work for grid types Simple, Points or Lines.

public float GetObjectHeight(GameObject obj)

Given an obj returns the objects height based on its collider.

This method is mostly used to decide whereabouts a UI element should appear above the object.

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.