# 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.

```csharp
using SoulGames.EasyGridBuilderPro;
```

## 02. Access Grid Systems

Get a reference to all grids in the scene.

```csharp
private List<EasyGridBuilderPro> easyGridBuilderProList;

private void Start()
{
    easyGridBuilderProList = MultiGridManager.Instance.easyGridBuilderProList;
}
```

Get a reference to the currently active grid in the scene.

```csharp
private EasyGridBuilderPro currentActiveSystem;

private void Update()
{
    currentActiveSystem = MultiGridManager.Instance.activeGridSystem;
}
```

**Example:** Get a reference to a specific grid system by its name.

```csharp
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)

```csharp
using SoulGames.EasyGridBuilderPro;

private EasyGridBuilderPro currentActiveSystem;
private int activeSystemGridWidth;

private void Update()
{
    currentActiveSystem = MultiGridManager.Instance.activeGridSystem;
    if (Input.GetKeyDown(KeyCode.Space))
    {
        activeSystemGridWidth = currentActiveSystem.GetGridWidth();
    }
}
```

```csharp
/// Returns grid system's GridMode. Takes no parameter.
currentActiveSystem.GetGridMode();
```

```csharp
/// Returns grid system's GridAxis. Takes no parameter.
currentActiveSystem.GetGridAxis();
```

```csharp
/// Returns grid system's GridWidth. Takes no parameter.
currentActiveSystem.GetGridWidth();
```

```csharp
/// Returns grid system's GridLength. Takes no parameter.
currentActiveSystem.GetGridLength();
```

```csharp
/// Returns grid system's CellSize. Takes no parameter.
currentActiveSystem.GetGridCellSize();
```

```csharp
/// Returns grid system's GridOrigin. Takes no parameter.
currentActiveSystem.GetGridOrigin();
```

```csharp
/// Returns current stored BuildableGridObjectTypeSOList. Takes no parameter.
currentActiveSystem.GetBuildableGridObjectTypeSOList();
```

```csharp
/// Returns current stored BuildableGridObjectTypeSOList. Takes no parameter.
currentActiveSystem.GetBuildableFreeObjectTypeSOList();
```

```csharp
/// Returns current active vertical grid system's grid index. Takes no parameter.
currentActiveSystem.GetActiveVerticalGridIndex();
```

```csharp
/// Returns Bertical Grids Count. Takes no parameter.
currentActiveSystem.GetVerticalGridCount();
```

```csharp
/// Returns grid system's GridHeight. Takes no parameter.
currentActiveSystem.GetGridHeight();
```

```csharp
/// Returns grid system's Unique Save Name. Takes no parameter.
currentActiveSystem.GetUniqueSaveName();
```

```csharp
/// Returns grid system's Save Location. Takes no parameter.
currentActiveSystem.GetSaveLocation();
```

```csharp
/// Returns currently buildable, Buildable Grid Object Type SO. Takes no parameter.
currentActiveSystem.GetBuildableGridObjectTypeSO();
```

<pre class="language-csharp"><code class="lang-csharp">/// Returns currently buildable, Buildable Free Object Type SO. Takes no parameter.
<strong>currentActiveSystem.GetBuildableFreeObjectTypeSO();
</strong></code></pre>

```csharp
/// Returns the Buildable Grid Object Type So by its name. Takes string parameter.
currentActiveSystem.GetBuildableGridObjectTypeSOFromName(string buildableGridObjectTypeSOName);
```

```csharp
/// Returns the Buildable Free Object Type So by its name. Takes string parameter.
currentActiveSystem.GetBuildableFreeObjectTypeSOFromName(string buildableFreeObjectTypeSOName);
```

```csharp
/// Returns the world position of a grid cell. Takes Vector2Int parameter.
currentActiveSystem.GetWorldPositionXZ(Vector2Int gridPosition)
currentActiveSystem.GetWorldPositionXY(Vector2Int gridPosition)
```

```csharp
/// Returns the grid position of a grid cell (Grid Index). Takes Vector3 parameter.
currentActiveSystem.GetGridPositionXZ(Vector3 worldPosition)
currentActiveSystem.GetGridPositionXY(Vector3 worldPosition)
```

```csharp
/// 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)
```

```csharp
/// 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)

```csharp
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);
        }
    }
}
```

```csharp
/// Force set grid system's GridMode. Takes one parameter.
/// <param name="gridMode">GridMode enum value</param>
easyGridBuilderPro.SetGridMode(GridMode gridMode);
```

```csharp
/// Set grid system's Vertical Grid. Takes one parameter.
/// <param name="currentActiveGridIndex">int Vertical Grid Index</param>
easyGridBuilderPro.SetActiveVerticalGrid(int currentActiveGridIndex);
```

```csharp
/// Set grid system's Vertical Grid Auto Height Detect. Takes one parameter.
/// <param name="setActive">bool enable or disable</param>
easyGridBuilderPro.SetAutoDetectHeight(bool setActive);
```

```csharp
/// 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);
```

```csharp
/// 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);
```

```csharp
/// Set Grid System's Unique Save Name. Takes one parameter.
/// <param name="uniqueSaveName">string unique save name</param>
currentActiveSystem.SetUniqueSaveName(string uniqueSaveName);
```

```csharp
/// Set Grid System's Save Location. Takes one parameter.
/// <param name="saveLocation">string save location</param>
easyGridBuilderPro.SetSaveLocation(string saveLocation);
```

```csharp
/// 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);
```

```csharp
/// 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);
```

```csharp
/// Remove Buildable Grid Object Type SO asset from the Grid System. Takes one parameter.
/// <param name="buildableGridObjectTypeSO">BuildableGridObjectTypeSO asset</param>
currentActiveSystem.RemoveBuildableFreeObjectTypeSO(BuildableGridObjectTypeSO buildableGridObjectTypeSO);
```

```csharp
/// 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)

```csharp
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();
        }
    }
}
```

```csharp
// 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();
```

```csharp
// Change Grid Vertical Level
foreach (EasyGridBuilderPro easyGridBuilderPro in easyGridBuilderProList)
{
    easyGridBuilderPro.TriggerGridHeightChangeManually();
}
```

```csharp
// Set Grid Mode Build
foreach (EasyGridBuilderPro easyGridBuilderPro in easyGridBuilderProList)
{
    easyGridBuilderPro.SetGridModeBuilding();
}
```

<pre class="language-csharp"><code class="lang-csharp"><strong>// Start Buildable Placement
</strong><strong>foreach (EasyGridBuilderPro easyGridBuilderPro in easyGridBuilderProList)
</strong>{
    easyGridBuilderPro.TriggerBuildablePlacement();
}
// End Buildable Placement
foreach (EasyGridBuilderPro easyGridBuilderPro in easyGridBuilderProList)
{
    easyGridBuilderPro.TriggerBuildablePlacementCancelled();
}
</code></pre>

```csharp
// Scroll Buildable List
/// <param name="value">Vector2 value of scroll direction</param>
foreach (EasyGridBuilderPro easyGridBuilderPro in easyGridBuilderProList)
{
    easyGridBuilderPro.TriggerBuildableListScroll(Vector2() value);
}
```

<pre class="language-csharp"><code class="lang-csharp">// Start Ghost Object Rotate Left
<strong>foreach (EasyGridBuilderPro easyGridBuilderPro in easyGridBuilderProList)
</strong>{
    easyGridBuilderPro.TriggerGhostRotateLeft();
}
// End Ghost Object Rotate Left
foreach (EasyGridBuilderPro easyGridBuilderPro in easyGridBuilderProList)
{
    easyGridBuilderPro.TriggerGhostRotateLeftCancelled();
}
</code></pre>

```csharp
// Start Ghost Object Rotate Right
foreach (EasyGridBuilderPro easyGridBuilderPro in easyGridBuilderProList)
{
    easyGridBuilderPro.TriggerGhostRotateRight();
}
// End Ghost Object Rotate Right
foreach (EasyGridBuilderPro easyGridBuilderPro in easyGridBuilderProList)
{
    easyGridBuilderPro.TriggerGhostRotateRightCancelled();
}
```

```csharp
// Set Grid Mode Destruction
foreach (EasyGridBuilderPro easyGridBuilderPro in easyGridBuilderProList)
{
    easyGridBuilderPro.SetGridModeDestruction();
}
```

```csharp
// Set Buildable Destroy
foreach (EasyGridBuilderPro easyGridBuilderPro in easyGridBuilderProList)
{
    easyGridBuilderPro.TriggerBuildableDestroy();
}
```

```csharp
// Set Grid Mode Selection
gridObjectSelector.SetGridModeSelection();
```

```csharp
// Set Buildable Select
gridObjectSelector.TriggerBuildableSelection();
```

```csharp
// Set Grids data Save
foreach (EasyGridBuilderPro easyGridBuilderPro in easyGridBuilderProList)
{
    easyGridBuilderPro.TriggerGridSave();
}
```

```csharp
// Set Grids data Load
foreach (EasyGridBuilderPro easyGridBuilderPro in easyGridBuilderProList)
{
    easyGridBuilderPro.TriggerGridLoad();
}
```
