API - All Accessible Events
Most of the Easy Grid Builder Pro 2 classes comes with useful events that you can easily subscribe to. In this part of the guide we will quickly go through all these events. However, for a deeper understanding and find out about all the Public Setter and Getter functions each class provide, It is highly recommended to go through the rest of the API documentation.
Events in Grid Manager Class
Here’s an example of demonstrating how to access and use one of the events in Grid Manager class:
using UnityEngine;
using SoulGames.EasyGridBuilderPro;
public class APIDocumentationClass : MonoBehaviour
{
private GridManager gridManager;
private void Start()
{
gridManager = GridManager.Instance;
// Subscribe to the OnActiveEasyGridBuilderProChanged event
gridManager.OnActiveEasyGridBuilderProChanged += OnActiveEasyGridBuilderProChanged;
}
private void OnDestroy()
{
// Unsubscribe from the OnActiveEasyGridBuilderProChanged event to prevent memory leaks
gridManager.OnActiveEasyGridBuilderProChanged -= OnActiveEasyGridBuilderProChanged;
}
/// Callback method triggered when the active EasyGridBuilderPro system changes
private void OnActiveEasyGridBuilderProChanged(EasyGridBuilderPro activeEasyGridBuilderProSystem)
{
// Example: Log the active EasyGridBuilderPro name to the console
Debug.Log($"Current Active EasyGridBuilderPro system is: {activeEasyGridBuilderProSystem.name}");
}
}
On Active Easy Grid Builder Pro Changed
/// Event triggered when the active EasyGridBuilderPro system changes
/// <param name="activeEasyGridBuilderProSystem">
/// Represents the new active EasyGridBuilderPro system
/// </param>
public event OnActiveEasyGridBuilderProChangedDelegate OnActiveEasyGridBuilderProChanged;
public delegate void OnActiveEasyGridBuilderProChangedDelegate(EasyGridBuilderPro activeEasyGridBuilderProSystem);
On Is Mouse Pointer On Grid Changed
/// Event triggered when the mouse pointer's presence on the grid changes
/// <param name="isMousePointerOnGrid">
/// Indicates whether the mouse pointer is currently on the grid
/// </param>
public event OnIsMousePointerOnGridChangedDelegate OnIsMousePointerOnGridChanged;
public delegate void OnIsMousePointerOnGridChangedDelegate(bool isMousePointerOnGrid);
On Active Camera Mode Changed
/// Event triggered when the active camera mode changes
/// <param name="activeCameraMode">
/// Represents the newly activated camera mode
/// </param>
public event OnActiveCameraModeChangedDelegate OnActiveCameraModeChanged;
public delegate void OnActiveCameraModeChangedDelegate(CameraMode activeCameraMode);
On Active Grid Mode Changed
/// Event triggered when the active grid mode changes
/// <param name="easyGridBuilderPro">
/// The EasyGridBuilderPro instance associated with the grid mode change
/// </param>
/// <param name="gridMode">
/// Represents the newly activated grid mode
/// </param>
public event OnActiveGridModeChangedDelegate OnActiveGridModeChanged;
public delegate void OnActiveGridModeChangedDelegate(EasyGridBuilderPro easyGridBuilderPro, GridMode gridMode);
On Active Buildable SO Changed
/// Event triggered when the active BuildableObjectSO changes
/// <param name="easyGridBuilderPro">
/// The EasyGridBuilderPro instance associated with the BuildableObjectSO change
/// </param>
/// <param name="buildableObjectSO">
/// Represents the newly activated BuildableObjectSO
/// </param>
public event OnActiveBuildableSOChangedDelegate OnActiveBuildableSOChanged;
public delegate void OnActiveBuildableSOChangedDelegate(EasyGridBuilderPro easyGridBuilderPro, BuildableObjectSO buildableObjectSO);
On Active Vertical Grid Changed
/// Event triggered when the active vertical grid index changes
/// <param name="easyGridBuilderPro">
/// The EasyGridBuilderPro instance triggering the vertical grid change
/// </param>
/// <param name="activeVerticalGridIndex">
/// Represents the newly activated vertical grid index
/// </param>
public event OnActiveVerticalGridChangedDelegate OnActiveVerticalGridChanged;
public delegate void OnActiveVerticalGridChangedDelegate(EasyGridBuilderPro easyGridBuilderPro, int activeVerticalGridIndex);
On Cell Object Value Changed
/// Event triggered when the value of a cell has changes
/// <param name="easyGridBuilderPro">
/// The EasyGridBuilderPro instance triggering the cell object value change
/// </param>
/// <param name="cellPosition">
/// The position of the cell where the value has changed
/// </param>
public event OnCellObjectValueChangedDelegate OnCellObjectValueChanged;
public delegate void OnCellObjectValueChangedDelegate(EasyGridBuilderPro easyGridBuilderPro, Vector2Int cellPosition);
On Buildable Object Placed
/// Event triggered when a buildable object is placed on the grid
/// <param name="easyGridBuilderPro">
/// The EasyGridBuilderPro instance triggering the event
/// </param>
/// <param name="buildableObject">
/// The buildable object that has been placed
/// </param>
public event OnBuildableObjectPlacedDelegate OnBuildableObjectPlaced;
public delegate void OnBuildableObjectPlacedDelegate(EasyGridBuilderPro easyGridBuilderPro, BuildableObject buildableObject);
On Buildable Object SO Added
/// Event triggered when a new BuildableObjectSO is added to the grid system's Buildables list
/// <param name="easyGridBuilderPro">
/// The EasyGridBuilderPro instance triggering the event
/// </param>
/// <param name="buildableObjectSO">
/// The BuildableObjectSO that has been added
/// </param>
public event OnBuildableObjectSOAddedDelegate OnBuildableObjectSOAdded;
public delegate void OnBuildableObjectSOAddedDelegate(EasyGridBuilderPro easyGridBuilderPro, BuildableObjectSO buildableObjectSO);
On Buildable Object SO Removed
/// Event triggered when a BuildableObjectSO is removed from the grid system's Buildables list
/// <param name="easyGridBuilderPro">
/// The EasyGridBuilderPro instance triggering the event
/// </param>
/// <param name="buildableObjectSO">
/// The BuildableObjectSO that has been removed
/// </param>
public event OnBuildableObjectSORemovedDelegate OnBuildableObjectSORemoved;
public delegate void OnBuildableObjectSORemovedDelegate(EasyGridBuilderPro easyGridBuilderPro, BuildableObjectSO buildableObjectSO);
Internal Supporter Events
These events are used internally within the Easy Grid Builder Pro 2 grid systems. However, they are accessible if needed. Let’s quickly review these events.
/// Event triggered when a Buildable Grid Object box placement starts
public event OnGridObjectBoxPlacementStartedDelegate OnGridObjectBoxPlacementStarted;
public delegate void OnGridObjectBoxPlacementStartedDelegate(EasyGridBuilderPro easyGridBuilderPro, Vector3 boxPlacementStartPosition, GridObjectPlacementType placementType);
/// Event triggered when a Buildable Grid Object box placement is updated
public event OnGridObjectBoxPlacementUpdatedDelegate OnGridObjectBoxPlacementUpdated;
public delegate void OnGridObjectBoxPlacementUpdatedDelegate(EasyGridBuilderPro easyGridBuilderPro, Vector3 boxPlacementEndPosition);
/// Event triggered when a Buildable Grid Object box placement is finalized
public event OnGridObjectBoxPlacementFinalizedDelegate OnGridObjectBoxPlacementFinalized;
public delegate void OnGridObjectBoxPlacementFinalizedDelegate(EasyGridBuilderPro easyGridBuilderPro);
/// Event triggered when a Buildable Grid Object box placement is cancelled
public event OnGridObjectBoxPlacementCancelledDelegate OnGridObjectBoxPlacementCancelled;
public delegate void OnGridObjectBoxPlacementCancelledDelegate(EasyGridBuilderPro easyGridBuilderPro);
/// Event triggered when a Buildable Edge Object box placement starts
public event OnEdgeObjectBoxPlacementStartedDelegate OnEdgeObjectBoxPlacementStarted;
public delegate void OnEdgeObjectBoxPlacementStartedDelegate(EasyGridBuilderPro easyGridBuilderPro, Vector3 boxPlacementStartPosition, EdgeObjectPlacementType placementType);
/// Event triggered when a Buildable Edge Object box placement is updated
public event OnEdgeObjectBoxPlacementUpdatedDelegate OnEdgeObjectBoxPlacementUpdated;
public delegate void OnEdgeObjectBoxPlacementUpdatedDelegate(EasyGridBuilderPro easyGridBuilderPro, Vector3 boxPlacementEndPosition);
/// Event triggered when a Buildable Edge Object box placement is finalized
public event OnEdgeObjectBoxPlacementFinalizedDelegate OnEdgeObjectBoxPlacementFinalized;
public delegate void OnEdgeObjectBoxPlacementFinalizedDelegate(EasyGridBuilderPro easyGridBuilderPro);
/// Event triggered when a Buildable Edge Object box placement is cancelled
public event OnEdgeObjectBoxPlacementCancelledDelegate OnEdgeObjectBoxPlacementCancelled;
public delegate void OnEdgeObjectBoxPlacementCancelledDelegate(EasyGridBuilderPro easyGridBuilderPro);
/// Event triggered when a Buildable Corner Object box placement starts
public event OnCornerObjectBoxPlacementStartedDelegate OnCornerObjectBoxPlacementStarted;
public delegate void OnCornerObjectBoxPlacementStartedDelegate(EasyGridBuilderPro easyGridBuilderPro, Vector3 boxPlacementStartPosition, CornerObjectPlacementType placementType);
/// Event triggered when a Buildable Corner Object box placement is updated
public event OnCornerObjectBoxPlacementUpdatedDelegate OnCornerObjectBoxPlacementUpdated;
public delegate void OnCornerObjectBoxPlacementUpdatedDelegate(EasyGridBuilderPro easyGridBuilderPro, Vector3 boxPlacementEndPosition);
/// Event triggered when a Buildable Corner Object box placement is finalized
public event OnCornerObjectBoxPlacementFinalizedDelegate OnCornerObjectBoxPlacementFinalized;
public delegate void OnCornerObjectBoxPlacementFinalizedDelegate(EasyGridBuilderPro easyGridBuilderPro);
/// Event triggered when a Buildable Corner Object box placement is cancelled
public event OnCornerObjectBoxPlacementCancelledDelegate OnCornerObjectBoxPlacementCancelled;
public delegate void OnCornerObjectBoxPlacementCancelledDelegate(EasyGridBuilderPro easyGridBuilderPro);
/// Event triggered when a Buildable Free Object spline placement starts or is updated
public event OnFreeObjectSplinePlacementStartedAndUpdatedDelegate OnFreeObjectSplinePlacementStartedAndUpdated;
public delegate void OnFreeObjectSplinePlacementStartedAndUpdatedDelegate(EasyGridBuilderPro easyGridBuilderPro, Vector3 worldPosition, FreeObjectPlacementType placementType);
/// Event triggered when a Buildable Free Object spline placement is finalized
public event OnFreeObjectSplinePlacementFinalizedDelegate OnFreeObjectSplinePlacementFinalized;
public delegate void OnFreeObjectSplinePlacementFinalizedDelegate(EasyGridBuilderPro easyGridBuilderPro);
/// Event triggered when a Buildable Free Object spline placement is cancelled
public event OnFreeObjectSplinePlacementCancelledDelegate OnFreeObjectSplinePlacementCancelled;
public delegate void OnFreeObjectSplinePlacementCancelledDelegate(EasyGridBuilderPro easyGridBuilderPro);
Events in Easy Grid Builder Pro Class
Most of the key events have been relocated to the Grid Manager class for better accessibility and simplicity. The only exclusive event remaining in the Easy Grid Builder Pro class is the OnGridSystemCreated static event. This is how you access it:
using UnityEngine;
using SoulGames.EasyGridBuilderPro;
public class APIDocumentationClass : MonoBehaviour
{
private void Start()
{
// Subscribe to the OnGridSystemCreated event
EasyGridBuilderPro.OnGridSystemCreated += OnGridSystemCreated;
}
private void OnDestroy()
{
// Unsubscribe from the OnGridSystemCreated event to prevent memory leaks
EasyGridBuilderPro.OnGridSystemCreated -= OnGridSystemCreated;
}
/// Callback method triggered when a new grid system is created
private void OnGridSystemCreated(EasyGridBuilderPro easyGridBuilderPro)
{
// Example: Log the name of the created grid system
Debug.Log($"Grid system created: {easyGridBuilderPro.name}");
}
}
On Grid System Created
/// Static event triggered when a new grid system is created
/// <param name="easyGridBuilderPro">
/// The EasyGridBuilderPro instance representing the newly created grid system
/// </param>
public static event OnGridSystemCreatedDelegate OnGridSystemCreated;
public delegate void OnGridSystemCreatedDelegate(EasyGridBuilderPro easyGridBuilderPro);
Events in Buildable Object Destroyer Class
This class is responsible for destroying built objects on the grid. Below is an example of how to access one of its events:
using UnityEngine;
using SoulGames.EasyGridBuilderPro;
public class APIDocumentationClass : MonoBehaviour
{
private GridManager gridManager;
// Reference to the BuildableObjectDestroyer component
private BuildableObjectDestroyer buildableObjectDestroyer;
private void Start()
{
gridManager = GridManager.Instance;
// Attempt to get the BuildableObjectDestroyer component from the GridManager
if (gridManager.TryGetBuildableObjectDestroyer(out buildableObjectDestroyer))
{
// Subscribe to the OnBuildableObjectDestroyed event
buildableObjectDestroyer.OnBuildableObjectDestroyed += OnBuildableObjectDestroyed;
}
}
private void OnDestroy()
{
// Unsubscribe from the OnBuildableObjectDestroyed event to prevent memory leaks
if (buildableObjectDestroyer)
{
buildableObjectDestroyer.OnBuildableObjectDestroyed -= OnBuildableObjectDestroyed;
}
}
/// Callback method triggered when a buildable object is destroyed
private void OnBuildableObjectDestroyed(EasyGridBuilderPro easyGridBuilderPro, BuildableObject buildableObject)
{
// Example: Log the name of the destroyed object
Debug.Log($"Buildable object destroyed: {buildableObject.name} in {easyGridBuilderPro.name}");
}
}
On Buildable Object Destroyed
/// Event triggered when a buildable object is destroyed
/// <param name="easyGridBuilderPro">
/// The EasyGridBuilderPro instance where the object was destroyed
/// </param>
/// <param name="buildableObject">
/// Represents the destroyed BuildableObject instance
/// </param>
public event OnBuildableObjectDestroyedDelegate OnBuildableObjectDestroyed;
public delegate void OnBuildableObjectDestroyedDelegate(EasyGridBuilderPro easyGridBuilderPro, BuildableObject buildableObject);
On Buildable Object Hover Enter
/// Event triggered when the mouse pointer hovers over a buildable object while in Destroy Mode
/// <param name="buildableObject">
/// Represents the buildable object that the mouse pointer has entered
/// </param>
public event OnBuildableObjectHoverEnterDelegate OnBuildableObjectHoverEnter;
public delegate void OnBuildableObjectHoverEnterDelegate(BuildableObject buildableObject);
On Buildable Object Hover Exit
/// Event triggered when the mouse pointer exits the hover state over a buildable object while in Destroy Mode
/// <param name="buildableObject">
/// Represents the buildable object that the mouse pointer exited from
/// </param>
public event OnBuildableObjectHoverExitDelegate OnBuildableObjectHoverExit;
public delegate void OnBuildableObjectHoverExitDelegate(BuildableObject buildableObject);
Events in Buildable Object Selector Class
This class is responsible for selecting built objects on the grid. Below is an example of how to access one of its events:
using UnityEngine;
using SoulGames.EasyGridBuilderPro;
public class APIDocumentationClass : MonoBehaviour
{
private GridManager gridManager;
// Reference to the BuildableObjectSelector component
private BuildableObjectSelector buildableObjectSelector;
private void Start()
{
gridManager = GridManager.Instance;
// Attempt to get the BuildableObjectSelector component from the GridManager
if (gridManager.TryGetBuildableObjectSelector(out buildableObjectSelector))
{
// Subscribe to the OnBuildableObjectSelected event
buildableObjectSelector.OnBuildableObjectSelected += OnBuildableObjectSelected;
}
}
private void OnDestroy()
{
// Unsubscribe from the OnBuildableObjectSelected event to prevent memory leaks
if (buildableObjectSelector)
{
buildableObjectSelector.OnBuildableObjectSelected -= OnBuildableObjectSelected;
}
}
/// Callback method triggered when a buildable object is selected
private void OnBuildableObjectSelected(BuildableObject buildableObject)
{
// Example: Log the name of the selected object
Debug.Log($"Buildable object selected: {buildableObject.name}");
}
}
On Buildable Object Selected
/// Event triggered when a buildable object is selected
/// <param name="buildableObject">
/// Represents the buildable object that was selected
/// </param>
public event OnBuildableObjectSelectedDelegate OnBuildableObjectSelected;
public delegate void OnBuildableObjectSelectedDelegate(BuildableObject buildableObject);
On Buildable Object Deselected
/// Event triggered when a buildable object is deselected
/// <param name="buildableObject">
/// Represents the buildable object that was deselected
/// </param>
public event OnBuildableObjectDeselectedDelegate OnBuildableObjectDeselected;
public delegate void OnBuildableObjectDeselectedDelegate(BuildableObject buildableObject);
On Buildable Object Hover Enter
/// Event triggered when the mouse pointer hovers over a buildable object while in Select Mode
/// <param name="buildableObject">
/// Represents the buildable object that the mouse pointer has entered
/// </param>
public event OnBuildableObjectHoverEnterDelegate OnBuildableObjectHoverEnter;
public delegate void OnBuildableObjectHoverEnterDelegate(BuildableObject buildableObject);
On Buildable Object Hover Exit
/// Event triggered when the mouse pointer exits the hover state over a buildable object while in Select Mode
/// <param name="buildableObject">
/// Represents the buildable object that the mouse pointer exited from
/// </param>
public event OnBuildableObjectHoverExitDelegate OnBuildableObjectHoverExit;
public delegate void OnBuildableObjectHoverExitDelegate(BuildableObject buildableObject);
Events in Buildable Object Mover Class
This class is responsible for moving built objects on the grid. Below is an example of how to access one of its events:
using UnityEngine;
using SoulGames.EasyGridBuilderPro;
public class APIDocumentationClass : MonoBehaviour
{
private GridManager gridManager;
// Reference to the BuildableObjectMover component
private BuildableObjectMover buildableObjectMover;
private void Start()
{
gridManager = GridManager.Instance;
// Attempt to get the BuildableObjectMover component from the GridManager
if (gridManager.TryGetBuildableObjectMover(out buildableObjectMover))
{
// Subscribe to the OnBuildableObjectStartMoving event
buildableObjectMover.OnBuildableObjectStartMoving += OnBuildableObjectStartMoving;
}
}
private void OnDestroy()
{
// Unsubscribe from the OnBuildableObjectStartMoving event to prevent memory leaks
if (buildableObjectMover)
{
buildableObjectMover.OnBuildableObjectStartMoving -= OnBuildableObjectStartMoving;
}
}
/// Callback method triggered when a buildable object starts moving
private void OnBuildableObjectStartMoving(BuildableObject buildableObject)
{
// Example: Log the name of the moving object
Debug.Log($"Buildable object started moving: {buildableObject.name}");
}
}
On Buildable Object Start Moving
/// Event triggered when a buildable object starts moving
/// <param name="buildableObject">
/// Represents the buildable object that has started moving
/// </param>
public event OnBuildableObjectStartMovingDelegate OnBuildableObjectStartMoving;
public delegate void OnBuildableObjectStartMovingDelegate(BuildableObject buildableObject);
On Buildable Object End Moving
/// Event triggered when a buildable object finishes moving
/// <param name="buildableObject">
/// Represents the buildable object that has finished moving
/// </param>
public event OnBuildableObjectEndMovingDelegate OnBuildableObjectEndMoving;
public delegate void OnBuildableObjectEndMovingDelegate(BuildableObject buildableObject);
On Buildable Object Hover Enter
/// Event triggered when the mouse pointer hovers over a buildable object while in Move Mode
/// <param name="buildableObject">
/// Represents the buildable object that the mouse pointer has entered
/// </param>
public event OnBuildableObjectHoverEnterDelegate OnBuildableObjectHoverEnter;
public delegate void OnBuildableObjectHoverEnterDelegate(BuildableObject buildableObject);
On Buildable Object Hover Exit
/// Event triggered when the mouse pointer exits the hover state over a buildable object while in Move Mode
/// <param name="buildableObject">
/// Represents the buildable object that the mouse pointer exited from
/// </param>
public event OnBuildableObjectHoverExitDelegate OnBuildableObjectHoverExit;
public delegate void OnBuildableObjectHoverExitDelegate(BuildableObject buildableObject);
Events in Grid Heat Map Manager Class
This class manages painting and reading values on grid heatmaps. Here's an example of how to access one of its events:
using UnityEngine;
using SoulGames.EasyGridBuilderPro;
using System.Collections.Generic;
public class APIDocumentationClass : MonoBehaviour
{
private void Start()
{
// Subscribe to the OnGridHeatMapReadAllValues event
GridHeatMapManager.OnGridHeatMapReadAllValues += OnGridHeatMapReadAllValues;
}
private void OnDestroy()
{
// Unsubscribe from the OnGridHeatMapReadAllValues event to prevent memory leaks
GridHeatMapManager.OnGridHeatMapReadAllValues -= OnGridHeatMapReadAllValues;
}
/// Callback method triggered when all grid heatmap values are read
private void OnGridHeatMapReadAllValues(Dictionary<GridModifierSO, float> customModifierValues)
{
// Example: Log the number of modifiers in the heatmap
Debug.Log($"Number of custom modifiers in heatmap: {customModifierValues.Count}");
}
}
On Grid Heat Map Read All Values
/// Static event triggered when all grid heatmap values are read
/// <param name="customModifierValues">
/// A dictionary containing the grid modifiers (GridModifierSO) and their corresponding values.
/// </param>
public static event OnGridHeatMapReadAllValuesDelegate OnGridHeatMapReadAllValues;
public delegate void OnGridHeatMapReadAllValuesDelegate(Dictionary<GridModifierSO, float> customModifierValues);
On Grid Heat Map Read Value
/// Static event triggered when a specific grid heatmap value is read
/// <param name="customModifierValue">
/// The heatmap modifier value read, represented as a float
/// </param>
public static event OnGridHeatMapReadValueDelegate OnGridHeatMapReadValue;
public delegate void OnGridHeatMapReadValueDelegate(float customModifierValue);
Last updated