Esempio n. 1
0
    static public Asset Load(string name)
    {
        Asset asset = AssetMgr.Load(name);

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

        asset.OnAssetLoaded = delegate(Object obj)
        {
            if (uiRoot == null)
            {
                uiRoot = NGUITools.CreateUI(false);
                GameObject.DontDestroyOnLoad(uiRoot.gameObject);
                //uiRoot.camera.audio.enabled = false;
                AudioListener al = (AudioListener)uiRoot.GetComponentInChildren <AudioListener>();
                al.enabled = false;
            }

            GameObject go = NGUITools.AddChild(uiRoot.gameObject, obj as GameObject);
            go.name = go.name.Replace("(Clone)", "");
        };

        return(asset);
    }
    public void PrepareConfig(string config)
    {
        config = config.ToLower();
        string[] settings = config.Split('|');
        currentCharacter = settings[0];
        Asset asset = AssetMgr.Load(currentCharacter);

        asset.OnAssetLoaded += delegate(Object obj)
        {
            root = (GameObject)GameObject.Instantiate(obj);
        };


        currentConfiguration = new Dictionary <string, CharacterElement>();
        for (int i = 1; i < settings.Length;)
        {
            string elementName = settings[i++];
            asset = AssetMgr.Load(elementName);
            if (asset.LoadAssetAsync == null)
            {
                asset.LoadAssetAsync = delegate(Bundle bundle)
                {
                    return(new CharacterRequest(elementName, bundle));
                };
            }

            asset.OnAssetLoaded += delegate(Object obj)
            {
                currentConfiguration.Add(elementName, obj as CharacterElement);
                if ((OnCharacterLoaded != null) && (currentConfiguration.Count == settings.Length - 1))
                {
                    OnCharacterLoaded();
                }
            };
        }
    }
Esempio n. 3
0
    void LoadHotFixAssembly()
    {
        Appdomain = new AppDomain();
        _pdb      = null;

        byte[] dll;

#if UNITY_EDITOR
        //开发模式
        if (!AssetMgr.RuntimeMode)
        {
            if (File.Exists(DLLPath)) //直接读DLL
            {
                dll = DLLMgr.FileToByte(DLLPath);

                //模拟加密
                dll = CryptoHelper.AesEncrypt(dll, key);
            }
            else
            {
                Log.PrintError("DLL文件不存在");
                return;
            }

            //查看是否有PDB文件
            if (File.Exists(PdbPath) && usePdb &&
                (File.GetLastWriteTime(DLLPath) - File.GetLastWriteTime(PdbPath)).Seconds < 30)
            {
                _pdb = new MemoryStream(DLLMgr.FileToByte(PdbPath));
            }
        }
        else //真机模式解密加载
#endif
        {
            var dllFile = (TextAsset)AssetMgr.Load(DllName, typeof(TextAsset));
            if (dllFile == null)
            {
                return;
            }

            dll = dllFile.bytes;
        }

        var buffer = new byte[dll.Length];
        Array.Copy(dll, buffer, dll.Length);
        AssetMgr.Unload(DllName, true);

        try
        {
            //这里默认用分块解密,JStream
            _fs = new JStream(buffer, key);

            /*
             * 如果一定要直接解密然后不进行分块解密加载Dll,可以这样:
             * var original = CryptoHelper.AesDecrypt(dll.bytes, Key);
             * _fs = new JStream(original, Key);
             * _fs.Encrypted = false;
             */

            Appdomain.LoadAssembly(_fs, _pdb, new PdbReaderProvider());
        }
        catch (Exception e)
        {
            Log.PrintError("加载热更DLL错误:\n" + e);
            if (!usePdb)
            {
                Log.PrintError(
                    "加载热更DLL失败,请确保HotUpdateResources/Dll里面有HotUpdateScripts.bytes文件,并且Build Bundle后将DLC传入服务器");
                Log.PrintError("也有可能是密码不匹配或密码包含特殊字符导致的");
            }
            else
            {
                Log.PrintError("PDB不可用,可能是DLL和PDB版本不一致,可能DLL是Release,如果是Release出包,请取消UsePdb选项,本次已跳过使用PDB");
                usePdb = false;
                LoadHotFixAssembly();
            }

            return;
        }

        Success = true;
        LoadILRuntime.InitializeILRuntime(Appdomain);
    }