Skip to content

Instantly share code, notes, and snippets.

View Badgerdox's full-sized avatar

Badgerdox Badgerdox

View GitHub Profile
public static class AssetRefLoader
{
public static async Task CreateAssetAddToList<T>(AssetReference reference, List<T> completedObjs)
where T : Object
{
completedObjs.Add(await reference.InstantiateAsync().Task as T);
}
}
public class AssetRefObjectData : MonoBehaviour
{
[SerializeField] private AssetReference _sqrARef;
[SerializeField] private List<AssetReference> _references = new List<AssetReference>();
private void Start()
{
_references.Add(_sqrARef);
}
}
public static async Task CreateAssetsAddToList<T>(List<AssetReference> references, List<T> completedObjs)
where T : Object
{
foreach (var reference in references)
completedObjs.Add(await reference.InstantiateAsync().Task as T);
}
[SerializeField] private AssetReference _sqrARef;
[SerializeField] private List<AssetReference> _references = new List<AssetReference>();
[SerializeField] private List<GameObject> _completedObj = new List<GameObject>();
private void Start()
{
_references.Add(_sqrARef);
StartCoroutine(LoadAndWaitUntilComplete());
}
public static class AddressableLocationLoader
{
public static async Task GetAll(string label, IList<IResourceLocation> loadedLocations)
{
var unloadedLocations = await Addressables.LoadResourceLocationsAsync(label).Task;
foreach (var location in unloadedLocations)
loadedLocations.Add(location);
}
}
public class LoadedAddressableLocations : MonoBehaviour
{
[SerializeField] private string _label;
public IList<IResourceLocation> AssetLocations { get; } = new List<IResourceLocation>();
private void Start()
{
InitAndWaitUntilLoaded(_label);
}
@Badgerdox
Badgerdox / CreateAddressablesLoader.cs
Created November 18, 2019 02:26
CreateAddressablesLoader #1
public static class CreateAddressablesLoader
{
public static async Task ByLoadedAddress<T>(IList<IResourceLocation> loadedLocations, List<T> createdObjs)
where T : Object
{
foreach (var location in loadedLocations)
{
var obj = await Addressables.InstantiateAsync(location).Task as T;
createdObjs.Add(obj);
}
@Badgerdox
Badgerdox / CreatedAssets.cs
Last active November 18, 2019 02:40
CreatedAssets.cs #1
public class CreatedAssets : MonoBehaviour
{
private LoadedAddressableLocations _loadedLocations;
[field: SerializeField] private List<GameObject> Assets { get; } = new List<GameObject>();
private void Start()
{
CreateAndWaitUntilCompleted();
}
private void Start()
{
CreateAndWaitUntilCompleted("prefab");
}
private async Task CreateAndWaitUntilCompleted(string label)
{
var locations = await Addressables.LoadResourceLocationsAsync(label).Task;
await Addressables.InstantiateAsync(locations[0]).Task;
}
@Badgerdox
Badgerdox / CreateAddressablesLoader.cs
Created November 18, 2019 04:02
CreateAddressablesLoader #2
public static class CreateAddressablesLoader
{
public static async Task ByAddress<T>(string label, List<T> createdAssets) where T : Object
{
var tempLocations = new List<IResourceLocation>();
await AddressableLocationLoader.GetAll(label, tempLocations);
foreach (var location in tempLocations)
{
var obj = await Addressables.InstantiateAsync(location).Task as T;