Esempio n. 1
0
        public static void Add(string path, string objectName, Action <GameObject> onAssetLoaded)
        {
            GetBundle("kerbokatz");
            var dataPath   = GetPath(path);
            var loaderInfo = new LoaderInfo();

            loaderInfo.path          = path;
            loaderInfo.objectName    = objectName;
            loaderInfo.onAssetLoaded = onAssetLoaded;
            AssetBundle bundle;

            if (!CheckBundle(dataPath, out bundle))
            {
                if (instance != null)
                {
                    instance.StartCoroutineForBundle(path);
                    pathsToLoad.TryGetOrAdd(path).Add(loaderInfo);
                    return;
                }
                else
                {
                    bundle = GetBundle(path);
                }
            }
            SetLoaderReady(loaderInfo, bundle);
        }
Esempio n. 2
0
        private static void SetLoaderReady(LoaderInfo loaderInfo, AssetBundle assetBundle)
        {
            var loadedAsset = assetBundle.LoadAsset <GameObject>(loaderInfo.objectName);

            if (loadedAsset == null)
            {
                var sb = new StringBuilder();
                foreach (var asset in assetBundle.GetAllAssetNames())
                {
                    sb.AppendLine(asset);
                }
                Log("Failed to load asset. Does the asset(", loaderInfo.objectName, ") exist in the specified bundle(", loaderInfo.path, ") ? But found:", sb.ToString());
                return;
            }
            loaderInfo.onAssetLoaded(loadedAsset);
            loaderInfo.isReady = true;
        }