Exemple #1
0
 private static AssetManager.Asset LoadAsset(AssetManager.Bundle bundle, string name, Type type, AssetManager.OnAssetLoaded assetLoaded, AssetManager.LoadAssetDelegate OnLoadAsset)
 {
     AssetManager.Asset asset = AssetManager.FindAsset(name);
     if (asset != null)
     {
         if (asset.State == AssetManager.State.Loaded)  //已经正确加载,重定向回调
         {
             asset.ClearEvents();
             asset.AssetLoaded += assetLoaded;
             asset.OnLoaded();
             return(asset);
         }
         AssetManager.StopLoadAsyncAsset(asset);
     }
     else
     {
         asset = new AssetManager.Asset();
         AssetManager.Assets.Add(name, asset);
     }
     asset.Name   = name;
     asset.Type   = type;
     asset.Bundle = bundle;
     asset.ClearEvents();   //如果先请求loadAsset,然后才loadBundle,不管前面的无效请求,只管loadBundle之后的loadAsset
     asset.AssetLoaded += assetLoaded;
     return(OnLoadAsset(asset));
 }
Exemple #2
0
 public static void OnGUI()
 {
     if (AssetManager.DebugInfo)
     {
         float num    = 10f;
         float top    = (float)Screen.height / 4f;
         float width  = (float)Screen.width - 2f * num;
         float height = (float)Screen.height / 2f;
         GUILayout.BeginArea(new Rect(num, top, width, height), GUI.skin.box);
         AssetManager.DebugScrollViewPosition = GUILayout.BeginScrollView(AssetManager.DebugScrollViewPosition, true, true, new GUILayoutOption[]
         {
             GUILayout.Width(width),
             GUILayout.Height(height)
         });
         GUI.color = Color.white;
         GUILayout.Label(string.Format("ASSET DEBUG\nActiveAssets:{0}\nAsyncActiveItems:{1}\nAsyncQueueAssets:{2}\n", AssetManager.ActiveAssetsCount, AssetManager.AsyncActiveItems.Count, AssetManager.AsyncQueueAssets.Count), new GUILayoutOption[0]);
         GUILayout.Label(string.Format("Bundles:{0}\nAsyncBundles:{1}\n", AssetManager.Bundles.Count, AssetManager.AsyncBundles.Count), new GUILayoutOption[0]);
         int num2 = 0;
         GUI.color = Color.yellow;
         foreach (KeyValuePair <string, AssetManager.Asset> current in AssetManager.Assets)
         {
             AssetManager.Asset value = current.Value;
             if (value.State == AssetManager.State.Loaded)
             {
                 GUILayout.Label(string.Format("{0}: {1}", num2++, value.Name), new GUILayoutOption[0]);
             }
         }
         GUILayout.EndScrollView();
         GUILayout.EndArea();
     }
 }
Exemple #3
0
 private static AssetManager.Asset OnLoadAssetFromBundle(AssetManager.Asset asset)
 {
     asset.AssetObject = asset.Bundle.AssetBundle.LoadAsset(AssetManager.GetBundleAssetName(asset.Name), asset.Type);
     if (asset.AssetObject == null)
     {
         AssetManager.AssetFailed(asset);
     }
     else
     {
         AssetManager.AssetLoaded(asset);
     }
     return(asset);
 }
Exemple #4
0
 private static AssetManager.Asset OnLoadAssetFromResources(AssetManager.Asset asset)
 {
     asset.AssetObject = ResourceManager.Load(asset.Name, asset.Type);
     if (asset.AssetObject == null)
     {
         AssetManager.AssetFailed(asset);
     }
     else
     {
         AssetManager.AssetLoaded(asset);
     }
     return(asset);
 }
Exemple #5
0
 public static bool UnloadAsset(AssetManager.Asset asset)
 {
     AssetManager.StopLoadAsyncAsset(asset);
     if (!AssetManager.Assets.Remove(asset.Name))
     {
         return(false);
     }
     if (asset.Bundle == null && (asset.Type == typeof(AnimationClip) || asset.Type == typeof(Texture2D) || asset.Type == typeof(Texture3D)))
     {
         Resources.UnloadAsset(asset.AssetObject);
     }
     asset.AssetObject = null;
     asset.Type        = null;
     asset.Bundle      = null;
     asset.State       = AssetManager.State.Invalid;
     return(true);
 }
Exemple #6
0
        public static void StopLoadAsyncAsset(AssetManager.Asset asset)
        {
            if (asset.State == AssetManager.State.Loaded)
            {
                return;
            }
            int num = AssetManager.AsyncQueueAssets.FindIndex((AssetManager.Asset a) => a == asset);

            if (num != -1)
            {
                AssetManager.AsyncQueueAssets.RemoveAt(num);
                return;
            }
            num = AssetManager.AsyncActiveItems.FindIndex((AssetManager.AsyncActiveItem i) => i.Asset == asset);
            if (num != -1)
            {
                AssetManager.AsyncActiveItems.RemoveAt(num);
                return;
            }
        }
Exemple #7
0
 private static void UpdateAssetLoading()
 {
     for (int i = 0; i < AssetManager.AsyncActiveItems.Count; i++)
     {
         AssetManager.AsyncActiveItem asyncActiveItem = AssetManager.AsyncActiveItems[i];
         bool flag  = false;
         bool flag2 = false;
         if (asyncActiveItem.Asset.Type == null)
         {
             if (asyncActiveItem.WWW.isDone)
             {
                 asyncActiveItem.Asset.AssetObject = asyncActiveItem.WWW.textureNonReadable;
                 flag = true;
             }
         }
         else if (asyncActiveItem.AssetBundleRequest != null)
         {
             if (asyncActiveItem.AssetBundleRequest.isDone)
             {
                 asyncActiveItem.Asset.AssetObject = asyncActiveItem.AssetBundleRequest.asset;
                 if (asyncActiveItem.Asset.AssetObject == null)
                 {
                     flag2 = true;
                 }
                 flag = true;
             }
         }
         else if (asyncActiveItem.ResourceRequest != null && asyncActiveItem.ResourceRequest.isDone)
         {
             asyncActiveItem.Asset.AssetObject = asyncActiveItem.ResourceRequest.asset;
             if (asyncActiveItem.Asset.AssetObject == null)
             {
                 flag2 = true;
             }
             flag = true;
         }
         if (flag)
         {
             AssetManager.AsyncActiveItems.RemoveAt(i--);
             if (flag2)
             {
                 AssetManager.AssetFailed(asyncActiveItem.Asset);
             }
             else
             {
                 AssetManager.AssetLoaded(asyncActiveItem.Asset);
             }
         }
     }
     if (AssetManager.AsyncQueueAssets.Count > 0)
     {
         int num = Mathf.Min(1 - AssetManager.AsyncActiveItems.Count, AssetManager.AsyncQueueAssets.Count);
         for (int j = 0; j < num; j++)
         {
             AssetManager.Asset           asset            = AssetManager.AsyncQueueAssets[0];
             AssetManager.AsyncActiveItem asyncActiveItem2 = new AssetManager.AsyncActiveItem();
             asyncActiveItem2.Asset = asset;
             bool flag3 = false;
             if (asset.Type == null)
             {
                 asyncActiveItem2.WWW = new WWW(asset.Name);
                 if (asyncActiveItem2.WWW != null)
                 {
                     flag3 = true;
                 }
             }
             else if (asset.Bundle != null)
             {
                 if (asset.Bundle.State == AssetManager.State.Loaded)
                 {
                     asyncActiveItem2.AssetBundleRequest = asset.Bundle.AssetBundle.LoadAssetAsync(AssetManager.GetBundleAssetName(asset.Name), asset.Type);
                     if (asyncActiveItem2.AssetBundleRequest != null)
                     {
                         flag3 = true;
                     }
                 }
             }
             else
             {
                 asyncActiveItem2.ResourceRequest = ResourceManager.LoadAsync(asset.Name, asset.Type);
                 if (asyncActiveItem2.ResourceRequest != null)
                 {
                     flag3 = true;
                 }
             }
             if (flag3)
             {
                 AssetManager.AsyncActiveItems.Add(asyncActiveItem2);
             }
             else
             {
                 AssetManager.AssetFailed(asyncActiveItem2.Asset);
             }
             AssetManager.AsyncQueueAssets.RemoveAt(0);
         }
     }
 }
Exemple #8
0
 private static AssetManager.Asset OnLoadAsyncAsset(AssetManager.Asset asset)
 {
     AssetManager.AsyncQueueAssets.Add(asset);
     return(asset);
 }
Exemple #9
0
 private static AssetManager.Asset OnLoadAssetFromEditorResources(AssetManager.Asset asset)
 {
     Assert.IsTrue(false, "Can't use LoadAssetFromEditorResources in non-editor mode!", new object[0]);
     return(asset);
 }
Exemple #10
0
 private static void AssetFailed(AssetManager.Asset asset)
 {
     asset.State = AssetManager.State.Failed;
     asset.OnFailed();
 }
Exemple #11
0
 private static void AssetLoaded(AssetManager.Asset asset)
 {
     asset.State = AssetManager.State.Loaded;
     asset.OnLoaded();
 }