Ejemplo n.º 1
0
        private static void Remove(AssetReference reference, NotifyOnDestroy obj)
        {
            Addressables.ReleaseInstance(obj.gameObject);
            AssetSprites[reference].Remove(obj.gameObject);
            if (AssetSprites[reference].Count == 0)
            {
                if (OperationHandles[reference].IsValid())
                {
                    Addressables.Release(OperationHandles[reference]);
                }

                OperationHandles.Remove(reference);
            }
        }
Ejemplo n.º 2
0
        // TODO: Potentially implement this for perf... right now, we're just loading all into memory and using that, but this is more of an
        // on demand system, which would be more optimal
        // Taken from https://www.youtube.com/watch?v=uNpBS0LPhaU
        public static void LoadAsset(int index)
        {
            AssetReference reference = AssetReferences[index];

            if (!reference.RuntimeKeyIsValid())
            {
                Debug.Log("DANGER!");
                return;
            }

            if (OperationHandles.ContainsKey(reference))
            {
                if (OperationHandles[reference].IsDone)
                {
                    SpawnObject(reference);
                }
                else
                {
                    //AssetQueue.Add(reference, )
                }

                return;
            }

            var op = Addressables.LoadAssetAsync <GameObject>(reference);

            // TODO: Add to dictionary?
            op.Completed += (operation) => {
                if (AssetQueue.ContainsKey(reference))
                {
                    while (AssetQueue[reference]?.Any() == true)
                    {
                        Vector3 position = AssetQueue[reference].Dequeue();
                        SpawnObject(reference);
                    }
                }
            };
        }