public MemoryStream LoadResource_LuaScript(string filePath)
    {
        if (UniGameResources.gameResourcesWorkMode == GameResourcesWorkMode.Mode_AloneSecurity)
        {
            try
            {
#if _Develop
                FileStream file = new FileStream(UniGameResources.ConnectPath(UniGameResources.DataPath, UniGameResourcesDefine.DefineAssetBundleName_LuaScript, "/", filePath), FileMode.Open, FileAccess.Read, FileShare.Read);
                file.Seek(0, SeekOrigin.Begin);
                byte[] buffer = new byte[file.Length];
                file.Read(buffer, 0, buffer.Length);
                file.Close();
                return(new MemoryStream(buffer));
#else
                return(luaScriptReaderSecurity.Load(filePath));
#endif//_Develop
            }
            catch (System.Exception ex)
            {
                Debug.LogError(ex.ToString());
                return(null);
            }
        }
        else if (UniGameResources.gameResourcesWorkMode == GameResourcesWorkMode.Mode_Mobile)
        {
            if (luaScriptPackage == null)
            {
                throw new Exception("cant find lua script package!");
            }
            luaScriptPackage.LockPackage();
#if UNITY_4_3 || UNITY_4_6
            TextAsset textAsset = luaScriptPackage.currentAssetBundle.Load(filePath, typeof(TextAsset)) as TextAsset;
#else
            TextAsset textAsset = luaScriptPackage.currentAssetBundle.LoadAsset(filePath, typeof(TextAsset)) as TextAsset;
#endif
            MemoryStream ret = null;
            try
            {
                byte[] luadata = textAsset.bytes;
                luadata = Convert.FromBase64String(Encoding.ASCII.GetString(luadata));
                //解密数据
#if _SupportDeviceVerify
                luadata = luaScriptFileEncipher.FileDecrypt(luadata, true);
#else
                luadata = luaScriptFileEncipher.FileDecrypt(luadata);
#endif //_SupportDeviceVerify
                ret = new MemoryStream(luadata);
            }
            catch (System.Exception ex)
            {
                Debug.LogError(ex.ToString());
                ret = null;
            }
            UniGameResources.ReleaseOneAssets(textAsset);
            luaScriptPackage.UnLockPackage();
            return(ret);
        }
        return(null);
    }
    private XmlDocument LoadResource_PublicXmlDocument(ref GameResourcesNode data, Encoding code)
    {
        if (UniGameResources.gameResourcesWorkMode == GameResourcesWorkMode.Mode_AloneSecurity)
        {
            try
            {
#if _Develop
                XmlDocument doc = new XmlDocument();
                doc.Load(UniGameResources.ConnectPath(UniGameResources.DataPath, data.packageName, "/", data.path));
                return(doc);
#else
                return(xmlPublicReaderSecurity.LoadXml(UniGameResources.ConnectPath(UniGameResources.DataPath, data.packageName, "/", data.path)));
#endif//_Develop
            }
            catch (System.Exception ex)
            {
                Debug.LogError(ex.ToString());
                return(null);
            }
        }
        else if (UniGameResources.gameResourcesWorkMode == GameResourcesWorkMode.Mode_Mobile)
        {
            UniGameResourcesPackage package = (UniGameResourcesPackage)data.package;
            package.LockPackage();
#if UNITY_4_3 || UNITY_4_6
            TextAsset textAsset = package.currentAssetBundle.Load(data.path, typeof(TextAsset)) as TextAsset;
#else
            TextAsset textAsset = package.currentAssetBundle.LoadAsset(data.path, typeof(TextAsset)) as TextAsset;
#endif
            XmlDocument doc = null;
            try
            {
                byte[] xmldata = textAsset.bytes;
                xmldata = Convert.FromBase64String(Encoding.ASCII.GetString(xmldata));
                //解密数据
#if _SupportDeviceVerify
                xmldata = xmlFileEncipher.FileDecrypt(xmldata, true);
#else
                xmldata = xmlFileEncipher.FileDecrypt(xmldata);
#endif //_SupportDeviceVerify
                //MemoryStream s = new MemoryStream(xmldata);
                doc = new XmlDocument();
                doc.LoadXml(code.GetString(xmldata));
                //s.Close();
            }
            catch (System.Exception ex)
            {
                Debug.LogError(ex.ToString());
                doc = null;
            }
            UniGameResources.ReleaseOneAssets(textAsset);
            package.UnLockPackage();
            return(doc);
        }
        return(null);
    }
Exemplo n.º 3
0
    public void InitializationName(string luaScriptName, uint storeMethodMask, OnStoreMethod storeMethod)
    {
        try
        {
            if (UniGameResources.currentUniGameResources == null)
            {
                throw new Exception("UniGameResources.currentUniGameResources == null!");
            }
            FTLibrary.Resources.GameResourcesNode data = new FTLibrary.Resources.GameResourcesNode();
            if (!UniGameResources.currentUniGameResources.FindResources(UniGameResourcesDefine.ResourcesTypeIndex_LuaScript,
                                                                        luaScriptName, ref data))
            {
                throw new Exception(string.Format("cant find lua script!name={0}", luaScriptName));
            }

            if (UniGameResources.gameResourcesWorkMode == UniGameResources.GameResourcesWorkMode.Mode_AloneSecurity)
            {
                try
                {
                    InitializationFile(data.path, storeMethodMask, storeMethod);
                }
                catch (System.Exception ex)
                {
                    Debug.LogError(ex.ToString());
                }
            }
            else if (UniGameResources.gameResourcesWorkMode == UniGameResources.GameResourcesWorkMode.Mode_Mobile)
            {
                UniGameResourcesPackage package = (UniGameResourcesPackage)data.package;
                package.LockPackage();
                try
                {
                    InitializationFile(data.path, storeMethodMask, storeMethod);
                }
                catch (System.Exception ex)
                {
                    Debug.LogError(ex.ToString());
                }
                package.UnLockPackage();
            }
        }
        catch (System.Exception ex)
        {
            Debug.LogError(ex.ToString());
        }
    }
    public IEnumerator LoadingAssetObject(string packageName, string assetName, uint assetGuid, Type type, bool isInstantiate)
    {
        UniGameResourcesDownLoader loader = AllocResourcesDownLoader_DontDestroyOnLoad();

        yield return(StartCoroutine(loader.DownloadPackage(packageName)));

        UniGameResourcesPackage package = UniGameResources.FindSystemResourcesPackageTable(packageName);

        if (package == null)
        {
            Debug.LogError(string.Format("not find package:{0}", packageName));
            yield break;
        }
        UnityEngine.Object obj = null;
        package.LockPackage();
        try
        {
            if (isInstantiate)
            {
#if UNITY_4_3 || UNITY_4_6
                obj = GameObject.Instantiate(package.currentAssetBundle.Load(assetName, type));
#else
                obj = GameObject.Instantiate(package.currentAssetBundle.LoadAsset(assetName, type));
#endif
            }
            else
            {
#if UNITY_4_3 || UNITY_4_6
                obj = package.currentAssetBundle.Load(assetName, type);
#else
                obj = package.currentAssetBundle.LoadAsset(assetName, type);
#endif
            }
        }
        catch (System.Exception ex)
        {
            Debug.LogError(ex.ToString());
        }
        package.UnLockPackage();

        loadingAssetTree.Add(assetGuid, obj);
        ReleaseResourcesDownLoader(loader);
    }
    private byte[] LoadResource_ByteFile(ref GameResourcesNode data)
    {
        if (UniGameResources.gameResourcesWorkMode == GameResourcesWorkMode.Mode_AloneSecurity)
        {
            try
            {
                string     path   = UniGameResources.ConnectPath(UniGameResources.DataPath, data.packageName, "/", data.path);
                FileStream file   = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, 4096);
                byte[]     buffer = new byte[file.Length];
                file.Read(buffer, 0, buffer.Length);
                file.Close();
                return(buffer);
            }
            catch (System.Exception ex)
            {
                Debug.LogError(ex.ToString());
                return(null);
            }
        }
        else if (UniGameResources.gameResourcesWorkMode == GameResourcesWorkMode.Mode_Mobile)
        {
            UniGameResourcesPackage package = (UniGameResourcesPackage)data.package;
            package.LockPackage();
#if UNITY_4_3 || UNITY_4_6
            TextAsset textAsset = package.currentAssetBundle.Load(data.path, typeof(TextAsset)) as TextAsset;
#else
            TextAsset textAsset = package.currentAssetBundle.LoadAsset(data.path, typeof(TextAsset)) as TextAsset;
#endif
            byte[] buffer = textAsset.bytes;
            buffer = Convert.FromBase64String(Encoding.ASCII.GetString(buffer));
            //解密数据
#if _SupportDeviceVerify
            buffer = xmlFileEncipher.FileDecrypt(buffer, true);
#else
            buffer = xmlFileEncipher.FileDecrypt(buffer);
#endif //_SupportDeviceVerify
            UniGameResources.ReleaseOneAssets(textAsset);
            package.UnLockPackage();
            return(buffer);
        }
        return(null);
    }
    private UnityEngine.Object PrivateLoadResource(ref GameResourcesNode data, Type type, bool isInstantiate)
    {
        //如果是系统资源包就换个函数加载
        if (data.packageId == UniGameResourcesDefine.DefineSystemAssetBundleId)
        {
            return(PrivateLoadResource_Resource(ref data, type, isInstantiate));
        }
        else if (UniGameResources.gameResourcesWorkMode == GameResourcesWorkMode.Mode_AloneSecurity)
        {
            try
            {
                if (isInstantiate)
                {
#if UNITY_4_3 || UNITY_4_6
                    return(GameObject.Instantiate(Resources.LoadAssetAtPath(UniGameResources.ConnectPath(UniGameResources.DataPath, data.packageName, "/", data.path), type)));
#else
                    return(GameObject.Instantiate(Resources.Load(UniGameResources.ConnectPath(UniGameResources.DataPath, data.packageName, "/", data.path), type)));
#endif
                }
                else
                {
#if UNITY_4_3 || UNITY_4_6
                    return(Resources.LoadAssetAtPath(UniGameResources.ConnectPath(UniGameResources.DataPath, data.packageName, "/", data.path), type));
#else
                    return(Resources.Load(UniGameResources.ConnectPath(UniGameResources.DataPath, data.packageName, "/", data.path), type));
#endif
                }
            }
            catch (System.Exception ex)
            {
                Debug.LogError(ex.ToString());
                return(null);
            }
        }
        else if (UniGameResources.gameResourcesWorkMode == GameResourcesWorkMode.Mode_Mobile)
        {
            UnityEngine.Object      ret     = null;
            UniGameResourcesPackage package = (UniGameResourcesPackage)data.package;
            package.LockPackage();
            try
            {
                if (isInstantiate)
                {
#if UNITY_4_3 || UNITY_4_6
                    ret = GameObject.Instantiate(package.currentAssetBundle.Load(data.path, type));
#else
                    ret = GameObject.Instantiate(package.currentAssetBundle.LoadAsset(data.path, type));
#endif
                }
                else
                {
#if UNITY_4_3 || UNITY_4_6
                    ret = package.currentAssetBundle.Load(data.path, type);
#else
                    ret = package.currentAssetBundle.LoadAsset(data.path, type);
#endif
                }
            }
            catch (System.Exception ex)
            {
                Debug.LogError(ex.ToString());
            }
            package.UnLockPackage();
            return(ret);
        }
        return(null);
    }