Exemple #1
0
        /// <summary>
        /// 创建Asset
        /// </summary>
        /// <param name="type"></param>
        /// <param name="data"></param>
        /// <param name="assetBundle"></param>
        /// <param name="bytes"></param>
        /// <returns></returns>
        public static IAsset CreateAsset(LoadType type, object data, AssetBundle assetBundle = null, byte[] bytes = null)
        {
            IAsset asset;

            switch (type)
            {
            case LoadType.BINARY:
                asset = new BinaryAsset();
                break;

            case LoadType.BYTEARRAY:
                asset = new ByteArrayAsset();
                break;

            case LoadType.TEXT:
                asset = new TxtAsset();
                break;

            case LoadType.JSON:
                asset = new JSONAsset();
                break;

            case LoadType.XML:
                asset = new XMLAsset();
                break;

            case LoadType.ASSETBUNDLE:
                asset = new AssetBundleAsset();
                break;

            case LoadType.TEXTURE:
            case LoadType.TEXTURE_ASSET_BUNDLE:
                asset = new TextureAsset();
                break;

            case LoadType.AUDIO:
            case LoadType.AUDIO_ASSET_BUNDLE:
                asset = new AudioAsset();
                break;

            case LoadType.ACTION:
                asset = new ActionAsset();
                break;

            case LoadType.TEXTURE_EXT:
                asset = new TextureExtAsset();
                break;

            case LoadType.TEXTURE_EXT_SPRITE:
                asset = new TextureExtSpriteAsset();
                break;

            default:
                asset = new TxtAsset();
                break;
            }

            // 将加载器中的资源填充到资源中
            asset.asset       = data;
            asset.assetBundle = assetBundle;
            //asset.bytes = bytes;

            return(asset);
        }
Exemple #2
0
        /// <summary>
        /// 从原始数据重创建资源
        /// </summary>
        /// <param name="type"></param>
        /// <param name="url"></param>
        /// <param name="assetBundle"></param>
        /// <param name="bytes"></param>
        /// <returns></returns>
        public IAsset CreateAssetFromAssetBundle(LoadType type, string url, AssetBundle assetBundle, byte[] bytes = null)
        {
            IAsset asset;
            string fileName;

            switch (type)
            {
            case LoadType.ASSETBUNDLE:
                asset       = new AssetBundleAsset();
                asset.asset = assetBundle;
                break;

            case LoadType.TEXTURE_ASSET_BUNDLE:
                asset       = new TextureAsset();
                fileName    = UrlUtil.GetFileName(url);
                asset.asset = assetBundle.LoadAsset <Texture2D>(fileName);
                break;

            case LoadType.AUDIO_ASSET_BUNDLE:
                asset       = new AudioAsset();
                fileName    = UrlUtil.GetFileName(url);
                asset.asset = assetBundle.LoadAsset <AudioClip>(fileName);
                break;

            case LoadType.ACTION:
                asset    = new ActionAsset();
                fileName = UrlUtil.GetFileName(url);
                ActionData actionData = App.objectPoolManager.GetObject <ActionData>();
                actionData.Init(fileName, assetBundle);
                asset.asset = actionData;
                break;

            case LoadType.TEXTURE_EXT:
                asset    = new TextureExtAsset();
                fileName = UrlUtil.GetFileName(url);
                TextureExt textureExt = App.objectPoolManager.GetObject <TextureExt>();
                textureExt.Init(fileName, assetBundle);
                asset.asset = textureExt;
                break;

            case LoadType.TEXTURE_EXT_SPRITE:
                asset    = new TextureExtSpriteAsset();
                fileName = UrlUtil.GetFileName(url);
                TextureExtSprite textureExtSprite = App.objectPoolManager.GetObject <TextureExtSprite>();
                textureExtSprite.Init(fileName, assetBundle);
                asset.asset = textureExtSprite;
                break;

            default:
                asset = null;
                break;
            }

            if (asset == null)
            {
                return(null);
            }

            asset.assetBundle = assetBundle;
            //asset.bytes = bytes;
            return(asset);
        }