private async ETVoid StartAsync() { try { SynchronizationContext.SetSynchronizationContext(OneThreadSynchronizationContext.Instance); DontDestroyOnLoad(gameObject); ClientConfigHelper.SetConfigHelper(); Game.EventSystem.Add(DLLType.Core, typeof(Core).Assembly); Game.EventSystem.Add(DLLType.Model, typeof(Init).Assembly); Game.Scene.AddComponent <GlobalConfigComponent>(); Game.Scene.AddComponent <ResourcesComponent>(); ETModel.Game.Scene.GetComponent <ResourcesComponent>().LoadBundle("config.unity3d"); Game.Scene.AddComponent <ConfigComponent>(); ETModel.Game.Scene.GetComponent <ResourcesComponent>().UnloadBundle("config.unity3d"); UnitConfig unitConfig = (UnitConfig)Game.Scene.GetComponent <ConfigComponent>().Get(typeof(UnitConfig), 1001); Log.Debug($"config {JsonHelper.ToJson(unitConfig)}"); //添加指定与网络组件 Game.Scene.AddComponent <OpcodeTypeComponent>(); Game.Scene.AddComponent <NetOuterComponent>(); ////添加UI组件 Game.Scene.AddComponent <UIComponent>(); Game.Scene.AddComponent <GamerComponent>(); //加上消息分发组件MessageDispatcherComponent Game.Scene.AddComponent <MessageDispatcherComponent>(); //执行斗地主初始事件,也就是创建LandLogin界面 Game.EventSystem.Run(UIEventType.LandInitSceneStart); //测试发送给服务端一条文本消息 Session session = Game.Scene.GetComponent <NetOuterComponent>().Create(GlobalConfigComponent.Instance.GlobalProto.Address); G2C_TestMessage g2CTestMessage = (G2C_TestMessage)await session.Call(new C2G_TestMessage() { Info = "==>>服务端的朋友,你好!收到请回答" }); } catch (Exception e) { Log.Error(e); } }
private async ETVoid StartAsync() { try { //上下文同步 SynchronizationContext.SetSynchronizationContext(OneThreadSynchronizationContext.Instance); //禁止销毁 在切换场景的时候 DontDestroyOnLoad(gameObject); //遍历Model的程序集 缓存各个加了特性标签的对象 Game.EventSystem.Add(DLLType.Model, typeof(Init).Assembly); Game.Scene.AddComponent <TimerComponent>(); //计时器 Game.Scene.AddComponent <GlobalConfigComponent>(); //全局配置 Game.Scene.AddComponent <NetOuterComponent>(); //外网组件 提供创建网络通道 在每个通道内部维护消息是收发处理 Game.Scene.AddComponent <ResourcesComponent>(); //资源组件 提供AB加载 Game.Scene.AddComponent <PlayerComponent>(); //玩家组件 提供玩家管理 Game.Scene.AddComponent <UnitComponent>(); //单位组件 它的实体加了HideInHierarchy 表示在层级视图中隐藏 Game.Scene.AddComponent <UIComponent>(); //UI组件 // 下载ab包 await BundleHelper.DownloadBundle(); //加载热更新代码 Game.Hotfix.LoadHotfixAssembly(); // 加载资源配置 Game.Scene.GetComponent <ResourcesComponent>().LoadBundle("config.unity3d"); Game.Scene.AddComponent <ConfigComponent>(); UnitConfig unit = (UnitConfig)Game.Scene.GetComponent <ConfigComponent>().Get(typeof(UnitConfig), 1); Game.Scene.GetComponent <ResourcesComponent>().UnloadBundle("config.unity3d"); //操作码 协议号 Game.Scene.AddComponent <OpcodeTypeComponent>(); //消息分发 Game.Scene.AddComponent <MessageDispatcherComponent>(); //初始化IL Game.Hotfix.GotoHotfix(); //测试热修复订阅事件 Game.EventSystem.Run(EventIdType.TestHotfixSubscribMonoEvent, "TestHotfixSubscribMonoEvent"); } catch (Exception e) { Log.Error(e); } }
private async ETVoid StartAsync() { try { SynchronizationContext.SetSynchronizationContext(OneThreadSynchronizationContext.Instance); DontDestroyOnLoad(gameObject); ClientConfigHelper.SetConfigHelper(); Game.EventSystem.Add(DLLType.Core, typeof(Core).Assembly); Game.EventSystem.Add(DLLType.Model, typeof(Init).Assembly); Game.Scene.AddComponent <GlobalConfigComponent>(); Game.Scene.AddComponent <ResourcesComponent>(); // 下载ab包 await BundleHelper.DownloadBundle(); ETModel.Game.Scene.GetComponent <ResourcesComponent>().LoadBundle("config.unity3d"); Game.Scene.AddComponent <ConfigComponent>(); ETModel.Game.Scene.GetComponent <ResourcesComponent>().UnloadBundle("config.unity3d"); UnitConfig unitConfig = (UnitConfig)Game.Scene.GetComponent <ConfigComponent>().Get(typeof(UnitConfig), 1001); Log.Debug($"config {JsonHelper.ToJson(unitConfig)}"); //添加指定与网络组件 Game.Scene.AddComponent <OpcodeTypeComponent>(); Game.Scene.AddComponent <NetOuterComponent>(); //添加UI组件 Game.Scene.AddComponent <UIComponent>(); Game.Scene.AddComponent <GamerComponent>(); Game.Scene.AddComponent <FUIPackageComponent>(); Game.Scene.AddComponent <FUIComponent>(); //添加消息分发组件MessageDispatcherComponent Game.Scene.AddComponent <MessageDispatcherComponent>(); /* * //Test05 * //练习1 * * Game.Scene.AddComponent<OpcodeTestComponent>(); * await BundleHelper.DownloadBundle(); * Game.EventSystem.Load(); * * //练习2 * Game.Scene.AddComponent<TimerComponent>(); * Game.Scene.AddComponent<FrameTestComponent>(); * * //练习3 * TestRoom room = ComponentFactory.Create<TestRoom>(); * room.AddComponent<TimeTestComponent>(); * room.GetComponent<TimeTestComponent>().Run(Typebehavior.Waiting, 5000); * * * * Game.EventSystem.Load(); * * //Test09 * //练习1 * Game.Scene.AddComponent<Test0901Component>(); * Game.EventSystem.Run(UIEventType.EndLandLogin); */ //执行斗地主初始事件,也就是创建LandLogin界面 Game.EventSystem.Run(UIEventType.FUILandInitSceneStart); //Game.EventSystem.Run(UIEventType.LandInitLobby); //测试发送给服务端一条文本消息 //Session session = Game.Scene.GetComponent<NetOuterComponent>().Create(GlobalConfigComponent.Instance.GlobalProto.Address); //G2C_TestMessage g2CTestMessage = (G2C_TestMessage) await session.Call(new C2G_TestMessage() { Info = "==>>服务端的朋友,你好!收到请回答" }); } catch (Exception e) { Log.Error(e); } }
public static Unit Create(long id, int typeId, UnitData unitData) { ResourcesComponent resourcesComponent = Game.Scene.GetComponent <ResourcesComponent>(); UnitConfig unitConfig = Game.Scene.GetComponent <ConfigComponent>().Get(typeof(UnitConfig), typeId) as UnitConfig; resourcesComponent.LoadBundle(unitConfig.ABPacketName.ToLower().StringToAB()); GameObject bundleGameObject = (GameObject)resourcesComponent.GetAsset(unitConfig.ABPacketName.ToLower().StringToAB(), unitConfig.ABPacketName); UnitComponent unitComponent = Game.Scene.GetComponent <UnitComponent>(); GameObject go = UnityEngine.Object.Instantiate(bundleGameObject); Unit unit = ComponentFactory.CreateWithId <Unit, GameObject>(id, go); unit.AddComponent <NumericComponent, int>(typeId); unit.AddComponent <AnimatorComponent>(); unit.AddComponent <UnitStateComponent>(); unit.AddComponent <UnitPathComponent>(); unit.AddComponent <AudioComponent>(); unit.AddComponent <BuffMgrComponent>(); var activeSkillCom = unit.AddComponent <ActiveSkillComponent>(); var passiveSkillCom = unit.AddComponent <PassiveSkillComponent>(); unit.AddComponent <SkillEffectComponent>(); if (!GlobalConfigComponent.Instance.networkPlayMode) { //添加碰撞体 AddCollider(unit, unitData, true); } unit.AddComponent <CharacterStateComponent>(); unit.AddComponent <CharacterMoveComponent>(); if (!Game.Scene.GetComponent <GlobalConfigComponent>().networkPlayMode) { unit.AddComponent <CalNumericComponent>(); } if (unitConfig.Skills != null && unitConfig.Skills.Length > 0) { SkillConfigComponent skillConfigComponent = Game.Scene.GetComponent <SkillConfigComponent>(); foreach (var v in unitConfig.Skills) { if (string.IsNullOrEmpty(v)) { continue; } var activeSkill = skillConfigComponent.GetActiveSkill(v); if (activeSkill != null) { Log.Debug(string.Format("{0} 添加主动技能 {1} ({2})成功!", typeId, v, activeSkill.skillName)); activeSkillCom.AddSkill(v); continue; } var passiveSkill = skillConfigComponent.GetPassiveSkill(v); if (passiveSkill != null) { Log.Debug(string.Format("{0} 添加被动技能 {1} ({2})成功!", typeId, v, passiveSkill.skillName)); passiveSkillCom.AddSkill(v); continue; } Log.Error(v + " 这样的技能不存在!"); } } //unit.AddComponent<TurnComponent>(); unitComponent.Add(unit); return(unit); }