Git Product home page Git Product logo

addressablesmanager's Introduction

AddressablesManager

Tested with Addressables version 1.3.

An unofficial intermediary for Unity's Addressables system. With this, you can load an asset without having to make use of a coroutine each time you need to use the Addressables system.

For a quick guide on how to setup Addressables, check the Getting Started guide and the forum post

The IAsyncOperationExtensions file was created by Unity forum user rigidbuddy.

Async/Await

This system needs to be prefaced with the fact that it uses async/await methods exclusively, what this basically means is that methods with the async modifier in front of them can "await" other asynchronous methods. You can find some examples here.

Usage

To use the manager, you must declare your current method with the async modifier so that it can await the Addressables Manager's methods.

async void GetAnInteger()
{
    int x = await GetInt();
}

Instantiating a gameobject

GameObject loneGameObject;

async void InstantiateSingleObject(string path)
{
    loneGameObject = await AddressablesManager.Instance.InstantiateGameObject(path);
}

Loading objects

You can load any kind of object by using the Load method, you can then assign these objects somewhere else if you wish.

Sprite _sprite;

async void LoadSprite()
{
    _sprite = await AddressablesManager.Instance.Load<Sprite>("sprite");
}

Loading assets by label

You can load an array of assets using the labels they use in the Addressables system.

List<Material> materials;

async void TestLoadByLabel()
{
    materials = await AddressablesManager.Instance.LoadAssetsByLabel<Material>("materials");
}

Loading a scene

With loading scenes, you can choose whether to load them in either of the LoadSceneModes (Additive or Single) or whether to only load them or load them and assign them to a variable.

Scene sceneToLoad;

async void LoadScene()
{
    sceneToLoad = await AddressablesManager.Instance.LoadScene("sceneName", LoadSceneMode.Additive);
}

async void OnlyLoadScene()
{
    await AddressablesManager.Instance.LoadScene("sceneName", LoadSceneMode.Additive);
}

Unloading scenes

You can unload scenes you hold a reference to.

async void UnloadScene()
{
    AddressablesManager.Instance.UnloadScene(sceneToLoad);
}

addressablesmanager's People

Contributors

milfeulle avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.