Coder Social home page Coder Social logo

addressables-assetmanager's Introduction

Addressables-AssetManager

Pre-loading, Synchronicity, and Pooling for Unity Addressables

This project attempts to extend the Unity Addressables system for other common use cases.

The main file to look at is AssetManager.cs

Getting Started

Open the project in Unity 2019.3. Alternatively, copy the Assets/Asset Manager folder into your project

Requires Addressable 1.5.0

Use Cases

  • Track loaded/unloaded assets.
  • Load/Unload assets by label (Addressable Group labels, not gameobject labels)
  • Track instantiated assets and destroy all instantiated assets by AssetReference.RuntimeKey
  • Load/Instantiate Components directly. The default Addressable system currently only allows GameObjects or assets which derive from UnityEngine.Object (AudioClip, etc).
  • Synchronous loading and instantiation
  • Pooling of instantiated AssetReferences

Code

  • Load

    • AssetManager.TryGetOrLoadObjectAsync(AssetReference aRef, out AsyncOperationHandle handle)
      • Tries to get an already loaded UnityEngine.Object (not a component) and, if it doesnt exist, loads it.
      • Returns true if the object was already loaded, false otherwise.
      • handle contains an AsyncOperationHandle with Result as the requested object.
    • AssetManager.TryGetOrLoadComponentAsync(AssetReference aRef, out AsyncOperationHandle handle)
      • Same as above but used for components.
      • the handle result in this case will contain a reference to the requested Component attached to the GameObject.
    • AssetManager.TryGetObjectSync(AssetReference aRef, out TObjectType result)
      • Tries to synchronously get a reference to an already loaded object.
      • Returns true if the object was already loaded, false otherwise.
      • If false, 'result' will be null.
      • This works similarly to TryGetOrLoadObjectAsync, but wont load the object if it wasn't already loaded.
    • AssetManager.TryGetComponentSync(AssetReference aRef, out TComponentType result)
      • Same as above for components
    • AssetManager.LoadAssetsByLabelAsync(string label)
      • Loads all assets with the given Addressables label
  • Unload

    • AssetManager.Unload(AssetReference aRef)
      • Unloads the given AssetReference
    • AssetManager.UnloadByLabel(string label)
      • Unloads all assets with the given Addressables label
  • Get

    • AssetManager.IsLoaded(AssetReference aRef)
      • Returns true/false if the given AssetReference has already been loaded.
    • AssetManager.IsLoading(AssetReference aRef)
      • Returns true/false if the given AssetReference is currently loading.
    • AssetManager.IsInstantiated(AssetReference aRef)
      • Returns true/false if the given AssetReference has been instantiated.
    • AssetManager.InstantiatedCount(AssetReference aRef)
      • returns the total number of instantiated objects with the given AssetReference.
  • Instantiate

    • AssetManager.TryInstantiateOrLoadAsync(AssetReference aRef, Vector3 position, Quaternion rotation, Transform parent, out AsyncOperationHandle handle)
      • Tries to instantiate the given AssetReference if it is already loaded. Otherwise, loads and instantiates it.
      • Returns true if the object was already loaded, false otherwise.
      • Important: The 'handle' field will contain a AsyncOperationHandle with a 'result' field containing THE INSTANTIATED OBJECT (not the loaded object).
    • AssetManager.TryInstantiateOrLoadAsync(AssetReference aRef, Vector3 position, Quaternion rotation, Transform parent, out AsyncOperationHandle handle)
      • Same as above but for components, rather than GameObjects.
    • AssetManager.TryInstantiateMultiOrLoadAsync(AssetReference aRef, int count, Vector3 position, Quaternion rotation, Transform parent, out AsyncOperationHandle<List> handle)
      • Same as TryInstantiateOrLoadAsync but instantiates multiple copies (determined by the count field).
    • AssetManager.TryInstantiateMultiOrLoadAsync(AssetReference aRef, int count, Vector3 position, Quaternion rotation, Transform parent, out AsyncOperationHandle<List> handle)
      • Same as above but for components, rather than GameObjects
    • Assetmanager.TryInstantiateSync(AssetReference aRef, Vector3 position, Quaternion rotation, Transform parent, out GameObject result)
      • Tries to instantiate the given AssetReference if it is already loaded.
      • Returns true if it was already loaded, false otherwise.
      • Similar to TryInstantiateOrLoadAsync but will not load the object if it was not already loaded.
  • Destroy

    • AssetManager.DestroyAllInstances(AssetReference aRef)
      • Destroys all instantiated instances of the given AssetReference.

Examples

Please see the examples folder included in the Unity project.

addressables-assetmanager's People

Contributors

agittm avatar akauper avatar

Watchers

 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.