How do I setup EasyCode?

To get started with EasyCode, you have a couple options.

1. Inherit from EasyManager.cs to access its methods. Only need 1 per scene.

// located at Assets/EasyCodeForVivox/Scripts/EasyBackend/EasyManager.cs

using EasyCodeForVivox;

public class VivoxManager : EasyManager
{

}

When placing EasyManager on a GameObject an additional script called SceneContext will be added. Do not delete. It is required for EasyManager and dependecy injection to work

2. Place an EasyManager.cs script on a Gameobject.

After that you can reference it by using [SerializedField]. Dont forget to drag and drop EasyManager gameobejct onto your script

using EasyCodeForVivox;
using UnityEngine;

public class VivoxManager : MonoBehaviour
{
    [SerializeField] private EasyManager _easyManager;
}

3. You can also use GetComponent<EasyManager>(); if on the same Gameobject that has the EasyManager script or you can use FindObjectOfType<EasyManager>(); (this is the slower option)

using EasyCodeForVivox;
using UnityEngine;

public class VivoxManager : MonoBehaviour
{
    private EasyManager _easyManager;

    private void Awake()
    {
        _easyManager = GetComponent<EasyManager>();
        // or
        _easyManager = FindObjectOfType<EasyManager>();
    }
}

4 . If you don't want to use EasyManager you can use dependency injection (Read more here) to inject EasyCode scripts into your classes

using EasyCodeForVivox;
using EasyCodeForVivox.Events;
using UnityEngine;
using Zenject;

public class VivoxManager : MonoBehaviour
{
    private EasyLogin _easyLogin;
    private EasyEvents _easyEvents;
    private EasyChannel _easyChannel;

    [Inject]
    private void Initialize(EasyLogin easyLogin, EasyEvents easyEvents, EasyChannel easyChannel)
    {
        _easyLogin = easyLogin;
        _easyEvents = easyEvents;
        _easyChannel = easyChannel;
    }
}

Last updated