# Game Manager

### Adding Custom UI References

{% hint style="info" %}
When you have created a new Player Item and want to display a custom UI interface, you can incorporate custom UI references into the Game Manager. This will allow you to access these UI references with ease.
{% endhint %}

1. In the **UHFPS Game Manager** component located in the **GAMEMANAGER** object, you'll come across a section called **Custom UI References**. To include a new UI reference, simply press the **Add** button.

<figure><img src="https://2665493337-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fh8bp6Jx5qkS4c0NEaWR1%2Fuploads%2FzLEipaMQ01SX4j6E76r0%2FScreenshot_1.png?alt=media&#x26;token=8492df55-c0ba-4c76-91c4-1d627d56630d" alt=""><figcaption></figcaption></figure>

2. To utilize the UI references, assign a name that will be used to access the references. Once that's done, you can easily use the **GraphicReferences** field to obtain the UI references by their designated name.

Here is a code snippet to get the flashlight UI references:

```csharp
private void Awake()
{
    GameManager gameManager = GameManager.Instance;

    var behaviours = gameManager.GraphicReferences.Value["Flashlight"];
    CanvasGroup flashlightPanel = (CanvasGroup)behaviours[0];
    Image batteryIcon = (Image)behaviours[1];
    Image batteryFill = (Image)behaviours[2];
}
```

{% hint style="info" %}
As you may have noticed, to get the specified reference, you have to access it using an index number because the return value from **GraphicReferences** is an array.
{% endhint %}

### Adding Manager Modules

{% hint style="info" %}
Adding module managers can be advantageous if you have components that don't have variables, or if you prefer a clean view of the inspector, or even if you're looking for convenient access to a module.
{% endhint %}

<figure><img src="https://2665493337-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fh8bp6Jx5qkS4c0NEaWR1%2Fuploads%2Fe9gxoXBcz8uK21hUF1mI%2FScreenshot_1.png?alt=media&#x26;token=bd8aeadc-2425-4b86-9075-b2ce69f12e40" alt=""><figcaption></figcaption></figure>

1. To create a new manager module, your new script needs to inherit from the **ManagerModule** class.

```csharp
namespace UHFPS.Runtime
{
    public class TestModule : ManagerModule
    {
        public override void OnAwake()
        {
            
        }

        public override void OnStart()
        {
            
        }

        public override void OnUpdate()
        {
            
        }
    }
}
```

2. Write your code into the provided methods as you typically would. Keep in mind that the **ManagerModule** class is based on a **ScriptableObject**. This implies that you can't include variables with scene references.
3. Find the **Manager Modules** asset, which is located within the **UHFPS Game Manager** component.
4. Within the **Manager Modules** asset, click on the **Add Module** button and pick your newly created module. This action will generate a new **Module** asset and automatically integrate it into the Manager Modules.

<figure><img src="https://2665493337-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fh8bp6Jx5qkS4c0NEaWR1%2Fuploads%2Fq1zUtJRMKnXLkvH5Kn4n%2FScreenshot_3.png?alt=media&#x26;token=b94e3c68-b2ba-4dd1-9d4c-bffc2c1fcb4a" alt=""><figcaption></figcaption></figure>

5. To retrieve a **Module** reference from the game manager, just use the <mark style="color:blue;">**Module\<T>**</mark> method from the **GameManager** component.

```csharp
private void Awake()
{
    TestModule testModule = GameManager.Module<TestModule>();
}
```
