/// <summary>

        #region 启动热更逻辑

        /// <summary>
        /// 初始化
        /// 修改版本,让这个启动逻辑由使用者自行处理
        /// </summary>
        /// <param name="mainProjectTypes">Editor模式下,UPM隔离了DLL需要手动传入</param>
        /// <param name="GameId">单游戏更新启动不需要id,多游戏更新需要id号</param>
        public void Launch(Type[] mainProjectTypes, Action <bool> clrBindingAction, string gameId = "default")
        {
            BDebug.Log("Persistent:" + Application.persistentDataPath);
            BDebug.Log("StreamingAsset:" + Application.streamingAssetsPath);
            //主工程启动
            IGameStart mainStart;

            foreach (var type in mainProjectTypes)
            {
                if (type.GetInterface(nameof(IGameStart)) != null)
                {
                    mainStart = Activator.CreateInstance(type) as IGameStart;
                    //注册
                    mainStart.Start();
                    OnUpdate     += mainStart.Update;
                    OnLateUpdate += mainStart.LateUpdate;
                    break;
                }
            }

            //开始资源检测
            AssetHelper.AssetHelper.CheckAssetPackageVersion(Application.platform, () =>
            {
                //1.美术目录
                BResources.Load(GameConfig.ArtRoot, GameConfig.CustomArtRoot);
                //2.sql
                SqliteLoder.Load(GameConfig.SQLRoot);
                //3.脚本,这个启动会开启所有的逻辑
                ScriptLoder.Load(GameConfig.CodeRoot, GameConfig.CodeRunMode, mainProjectTypes, clrBindingAction);
            });
        }
Beispiel #2
0
        /// <summary>
        /// 对比
        /// 原则上认为StreamingAsset资源为母包携带,且完整
        /// </summary>
        private Queue <AssetItem> Compare(List <AssetItem> localAssetsInfo, List <AssetItem> serverAssetsInfo, RuntimePlatform platform)
        {
            var diffQueue = new Queue <AssetItem>();

            //比对平台
            foreach (var serverAsset in serverAssetsInfo)
            {
                //比较本地配置是否有 hash、文件名一致的资源
                var result = localAssetsInfo.FirstOrDefault((info) => serverAsset.Equals(info));
                //不存在
                if (result == null)
                {
                    diffQueue.Enqueue(serverAsset);
                }
                else
                {
                    if (!BResources.IsExsitAsset(platform, serverAsset.LocalPath, serverAsset.HashName))
                    {
                        diffQueue.Enqueue(serverAsset);
                    }
                }
            }


            return(diffQueue);
        }
Beispiel #3
0
 /// <summary>
 /// 从缓存中卸载 实例化的资源
 /// </summary>
 /// <param name="assetLoadPath">api传入的加载路径,Runtime下的相对路径</param>
 /// <returns></returns>
 public void UnloadObjectCache(Type type, string assetLoadPath)
 {
     if (type != null)
     {
         //卸载指定类型的缓存资源
         var ret = GameObjectCacheMap.TryGetValue(type, out var map);
         if (ret)
         {
             ret = map.TryGetValue(assetLoadPath, out var gobj);
             if (ret)
             {
                 //卸载
                 BResources.UnloadAsset(gobj);
                 map.Remove(assetLoadPath);
             }
         }
     }
     else
     {
         //卸载所有同名的缓存资产
         foreach (var typeMap in GameObjectCacheMap.Values)
         {
             var ret = typeMap.TryGetValue(assetLoadPath, out var gobj);
             if (ret)
             {
                 //卸载
                 BResources.UnloadAsset(gobj);
                 typeMap.Remove(assetLoadPath);
             }
         }
     }
 }
Beispiel #4
0
    /// <summary>
    /// 异步加载
    /// </summary>
    /// <param name="callback"></param>
    public void AsyncLoad(Action callback)
    {
        //  JDeBug.Inst.Log("开始任务:" + resourcePath);
        BResources.AsyncLoad <GameObject>(resourcePath, (result, o) =>
        {
            if (o != null)
            {
                var go    = GameObject.Instantiate(o);
                Transform = go.transform;
                Transform.gameObject.SetActive(false);
                IsLoad = true;
                //自动查找节点
                UITools.AutoSetTransformPath(this);
                Init();
            }
            else
            {
                BDebug.LogError("窗口资源不存在:" + this.GetType().FullName);
            }

            if (callback != null)
            {
                callback();
            }
        });
    }
Beispiel #5
0
    /// <summary>
    /// 获取子包
    /// </summary>
    private void OnClick_GetSubPackage()
    {
        var url = "http://" + inputField.text;

        BResources.GetServerSubPacks(url, (map) =>
        {
            //获取到子包
            Debug.Log("获取到子包信息:\n" + JsonMapper.ToJson(map, true));

            //全隐藏
            var grid = this.transform.Find("grid_SubPack");
            foreach (Transform child in grid)
            {
                child.gameObject.SetActive(false);
            }
            //显示
            var idx = 0;
            foreach (var kv in map)
            {
                var btn = grid.GetChild(idx)?.GetComponent <Button>();
                btn.gameObject.SetActive(true);
                btn.onClick.RemoveAllListeners();
                btn.transform.GetChild(0).GetComponent <Text>().text = "下载子包:" + kv.Key;
                //添加监听
                btn.onClick.AddListener(() =>
                {
                    //下载
                    this.Onclick_DownloadSubPackageLoadAndLaunch((kv.Key));
                });

                idx++;
            }
        });
    }
        static public void LoadALL()
        {
            //同个目录
            var objs = BResources.LoadALL <Sprite>("LoadAllTest/timg");

            Assert.Equals(objs.Length, 4);
        }
Beispiel #7
0
        static public void LoadSameNameAsset()
        {
            //同个目录
            var o   = BResources.Load <GameObject>("AssetTest/Cube");
            var mat = BResources.Load <Material>("AssetTest/Cube");

            Assert.IsPass(o != null && mat != null, "加载同名文件失败!");
        }
 static public void InitEditorFrame()
 {
     //BD生命周期启动
     BDApplication.Init();
     BDFrameEditorConfigHelper.Init();
     //编辑器下加载初始化
     BResources.Load(AssetLoadPath.Editor);
 }
Beispiel #9
0
        /// <summary>
        /// 初始化框架编辑器
        /// </summary>
        static public void InitEditorEnvironment()
        {
            //是否为batchmode
            if (Application.isBatchMode)
            {
                Debug.Log("BDFramework version:" + BDLauncher.Version);
            }

            //只有在非Playing的时候才初始化
            if (EditorApplication.isPlayingOrWillChangePlaymode || IsInited)
            {
                return;
            }

            try
            {
                //BD初始化
                //BApplication.Init();
                //BDEditor初始化
                BDEditorApplication.Init();
                //加载主工程的DLL Type
                var assemblyPath      = BApplication.Library + "/ScriptAssemblies/Assembly-CSharp.dll";
                var editorAssemlyPath = BApplication.Library + "/ScriptAssemblies/Assembly-CSharp-Editor.dll";
                if (File.Exists(assemblyPath) && File.Exists(editorAssemlyPath))
                {
                    var gAssembly = Assembly.LoadFile(assemblyPath);
                    var eAssemlby = Assembly.LoadFile(editorAssemlyPath);
                    Types = CollectTypes(gAssembly, eAssemlby).ToArray();
                }

                //编辑器下加载初始化
                BResources.Init(AssetLoadPathType.Editor);
                //编辑器下管理器注册
                ManagerInstHelper.Load(Types);
                //Editor的管理器初始化
                BDFrameworkPipelineHelper.Init();
                //调试器启动
                DebuggerServerProcessManager.Inst.Start();
                //Pipeline初始化
                HotfixPipelineTools.Init();
                //编辑器初始化
                InitEditorTask();
                //编辑器任务
                EditorTaskInstance.OnUnityLoadOrCodeRecompiled();
                //编辑器http服务
                InitEditorHttpServer();
                //最后,完成初始化
                IsInited = true;
                //  Debug.Log("框架编辑器环境初始化成功!");
            }
            catch (Exception e)
            {
                Debug.LogError("框架编辑器环境初始化失败!");
                Debug.LogError(e);
                throw;
            }
        }
Beispiel #10
0
    private void btn_06()
    {
        List <GameObject> golist = new List <GameObject>();
        //1.同步加载
        var go    = BResources.Load <GameObject>("AssetTest/Cube");
        var load1 = GameObject.Instantiate(go);

        go = BResources.Load <GameObject>("Test/Cube");
        var load2 = GameObject.Instantiate(go);

        go = BResources.Load <GameObject>("AssetTest/Particle");
        var load3 = GameObject.Instantiate(go);

        go = BResources.Load <GameObject>("Char/001");
        var loadModel = GameObject.Instantiate(go);

        golist.Add(load1);
        golist.Add(load2);
        golist.Add(load3);
        golist.Add(loadModel);
        //2.异步加载单个
        var id = BResources.AsyncLoad <GameObject>("Test/Cube", (o) =>
        {
            var load4 = GameObject.Instantiate(o);
            golist.Add(load4);
        });

        //3.异步加载多个
        var list = new List <string>()
        {
            "AssetTest/Cube", "Test/Cube"
        };

        BResources.AsyncLoad(list, (i, i2) =>
        {
            //进度
            Debug.Log(string.Format("进度 {0} / {1}", i, i2));
        }, (map) =>
        {
            BDebug.Log("加载全部完成,资源列表:");
            foreach (var r in map)
            {
                BDebug.Log(string.Format("--> {0} : {1}", r.Key, r.Value.name));
                var _go = GameObject.Instantiate(r.Value);
                golist.Add(_go as  GameObject);
            }
        });


        IEnumeratorTool.WaitingForExec(5, () =>
        {
            foreach (var _go in golist)
            {
                GameObject.Destroy(_go);
            }
        });
    }
Beispiel #11
0
    public static void ChangeToGray(this Image img)
    {
        Material material = BResources.Load <Material>("Shader/UI_Gary") as Material;

        if (img != null && material != null)
        {
            img.material = material;
        }
    }
        static public void Load()
        {
            //同个目录
            var o = BResources.Load <GameObject>("AssetTest/Cube");

            o = BResources.Load <GameObject>("AssetTest/Particle");
            //不同的runtime目录
            o = BResources.Load <GameObject>("CubeSVN");
        }
Beispiel #13
0
    void Finish()
    {
        BResources.ReleaseToPool(this.gameObject);

        //Note:
        // This takes the gameObject instance, and NOT the prefab instance.
        // Without this call the object will never be available for re-use!
        // gameObject.SetActive(false) is automatically called
    }
Beispiel #14
0
    //Spawn pooled objects
    void FireBullet(Vector3 position, Quaternion rotation)
    {
        var bullet = BResources.LoadFormPool(bulletPath, position, rotation).GetComponent <Bullet>();

        //Notes:
        // bullet.gameObject.SetActive(true) is automatically called on spawn
        // When done with the instance, you MUST release it!
        // If the number of objects in use exceeds the pool size, new objects will be created
    }
Beispiel #15
0
        public void Init()
        {
            var o = BResources.Load <GameObject>(data.ResurcePath);

            this.Trans = GameObject.Instantiate(o).transform;
            this.Trans.SetParent(Client.SceneRoot, false);
            //
            this.AniPlayer   = this.Trans.GetComponent <AniPlayer>();
            this.SkillPlayer = this.Trans.GetComponent <SkillPlayer_TBS>();
        }
Beispiel #16
0
 void Start()
 {
     //加载接口初始化
     BResources.Init(BAssetLoadPathType);
     //预热
     BResources.WarmPool(bulletPath, 10);
     //测试删除
     this.StartCoroutine(TestDestory());
     //Notes
     // Make sure the prefab is inactive, or else it will run update before first use
 }
Beispiel #17
0
        static public void CloseEffectLooped(int effid)
        {
            Transform t = null;

            effectMap.TryGetValue(effid, out t);
            if (t != null)
            {
                BResources.Destroy(t);
                effectMap.Remove(effid);
            }
        }
Beispiel #18
0
        /// <summary>
        /// 获取下载资源数据
        /// </summary>
        /// <param name="serverUrl"></param>
        /// <param name="localSaveAssetsPath"></param>
        /// <param name="platform"></param>
        /// <param name="serverVersionInfo"></param>
        /// <param name="localVersionInfo"></param>
        /// <returns>err, suc, 服务器数据, 本地数据,服务器数据内容 </returns>
        public (string, string, List <AssetItem>, List <AssetItem>, string) GetDownloadAssetsData(string serverUrl, RuntimePlatform platform, AssetsVersionInfo serverVersionInfo, AssetsVersionInfo localVersionInfo)
        {
            //返回数据
            string err = null;
            string suc = null;
            var    serverAssetsInfoList = new List <AssetItem>();
            var    localAssetsInfoList  = new List <AssetItem>();
            var    serverAssetsContent  = "";

            //1.判断版本号
            if (localVersionInfo.Version == serverVersionInfo.Version)
            {
                suc = "【版本控制】全量版本一致,无需下载!";
                BDebug.Log(suc);
                return(err, suc, null, null, null);
            }

            //2.获取Assets.info
            BDebug.Log($"【版本控制】全量下载模式! server:{serverVersionInfo.Version} local:{localVersionInfo.Version} ", "red");
            {
                //服务器路径
                var serverAssetInfosUrl = BResources.GetAssetsInfoPath(serverUrl, platform);
                //下载服务器Assets.info
                (err, serverAssetsInfoList, serverAssetsContent) = LoadServerAssetInfo(serverAssetInfosUrl);
            }
            //加载本地SubPackage配置
            localAssetsInfoList = LoadLocalSubPacakgeAssetInfo(platform, localVersionInfo);

            //加载本地asset.info
            var localAssetsInfo = this.LoadLocalAssetInfo(platform);

            localAssetsInfoList.AddRange(localAssetsInfo);
            //去重
            localAssetsInfoList = localAssetsInfoList.Distinct().ToList();
            localAssetsInfoList.Sort((a, b) =>
            {
                if (a.Id < b.Id)
                {
                    return(-1);
                }
                else if (a.Id == b.Id)
                {
                    return(0);
                }
                else
                {
                    return(1);
                }
            });
            //返回
            return(err, suc, serverAssetsInfoList, localAssetsInfoList, serverAssetsContent);
        }
        /// <summary>
        /// 初始化框架编辑器
        /// </summary>
        static public void InitFrameEditor()
        {
            //BD生命周期启动
            BDApplication.Init();
            BDFrameEditorConfigHelper.Init();
            //编辑器下加载初始化
            BResources.Load(AssetLoadPath.Editor);
            //初始化DLL
            var gAssembly = Assembly.LoadFile(BDApplication.Library + "/ScriptAssemblies/Assembly-CSharp.dll");
            var eAssemlby = Assembly.LoadFile(BDApplication.Library + "/ScriptAssemblies/Assembly-CSharp-Editor.dll");

            RegisterMainProjectAssembly(gAssembly, eAssemlby);
        }
        public void Do(IBattle battle, IHeroFSM selfFSM, IHeroFSM targetFSM)
        {
            var o = BResources.Load <GameObject>(this.se.StrParam0);

            effect = GameObject.Instantiate(o).transform;
            //在敌方阵营的特效 需要旋转


            //父节点
            Transform parent = null;

            if (se.DoubleParams0 == 1) //单体
            {
                if (targetFSM.Camp == 2)
                {
                    effect.eulerAngles = new Vector3(0, 180, 0);
                }
                parent = battle.World.GetPlayerRootTransform(targetFSM.ID);
            }
            else if (se.DoubleParams0 == 2)
            {
                parent = battle.World.GetPlayerRootTransform(targetFSM.Camp);
            }
            else if (se.DoubleParams0 == 3) //连接
            {
                parent = battle.World.GetPlayerRootTransform(selfFSM.Camp);
                var mypos  = battle.World.GetPlayerPos(selfFSM.ID);
                var tarpos = battle.World.GetPlayerPos(targetFSM.ID);

                //TODO 求两个向量夹角
                var v1  = new Vector2(mypos.x, mypos.z);
                var v2  = new Vector2(tarpos.x, tarpos.z);
                var dir = (v2 - v1).normalized;

                effect.LookAt(dir);
//              float angle = Vector3.Angle(mypos, tarpos);
//                effect.eulerAngles += new Vector3(0,angle,0);
            }

            effect.SetParent(parent, false);


            if (se.DoubleParams1 > 0)
            {
                IEnumeratorTool.WaitingForExec((float)se.DoubleParams1, () =>
                {
                    BResources.Destroy(effect);
                });
            }
        }
Beispiel #21
0
 static public void Clear()
 {
     //卸载复制体
     foreach (var v in gameObjPoolsMap.Values)
     {
         v.Clear();
     }
     gameObjPoolsMap = new Dictionary <string, GameObjectRecord>();
     //卸载源数据
     foreach (var m in gameObjPoolsMap)
     {
         BResources.UnloadAsset(m.Key);
     }
 }
Beispiel #22
0
        static public int PlayEffectLooped(string name, Vector3 pos, int dir = -1, Transform follow = null)
        {
            effectCount++;
            var o = GameObject.Instantiate(BResources.Load <GameObject>(name));

            effectMap[effectCount] = o.transform;
            if (follow != null)
            {
                o.transform.SetParent(follow, false);
                o.transform.localPosition = Vector3.zero;
            }

            return(effectCount);
        }
Beispiel #23
0
    /// <summary>
    /// 销毁窗口
    /// </summary>
    virtual public void Destroy()
    {
        //卸载
        BResources.Destroy(this.Transform);
        //
        foreach (var subwin in this.subWindowsDictionary.Values)
        {
            subwin.Destroy();
        }

        IsLoad = false;
        //卸载窗口
        BResources.UnloadAsset(resourcePath);
    }
Beispiel #24
0
        /// <summary>
        /// 加载本地的Asset.info
        /// </summary>
        private List <AssetItem> LoadLocalAssetInfo(RuntimePlatform platform)
        {
            var retList = new List <AssetItem>();
            //优先加载persistent的Assets.info
            var persistentAssetInfoPath = BResources.GetAssetsInfoPath(BApplication.persistentDataPath, platform);

            if (File.Exists(persistentAssetInfoPath))
            {
                var content = File.ReadAllText(persistentAssetInfoPath);
                retList = CsvSerializer.DeserializeFromString <List <AssetItem> >(content);
            }
            //streaming 和其他的Assets.info
            else
            {
                //根据加载模式不同,寻找不同目录下的其他配置
                //打包时,本地会带一份ServerAssets.info以标记当前包携带的资源
                var loadArtRoot = BDLauncher.Inst.GameConfig.ArtRoot;
                switch (loadArtRoot)
                {
                case AssetLoadPathType.Persistent:
                case AssetLoadPathType.StreamingAsset:
                {
                    //TODO :BSA 读取,不需要Streaming前缀
                    var steamingAssetsInfoPath = IPath.Combine(BApplication.GetPlatformPath(platform), BResources.ASSETS_INFO_PATH);
                    //var steamingAssetsInfoPath = GetAssetsInfoPath(BDApplication.streamingAssetsPath, platform);
                    if (BetterStreamingAssets.FileExists(steamingAssetsInfoPath))
                    {
                        var content = BetterStreamingAssets.ReadAllText(steamingAssetsInfoPath);
                        retList = CsvSerializer.DeserializeFromString <List <AssetItem> >(content);
                    }
                }
                break;

                case AssetLoadPathType.DevOpsPublish:
                {
                    var path = GameConfig.GetLoadPath(loadArtRoot);
                    var devopsAssetInfoPath = BResources.GetAssetsInfoPath(path, platform);
                    if (File.Exists(devopsAssetInfoPath))
                    {
                        var content = File.ReadAllText(devopsAssetInfoPath);
                        retList = CsvSerializer.DeserializeFromString <List <AssetItem> >(content);
                    }
                }
                break;
                }
            }

            return(retList);
        }
Beispiel #25
0
        static StackObject *Load_5(ILIntepreter __intp, StackObject *__esp, IList <object> __mStack, CLRMethod __method, bool isNewObj)
        {
            ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
            StackObject *ptr_of_this_method;
            StackObject *__ret = ILIntepreter.Minus(__esp, 1);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
            System.String @name = (System.String) typeof(System.String).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
            __intp.Free(ptr_of_this_method);


            var result_of_this_method = BResources.Load <UnityEngine.Sprite>(@name);

            return(ILIntepreter.PushObject(__ret, __mStack, result_of_this_method));
        }
Beispiel #26
0
        static StackObject *Destroy_3(ILIntepreter __intp, StackObject *__esp, IList <object> __mStack, CLRMethod __method, bool isNewObj)
        {
            ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
            StackObject *ptr_of_this_method;
            StackObject *__ret = ILIntepreter.Minus(__esp, 1);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
            UnityEngine.Transform @trans = (UnityEngine.Transform) typeof(UnityEngine.Transform).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
            __intp.Free(ptr_of_this_method);


            BResources.Destroy(@trans);

            return(__ret);
        }
Beispiel #27
0
 /// <summary>
 /// 初始化
 /// 修改版本,让这个启动逻辑由使用者自行处理
 /// </summary>
 /// <param name="GameId">单游戏更新启动不需要id,多游戏更新需要id号</param>
 public void Launch(string GameId = "")
 {
     BDebug.Log("Persistent:" + Application.persistentDataPath);
     BDebug.Log("StreamingAsset:" + Application.streamingAssetsPath);
     //开始资源检测
     AssetHelper.AssetHelper.CheckAssetPackageVersion(Application.platform, () =>
     {
         //1.美术目录
         BResources.Load(GameConfig.ArtRoot, GameConfig.CustomArtRoot);
         //2.sql
         SqliteLoder.Load(GameConfig.SQLRoot);
         //3.脚本,这个启动会开启所有的逻辑
         ScriptLoder.Load(GameConfig.CodeRoot, GameConfig.CodeRunMode);
     });
 }
Beispiel #28
0
        public void Load()
        {
            //重置pos
            this.playersPos = new List <Vector3>();
            //加载场景
            var o = GameObject.Instantiate(BResources.Load <GameObject>(this.path));

            this.Transform = o.transform;
            this.Transform.SetParent(Client.SceneRoot, false);
            var playesPosTrans = this.Transform.Find("PlayerPos");

            foreach (Transform p in playesPosTrans)
            {
                this.playersPos.Add(p.position);
            }
        }
Beispiel #29
0
    private void btn_07()
    {
        var path = Application.persistentDataPath;

        //开始下载
        BResources.StartAssetsVersionControl(UpdateMode.Repair, "http://127.0.0.1", null, (idx, totalNum) =>
        {
            //进度通知
            Debug.LogFormat("资源更新进度:{0}/{1}", idx, totalNum);
        },
                                             (status, msg) =>
        {
            //错误通知
            Debug.LogError("结果:" + status + " - " + msg);
        });
    }
Beispiel #30
0
        /// <summary>
        /// 修复模式
        /// Persistent资源和Streaming资源全量进行对比:文件名和hash
        /// </summary>
        private Queue <AssetItem> Repair(List <AssetItem> serverAssetsInfo, RuntimePlatform platform)
        {
            var diffQueue = new Queue <AssetItem>();

            //平台
            //根据服务器配置,遍历本地所有文件判断存在且修复
            foreach (var serverAsset in serverAssetsInfo)
            {
                if (!BResources.IsExsitAssetWithCheckHash(platform, serverAsset.LocalPath, serverAsset.HashName))
                {
                    diffQueue.Enqueue(serverAsset);
                }
            }

            return(diffQueue);
        }