> For the complete documentation index, see [llms.txt](https://mindcodeinteractive.gitbook.io/easy-build-system-old/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://mindcodeinteractive.gitbook.io/easy-build-system-old/components/building-manager.md).

# Building Manager

This component is the core of the system. It contains a [Building Parts](/easy-build-system-old/components/building-part.md) reference list and keeps in cache all the components related to the system in the scene during runtime.

It includes a list of **Building Types** used to define the type of [Building Parts](/easy-build-system-old/components/building-part.md), as well as some optimization features such as **Area Of Interest** and **Building Batching**.

Optimization Features

* **Area Of Interest** Disabling all [Building Areas](broken://pages/vObTUdjvigZPFANTOADm) and [Building Sockets](/easy-build-system-old/components/building-socket.md) that are far from the camera to prevent reaching the colliders limit in your scene. "*PhysX engine used by Unity only handles a maximum of 65536 colliders in a scene."*
* **Building Batching** Reduce thousands of drawcalls into one call and increase performance significantly.

{% hint style="info" %}
Explore fields description in the Inspector by hovering your cursor over them.\
You can find more information about this here: [Tooltip Attribute](https://docs.unity3d.com/ScriptReference/TooltipAttribute.html).
{% endhint %}

***

## API

You can access this class by including the following namespace:

```csharp
using EasyBuildSystem.Features.Runtime.Buildings.Manager;
```

This class inherits from **Singleton** class and can be called like this:

```csharp
BuildingManager.Instance
```

Here is a list of all the events and methods of this component that can be called:

{% tabs %}
{% tab title="Events" %}

#### Events

```csharp
/// <summary>
/// Event triggered when a Building Part is being placed.
/// </summary>
BuildingManager.Instance.OnPlacingBuildingPartEvent.AddListener((BuildingPart part) => { });

/// <summary>
/// Event triggered when a Building Part is being destroyed.
/// </summary>
BuildingManager.Instance.OnDestroyingBuildingPartEvent.AddListener((BuildingPart part) => { });

/// <summary>
/// Event triggered when a Building Area is registered.
/// </summary>
BuildingManager.Instance.OnRegisterBuildingAreaEvent.AddListener((BuildingArea area) => { });

/// <summary>
/// Event triggered when a Building Area is unregistered.
/// </summary>
BuildingManager.Instance.OnUnregisterBuildingAreaEvent.AddListener((BuildingArea area) => { });

/// <summary>
/// Event triggered when a Building Part is registered.
/// </summary>
BuildingManager.Instance.OnRegisterBuildingPartEvent.AddListener((BuildingPart part) => { });

/// <summary>
/// Event triggered when a Building Part is unregistered.
/// </summary>
BuildingManager.Instance.OnUnregisterBuildingPartEvent.AddListener((BuildingPart part) => { });

/// <summary>
/// Event triggered when a Building Socket is registered.
/// </summary>
BuildingManager.Instance.OnRegisterBuildingSocketEvent.AddListener((BuildingSocket socket) => { });

/// <summary>
/// Event triggered when a Building Socket is unregistered.
/// </summary>
BuildingManager.Instance.OnUnregisterBuildingSocketEvent.AddListener((BuildingSocket socket) => { });

/// <summary>
/// Event triggered when a Building Group is registered.
/// </summary>
BuildingManager.Instance.OnRegisterBuildingGroupEvent.AddListener((BuildingGroup group) => { });

/// <summary>
/// Event triggered when a Building Group is unregistered.
/// </summary>
BuildingManager.Instance.OnUnregisterBuildingGroupEvent.AddListener((BuildingGroup group) => { });
```

{% endtab %}

{% tab title="Methods" %}

#### Methods

```csharp
/// <summary>
/// Retrieves the closest Building Area to the specified position.
/// </summary>
/// <param name="position">The position to find the closest Building Area from.</param>
/// <returns>The closest Building Area to the specified position, or null if no active Building Areas are found.</returns>
BuildingArea closestArea = BuildingManager.Instance.GetClosestBuildingArea(Vector3 position);

/// <summary>
/// Gets the closest Building Group to the specified Building Part.
/// </summary>
/// <param name="buildingPart">The Building Part to find the closest Building Group from.</param>
/// <returns>The closest Building Group to the specified Building Part, or null if not found.</returns>
BuildingGroup closestGroup = BuildingManager.Instance.GetClosestBuildingGroup(BuildingPart part).

/// <summary>
/// Gets a Building Part by its identifier.
/// </summary>
/// <param name="identifier">The identifier of the Building Part to retrieve.</param>
/// <returns>The Building Part with the specified identifier, or null if not found.</returns>
BuildingPart partReference = BuildingManager.Instance.GetBuildingPartByIdentifier(string identifier);

/// <summary>
/// Places a new Building Part.
/// </summary>
/// <param name="buildingPart">The Building Part to place.</param>
/// <param name="position">The position to place the Building Part.</param>
/// <param name="rotation">The rotation of the Building Part.</param>
/// <param name="scale">The scale of the Building Part.</param>
/// <param name="createNewGroup">Whether to create a new Building Group for the Building Part (default: true).</param>
/// <returns>The placed Building Part.</returns>
BuildingPart placedPart = BuildingManager.Instance.PlaceBuildingPart(BuildingPart part, Vector3 position, Vector3 rotation, Vector3 scale);

/// <summary>
/// Destroys a Building Part.
/// </summary>
/// <param name="buildingPart">The Building Part to destroy.</param>
BuildingManager.Instance.DestroyBuildingPart(BuildingPart part);
```

{% endtab %}
{% endtabs %}

All of the methods related to this component can be found in the file "BuildingManager.cs".\
If you have any specific questions about the API, feel free to contact us.
