Ejemplo n.º 1
0
        public void Unload()
        {
            AssetManager assetManager = Service.Get <AssetManager>();

            foreach (Queue <WorldPreloadAsset> current in this.preloadedAssets.Values)
            {
                int i     = 0;
                int count = current.Count;
                while (i < count)
                {
                    WorldPreloadAsset worldPreloadAsset = current.Dequeue();
                    if (worldPreloadAsset.GameObj != null && assetManager.IsAssetCloned(worldPreloadAsset.AssetName))
                    {
                        UnityEngine.Object.Destroy(worldPreloadAsset.GameObj);
                        worldPreloadAsset.GameObj = null;
                    }
                    if (worldPreloadAsset.Handle != AssetHandle.Invalid)
                    {
                        assetManager.Unload(worldPreloadAsset.Handle);
                        worldPreloadAsset.Handle = AssetHandle.Invalid;
                    }
                    i++;
                }
            }
            this.preloadedAssets.Clear();
        }
Ejemplo n.º 2
0
 private void OnAssetLoadSuccess(object asset, object cookie)
 {
     if (asset != null)
     {
         GameObject gameObject = asset as GameObject;
         gameObject.SetActive(false);
         WorldPreloadAsset worldPreloadAsset = (WorldPreloadAsset)cookie;
         worldPreloadAsset.GameObj = gameObject;
     }
     if (--this.numAssetsRemainingToLoad == 0)
     {
         this.onPreloadSuccess();
     }
 }
Ejemplo n.º 3
0
        public WorldPreloadAsset GetPreloadedAsset(string assetName)
        {
            WorldPreloadAsset worldPreloadAsset = null;

            if (this.preloadedAssets.ContainsKey(assetName))
            {
                Queue <WorldPreloadAsset> queue = this.preloadedAssets[assetName];
                worldPreloadAsset = queue.Dequeue();
                if (queue.Count == 0)
                {
                    this.preloadedAssets.Remove(assetName);
                }
                if (worldPreloadAsset.GameObj != null)
                {
                    worldPreloadAsset.GameObj.SetActive(true);
                }
            }
            return(worldPreloadAsset);
        }
Ejemplo n.º 4
0
        public void Load(List <IAssetVO> assetsToLoad, WorldPreloader.PreloadSuccessDelegate onPreloadSuccess)
        {
            if (this.numAssetsRemainingToLoad != 0)
            {
                Service.Get <StaRTSLogger>().Error("WorldPreloader.Load() is called when it's still loading!");
                return;
            }
            int num = (assetsToLoad == null) ? 0 : assetsToLoad.Count;

            if (num == 0)
            {
                onPreloadSuccess();
                return;
            }
            this.onPreloadSuccess         = onPreloadSuccess;
            this.numAssetsRemainingToLoad = num;
            AssetManager assetManager = Service.Get <AssetManager>();

            for (int i = 0; i < num; i++)
            {
                string            assetName         = assetsToLoad[i].AssetName;
                WorldPreloadAsset worldPreloadAsset = new WorldPreloadAsset(assetName);
                assetManager.Load(ref worldPreloadAsset.Handle, assetName, new AssetSuccessDelegate(this.OnAssetLoadSuccess), new AssetFailureDelegate(this.OnAssetLoadFailure), worldPreloadAsset);
                Queue <WorldPreloadAsset> queue;
                if (this.preloadedAssets.ContainsKey(assetName))
                {
                    queue = this.preloadedAssets[assetName];
                }
                else
                {
                    queue = new Queue <WorldPreloadAsset>();
                    this.preloadedAssets.Add(assetName, queue);
                }
                queue.Enqueue(worldPreloadAsset);
            }
        }