コード例 #1
0
ファイル: AssetBundleManager.cs プロジェクト: Liangzg/GEX_1.X
        public Sprite LoadSprite(GameObject owner, string spriteName, string atlasName)
        {
            using (zstring.Block())
            {
                zstring assetName = atlasName.ToLower();
                zstring ext       = Path.GetExtension(assetName);
                if (!string.IsNullOrEmpty(ext))
                {
                    assetName = assetName.Replace(ext, "");
                }

                string bundleRelativePath = assetName;
                if (!assetbundleMap.TryGetValue(assetName, out bundleRelativePath))
                {
                    Debug.LogWarning(zstring.Format("{0} has no assetbundle resource", assetName));
                    return(null);
                }

                UIAtlasCache atlasCache = null;
                if (!atlasMap.TryGetValue(bundleRelativePath, out atlasCache))
                {
                    AssetBundle bundle = TryGetBundleByFile(assetName);
                    if (bundle == null)
                    {
                        return(null);
                    }

                    var assets = bundle.LoadAllAssets <Sprite>();
                    if (assets == null)
                    {
                        Debug.LogWarning(zstring.Format("Cant find sprite: {0} in bundle {1}", spriteName, bundleRelativePath));
                    }

                    atlasCache = new UIAtlasCache(assets);
                    atlasMap[bundleRelativePath] = atlasCache;
                }

                Sprite         sprite  = atlasCache.GetSprite(spriteName);
                TextureWatcher watcher = owner.transform.GetOrAddComponent <TextureWatcher>();
                watcher.AddBundleName(bundleRelativePath);

                return(sprite);
            }
        }
コード例 #2
0
ファイル: AssetBundleManager.cs プロジェクト: Liangzg/GEX_1.X
        public Texture LoadTexture(GameObject owner, string assetPath)
        {
            using (zstring.Block())
            {
                zstring assetName = assetPath.ToLower();
                zstring ext       = Path.GetExtension(assetName);
                if (!zstring.IsNullOrEmpty(ext))
                {
                    assetName = assetName.Replace(ext, "");
                }

                AssetBundle bundle = TryGetBundleByFile(assetName);
                if (bundle == null)
                {
                    return(null);
                }

                TextureWatcher watcher = owner.transform.GetOrAddComponent <TextureWatcher>();
                string         bundleName;
                if (assetbundleMap.TryGetValue(assetName, out bundleName))
                {
                    watcher.AddBundleName(bundleName);
                }

                string assetRoot = GResource.RuntimeAssetsRoot.ToLower();
                if (!assetName.StartsWith(assetRoot))
                {
                    assetName = zstring.Concat(assetRoot, assetPath);
                }

                var asset = bundle.LoadAsset(assetName) as Texture;
                if (asset == null)
                {
                    Debug.LogWarning(zstring.Format("Cant find ab: {0}", assetName));
                }
                return(asset);
            }
        }