Basic API Documentation
In this guide, we will go through how to use Easy Grid Builder Pro API. And also this documentation will get updated when new functionalities are added.
01. Namespace
You need to add Easy Grid Builder Pro namespace in your scripts to use all its functionalities.
using SoulGames.EasyGridBuilderPro;
02. Access Grid Systems
Get a reference to all grids in the scene.
private List<EasyGridBuilderPro> easyGridBuilderProList;
private void Start()
{
easyGridBuilderProList = MultiGridManager.Instance.easyGridBuilderProList;
}
Get a reference to the currently active grid in the scene.
private EasyGridBuilderPro currentActiveSystem;
private void Update()
{
currentActiveSystem = MultiGridManager.Instance.activeGridSystem;
}
Example: Get a reference to a specific grid system by its name.
using SoulGames.EasyGridBuilderPro;
private List<EasyGridBuilderPro> easyGridBuilderProList;
private EasyGridBuilderPro specificGrid;
private string specificGridName;
private void Start()
{
easyGridBuilderProList = MultiGridManager.Instance.easyGridBuilderProList;
foreach (EasyGridBuilderPro easyGridBuilderPro in easyGridBuilderProList)
{
if(easyGridBuilderPro.name is specificGridName)
{
specificGrid = easyGridBuilderPro;
}
}
}
03. Public Get Functions
Example: Get a reference to the currently active grid's Grid Width. (When the key "Space" is pressed)
using SoulGames.EasyGridBuilderPro;
private EasyGridBuilderPro currentActiveSystem;
private int activeSystemGridWidth;
private void Update()
{
currentActiveSystem = MultiGridManager.Instance.activeGridSystem;
if (Input.GetKeyDown(KeyCode.Space))
{
activeSystemGridWidth = currentActiveSystem.GetGridWidth();
}
}
/// Returns grid system's GridMode. Takes no parameter.
currentActiveSystem.GetGridMode();
/// Returns grid system's GridAxis. Takes no parameter.
currentActiveSystem.GetGridAxis();
/// Returns grid system's GridWidth. Takes no parameter.
currentActiveSystem.GetGridWidth();
/// Returns grid system's GridLength. Takes no parameter.
currentActiveSystem.GetGridLength();
/// Returns grid system's CellSize. Takes no parameter.
currentActiveSystem.GetGridCellSize();
/// Returns grid system's GridOrigin. Takes no parameter.
currentActiveSystem.GetGridOrigin();
/// Returns current stored BuildableGridObjectTypeSOList. Takes no parameter.
currentActiveSystem.GetBuildableGridObjectTypeSOList();
/// Returns current stored BuildableGridObjectTypeSOList. Takes no parameter.
currentActiveSystem.GetBuildableFreeObjectTypeSOList();
/// Returns current active vertical grid system's grid index. Takes no parameter.
currentActiveSystem.GetActiveVerticalGridIndex();
/// Returns Bertical Grids Count. Takes no parameter.
currentActiveSystem.GetVerticalGridCount();
/// Returns grid system's GridHeight. Takes no parameter.
currentActiveSystem.GetGridHeight();
/// Returns grid system's Unique Save Name. Takes no parameter.
currentActiveSystem.GetUniqueSaveName();
/// Returns grid system's Save Location. Takes no parameter.
currentActiveSystem.GetSaveLocation();
/// Returns currently buildable, Buildable Grid Object Type SO. Takes no parameter.
currentActiveSystem.GetBuildableGridObjectTypeSO();
/// Returns currently buildable, Buildable Free Object Type SO. Takes no parameter.
currentActiveSystem.GetBuildableFreeObjectTypeSO();
/// Returns the Buildable Grid Object Type So by its name. Takes string parameter.
currentActiveSystem.GetBuildableGridObjectTypeSOFromName(string buildableGridObjectTypeSOName);
/// Returns the Buildable Free Object Type So by its name. Takes string parameter.
currentActiveSystem.GetBuildableFreeObjectTypeSOFromName(string buildableFreeObjectTypeSOName);
/// Returns the world position of a grid cell. Takes Vector2Int parameter.
currentActiveSystem.GetWorldPositionXZ(Vector2Int gridPosition)
currentActiveSystem.GetWorldPositionXY(Vector2Int gridPosition)
/// Returns the grid position of a grid cell (Grid Index). Takes Vector3 parameter.
currentActiveSystem.GetGridPositionXZ(Vector3 worldPosition)
currentActiveSystem.GetGridPositionXY(Vector3 worldPosition)
/// Returns the grid built object of a grid cell (Grid Index). Takes Vector3 parameter or Vector2Int parameter.
currentActiveSystem.GetGridObjectXZ(Vector3 worldPosition)
currentActiveSystem.GetGridObjectXZ(Vector2Int gridPosition)
currentActiveSystem.GetGridObjectXY(Vector3 worldPosition)
currentActiveSystem.GetGridObjectXY(Vector2Int gridPosition)
/// Returns true or false whether the grid cell index is inside the fixed grid or not. Takes Vector2Int parameter.
currentActiveSystem.IsValidGridPositionXZ(Vector2Int gridPosition)
currentActiveSystem.IsValidGridPositionXZ(Vector2Int gridPosition)
04. Public Set Functions
Example: Set all grids GridMode. (When the key "Space" is pressed)
using SoulGames.EasyGridBuilderPro;
private List<EasyGridBuilderPro> easyGridBuilderProList;
private GridMode gridMode = GridMode.None;
private void Start()
{
easyGridBuilderProList = MultiGridManager.Instance.easyGridBuilderProList;
}
private void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
foreach(EasyGridBuilderPro easyGridBuilderPro in easyGridBuilderProList)
{
easyGridBuilderPro.SetGridMode(gridMode);
}
}
}
/// Force set grid system's GridMode. Takes one parameter.
/// <param name="gridMode">GridMode enum value</param>
easyGridBuilderPro.SetGridMode(GridMode gridMode);
/// Set grid system's Vertical Grid. Takes one parameter.
/// <param name="currentActiveGridIndex">int Vertical Grid Index</param>
easyGridBuilderPro.SetActiveVerticalGrid(int currentActiveGridIndex);
/// Set grid system's Vertical Grid Auto Height Detect. Takes one parameter.
/// <param name="setActive">bool enable or disable</param>
easyGridBuilderPro.SetAutoDetectHeight(bool setActive);
/// Set grid system's Vertical Grid Change Height with Input. Takes one parameter.
/// <param name="setActive">bool enable or disable</param>
easyGridBuilderPro.SetChangeHeightWithInput(bool setActive);
/// Set grid system's UseBuildableDistance. Takes four parameters.
/// <param name="enable">Enable/Disable UseBuildableDistance</param>
/// <param name="objectTransform">Take object transform to distance check, default null</param>
/// <param name="distanceMin">Minimum distance</param>
/// <param name="distanceMax">Maximum distance</param>
easyGridBuilderPro.SetUseBuildableDistance(bool enable, Transform objectTransform, float distanceMin, float distanceMax);
/// Set Grid System's Unique Save Name. Takes one parameter.
/// <param name="uniqueSaveName">string unique save name</param>
currentActiveSystem.SetUniqueSaveName(string uniqueSaveName);
/// Set Grid System's Save Location. Takes one parameter.
/// <param name="saveLocation">string save location</param>
easyGridBuilderPro.SetSaveLocation(string saveLocation);
/// Add Buildable Grid Object Type SO asset to the Grid System. Takes one parameter.
/// <param name="buildableGridObjectTypeSO">BuildableGridObjectTypeSO asset</param>
/// <param name="checkIfAlreadyHas">Check before if asset already exist, If so is ignore</param>
currentActiveSystem.AddBuildableGridObjectTypeSO(BuildableGridObjectTypeSO buildableGridObjectTypeSO, bool checkIfAlreadyHas);
/// Add Buildable Free Object Type SO asset to the Grid System. Takes one parameter.
/// <param name="buildableFreeObjectTypeSO">BuildableFreeObjectTypeSO asset</param>
/// <param name="checkIfAlreadyHas">Check before if asset already exist, If so is ignore</param>
currentActiveSystem.AddBuildableFreeObjectTypeSO(BuildableFreeObjectTypeSO buildableFreeObjectTypeSO, bool checkIfAlreadyHas);
/// Remove Buildable Grid Object Type SO asset from the Grid System. Takes one parameter.
/// <param name="buildableGridObjectTypeSO">BuildableGridObjectTypeSO asset</param>
currentActiveSystem.RemoveBuildableFreeObjectTypeSO(BuildableGridObjectTypeSO buildableGridObjectTypeSO);
/// Remove Buildable Free Object Type SO asset from the Grid System. Takes one parameter.
/// <param name="buildableFreeObjectTypeSO">BuildableFreeObjectTypeSO asset</param>
currentActiveSystem.RemoveBuildableFreeObjectTypeSO(BuildableFreeObjectTypeSO buildableFreeObjectTypeSO);
05. Input Functions
You can use these functions to call Easy Grid Builder Pro inputs instead of using Easy Grid Builder Pro Inputs SO assets. Or you can do both.
NOTE: Easy Grid Builder Pro built-in Input System with Inputs SO assets is a very powerful system with high flexibility. Only use these custom methods for specific reasons. To get a better understanding it is recommended to check the Multi Grid Input Manager script code.
Example: Call input function to place a buildable object. (When the key "Space" is pressed)
using SoulGames.EasyGridBuilderPro;
private List<EasyGridBuilderPro> easyGridBuilderProList;
private void Start()
{
easyGridBuilderProList = MultiGridManager.Instance.easyGridBuilderProList;
}
private void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
foreach(EasyGridBuilderPro easyGridBuilderPro in easyGridBuilderProList)
{
easyGridBuilderPro.TriggerBuildablePlacement();
easyGridBuilderPro.TriggerBuildablePlacementCancelled();
}
}
}
// Set Grid Mode Reset
foreach (EasyGridBuilderPro easyGridBuilderPro in easyGridBuilderProList)
{
easyGridBuilderPro.SetGridModeReset();
}
// For this you need to call this in these scripts too
[SerializeField]private GridObjectSelector gridObjectSelector;
if (gridObjectSelector) gridObjectSelector.SetGridModeReset();
// Change Grid Vertical Level
foreach (EasyGridBuilderPro easyGridBuilderPro in easyGridBuilderProList)
{
easyGridBuilderPro.TriggerGridHeightChangeManually();
}
// Set Grid Mode Build
foreach (EasyGridBuilderPro easyGridBuilderPro in easyGridBuilderProList)
{
easyGridBuilderPro.SetGridModeBuilding();
}
// Start Buildable Placement
foreach (EasyGridBuilderPro easyGridBuilderPro in easyGridBuilderProList)
{
easyGridBuilderPro.TriggerBuildablePlacement();
}
// End Buildable Placement
foreach (EasyGridBuilderPro easyGridBuilderPro in easyGridBuilderProList)
{
easyGridBuilderPro.TriggerBuildablePlacementCancelled();
}
// Scroll Buildable List
/// <param name="value">Vector2 value of scroll direction</param>
foreach (EasyGridBuilderPro easyGridBuilderPro in easyGridBuilderProList)
{
easyGridBuilderPro.TriggerBuildableListScroll(Vector2() value);
}
// Start Ghost Object Rotate Left
foreach (EasyGridBuilderPro easyGridBuilderPro in easyGridBuilderProList)
{
easyGridBuilderPro.TriggerGhostRotateLeft();
}
// End Ghost Object Rotate Left
foreach (EasyGridBuilderPro easyGridBuilderPro in easyGridBuilderProList)
{
easyGridBuilderPro.TriggerGhostRotateLeftCancelled();
}
// Start Ghost Object Rotate Right
foreach (EasyGridBuilderPro easyGridBuilderPro in easyGridBuilderProList)
{
easyGridBuilderPro.TriggerGhostRotateRight();
}
// End Ghost Object Rotate Right
foreach (EasyGridBuilderPro easyGridBuilderPro in easyGridBuilderProList)
{
easyGridBuilderPro.TriggerGhostRotateRightCancelled();
}
// Set Grid Mode Destruction
foreach (EasyGridBuilderPro easyGridBuilderPro in easyGridBuilderProList)
{
easyGridBuilderPro.SetGridModeDestruction();
}
// Set Buildable Destroy
foreach (EasyGridBuilderPro easyGridBuilderPro in easyGridBuilderProList)
{
easyGridBuilderPro.TriggerBuildableDestroy();
}
// Set Grid Mode Selection
gridObjectSelector.SetGridModeSelection();
// Set Buildable Select
gridObjectSelector.TriggerBuildableSelection();
// Set Grids data Save
foreach (EasyGridBuilderPro easyGridBuilderPro in easyGridBuilderProList)
{
easyGridBuilderPro.TriggerGridSave();
}
// Set Grids data Load
foreach (EasyGridBuilderPro easyGridBuilderPro in easyGridBuilderProList)
{
easyGridBuilderPro.TriggerGridLoad();
}
Last updated