GridSelector

Updated on August 1, 2022

public void ShowHideSelectorAndPreview()

This will force the grid selector to check again if cells are valid for placement for the current positions. It is called on every cell move, and after certain actions such as placing and removing objects.

Use this function when you need to manually recheck cell validity.

public void PlaceObjectIfEmpty(GridSquare currentGrid)

This function will set up the data necessary for the ObjectPlacer. This function uses a lot of data stored at the time of calling SetGameObjectToPlace as well as positional and rotational data stored in the GridSelector.

If you are calling this outside of using SetGameObjectToPlace some of the data stored may not be null.

This function also checks when calling if the cells are clear to place.

public void ChangeObjMat(GameObject obj, Material newMat)

This will loop through all children of the obj including itself and through all assigned materials and assign the newMat to each of them.

//Changes the obj material to something else.
GridSelector gridSelector;

void Start() 
{
    gridSelector.ChangeObjMat(myObjectToChange, invalidMaterial);
} 

public void ChangePreviewObjLayer(GameObject obj, int newLayer)

This changes the given obj and its children to layer newLayer.

public void DeselectPreview()

This function destroys the preview object from the hierarchy and sets the object to place as null.

//Remove the previewing of the object assigned when pressing escape.
GridSelector gridSelector;

void Update() 
{
    if(Input.GetKeyDown(KeyCode.Escape))
    {
        gridSelector.DeselectPreview();
    } 
}

public void SetGameObjectToPlace(GameObject obj, SelectObject.ObjectSize objSize = null, bool moveOnPoints = false, int id = 0, int buildTime = 0, string instanceId = null)

This takes in the obj, and sets it for the Grid Selector to preview and place the object.

Most of the parameters here are optional, however it is best used from a SelectObject button for best results as all of the information will be sent. See Setting up the SelectObject button.

//Takes an object from a button to place on the grid selector.
GridSelector gridSelector;

//The prefab to send to the grid selector to place
public GameObject prefab;

void Awake() 
{
    btn = GetComponent<Button>();
}
void Start() 
{
    btn.onClick.AddListener(() => {
        gridSelector.SetGameObjectToPlace(prefab); 
    });
}

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.