Пример #1
0
        /// <summary>
        /// 加载单个AssetBundle根据名字
        /// </summary>
        /// <param name="name">AB 包名</param>
        /// <returns></returns>
        AssetBundle LoadAssetBundle(string name)
        {
            TAssetBundleItem item = null;
            uint             crc  = CRC32.GetCRC32(name);

            if (!mAssetBundleItemDic.TryGetValue(crc, out item))
            {
                AssetBundle assetBundel = null;

                string hotAbPath = HotPatchManager.Instance.ComputeABPath(name);
                string fullpath  = string.IsNullOrEmpty(hotAbPath) ? ABLoadPath + name : hotAbPath;
                byte[] bytes     = AES.AESFileByteDecrypt(fullpath, EdgeFrameworkConst.AESKEY);
                assetBundel = AssetBundle.LoadFromMemory(bytes);

                if (assetBundel == null)
                {
                    Debug.LogError("Load AssetBundle Error:" + fullpath);
                }

                item    = mAssetBundleItemPool.Allocate();
                item.AB = assetBundel;
                item.ReCount++;
                mAssetBundleItemDic.Add(crc, item);
            }
            else
            {
                item.ReCount++;
            }
            return(item.AB);
        }
Пример #2
0
    /// <summary>
    /// 加载单个assetbundle根据名字
    /// </summary>
    /// <param name="name"></param>
    /// <returns></returns>
    private AssetBundle LoadAssetBundle(string name)
    {
        AssetBundleItem item = null;
        uint            crc  = Crc32.GetCrc32(name);

        if (!m_AssetBundleItemDic.TryGetValue(crc, out item))
        {
            AssetBundle assetBundle = null;

            string hotABPath = HotPatchManager.Instance.ComputeABPath(name);
            //如果有热更的,走热更,没有就走本地
            string fullPath = string.IsNullOrEmpty(hotABPath) ? ABLoadPath + name : hotABPath;
            byte[] bytes    = AES.AESFileByteDecrypt(fullPath, "Ocean");
            assetBundle = AssetBundle.LoadFromMemory(bytes);

            if (assetBundle == null)
            {
                Debug.LogError(" Load AssetBundle Error:" + fullPath);
            }

            item             = m_AssetBundleItemPool.Spawn(true);
            item.assetBundle = assetBundle;
            item.RefCount++;
            m_AssetBundleItemDic.Add(crc, item);
        }
        else
        {
            item.RefCount++;
        }

        return(item.assetBundle);
    }
Пример #3
0
    static void DecryptAssetBunld()
    {
        string path = Application.streamingAssetsPath + "/" + EditorUserBuildSettings.activeBuildTarget + "/panel";

        // 对AB包进行解密
        byte[] bytes = AES.AESFileByteDecrypt(path, SECRET_KEY);
        // 从内存中加载AB包
        AssetBundle ab = AssetBundle.LoadFromMemory(bytes);
        // 加载AB包中的名字为Panel预制体
        GameObject prefab = ab.LoadAsset <GameObject>("Panel");

        // 实例化预制体到Canvas下
        GameObject.Instantiate(prefab, GameObject.Find("Canvas").transform);
    }
Пример #4
0
    /// <summary>
    /// 加载ab配置表
    /// </summary>
    /// <returns></returns>
    public bool LoadAssetBundleConfig()
    {
#if UNITY_EDITOR
        if (!ResourceManager.Instance.m_LoadFormAssetBundle)
        {
            return(false);
        }
#endif

        m_ResouceItemDic.Clear();
        string configPath = ABLoadPath + m_ABConfigABName;
        string hotABPath  = HotPatchManager.Instance.ComputeABPath(m_ABConfigABName);
        configPath = string.IsNullOrEmpty(hotABPath) ? configPath : hotABPath;
        byte[]      bytes     = AES.AESFileByteDecrypt(configPath, "Ocean");
        AssetBundle configAB  = AssetBundle.LoadFromMemory(bytes);
        TextAsset   textAsset = configAB.LoadAsset <TextAsset>(m_ABConfigABName);
        if (textAsset == null)
        {
            Debug.LogError("AssetBundleConfig is no exist!");
            return(false);
        }

        MemoryStream      stream = new MemoryStream(textAsset.bytes);
        BinaryFormatter   bf     = new BinaryFormatter();
        AssetBundleConfig config = (AssetBundleConfig)bf.Deserialize(stream);
        stream.Close();

        for (int i = 0; i < config.ABList.Count; i++)
        {
            ABBase      abBase = config.ABList[i];
            ResouceItem item   = new ResouceItem();
            item.m_Crc               = abBase.Crc;
            item.m_AssetName         = abBase.AssetName;
            item.m_ABName            = abBase.ABName;
            item.m_DependAssetBundle = abBase.ABDependce;
            if (m_ResouceItemDic.ContainsKey(item.m_Crc))
            {
                Debug.LogError("重复的Crc 资源名:" + item.m_AssetName + " ab包名:" + item.m_ABName);
            }
            else
            {
                m_ResouceItemDic.Add(item.m_Crc, item);
            }
        }

        return(true);
    }