예제 #1
0
        /// <summary>
        /// 同步加载资源
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="path"></param>
        /// <returns></returns>
        public T LoadAssets <T>(string path) where T : UnityEngine.Object
        {
            using (zstring.Block())
            {
                zstring assetName = path.ToLower();
                zstring ext       = Path.GetExtension(assetName);
                if (!zstring.IsNullOrEmpty(ext))
                {
                    assetName = assetName.Replace(ext, "");
                }

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

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

                var asset = bundle.LoadAsset(assetName) as T;
                if (asset == null)
                {
                    Debug.LogWarning(zstring.Format("Cant find ab: {0}", assetName));
                }
                return(asset);
            }
        }
예제 #2
0
        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);
            }
        }