private static async ETVoid CreatePlayerCube(Vector3 InitPos, ETTaskCompletionSource <PlayerCube> tcs) { try { //创建一个cube角色的3D物体 GameObject resObj = await ETModel.Game.Scene.GetComponent <ResourcesAsyncComponent>().LoadAssetAsync <GameObject>(Assets.LoadAssetAsync("Assets/Bundles/Prefab/PlayerCube.prefab", typeof(GameObject))); ReferenceCollector rc = resObj.GetComponent <ReferenceCollector>(); GameObject playerCubeObj = GameObject.Instantiate <GameObject>(rc.Get <GameObject>("PlayerCube")); playerCubeObj.transform.position = InitPos; //创建cube角色实体脚本 PlayerCube playerCube = ComponentFactory.Create <PlayerCube, GameObject>(playerCubeObj, false); //创建控制UI UI ui = await UIJoystickFactory.Create(); Game.Scene.GetComponent <UIComponent>().Add(ui); //添加控制组件 PlayerCubeControllerComponent playerCubeControllerComponent = playerCube.AddComponent <PlayerCubeControllerComponent, UI>(ui); //创建准星控制UI UI AttackUI = await UIAttackDirstickFactory.Create(); Game.Scene.GetComponent <UIComponent>().Add(AttackUI); //创建准星3D物品 TargetArrow targetArrow = await TargetArrowFactory.Create(Vector3.zero, playerCube, AttackUI); //管理准星与cube playerCubeControllerComponent.targetArrow = targetArrow; //添加攻击脚本 playerCube.AddComponent <PlayerCubeAttackComponent>(); //添加生命值信息UI playerCube.AddComponent <PlayerCubeHealthComponent>(); //添加攻击伤害同步脚本 playerCube.AddComponent <HurtSyncComponent>(); tcs.SetResult(playerCube); } catch (Exception e) { Log.Error(e); tcs.SetResult(null); } }
public static async ETVoid EnterMapAsync() { try { Session hotfixSession = Game.Scene.GetComponent <SessionComponent>().Session; ResourcesAsyncComponent resourcesAsync = ETModel.Game.Scene.GetComponent <ResourcesAsyncComponent>(); PlayerInfoComponent playerInfo = Game.Scene.GetComponent <PlayerInfoComponent>(); if (hotfixSession == null) { Log.Error("获取hotfixSession失败"); } G2C_RequestEnterMap g2CRequestEnterMap = (G2C_RequestEnterMap)await hotfixSession.Call(new C2G_RequestEnterMap() { Account = playerInfo.account }); // 加载场景资源 SceneAssetRequest sceneAssetAsyncRequest = Assets.LoadSceneAsync("Arena.unity3d"); await resourcesAsync.LoadSceneAsync(sceneAssetAsyncRequest); // 切换到map场景 using (SceneChangeComponent sceneChangeComponent = ETModel.Game.Scene.AddComponent <SceneChangeComponent>()) { await sceneChangeComponent.ChangeSceneAsync(SceneType.Arena); } PlayerCube playerCube = await PlayerCubeFactory.Create(new Vector3(g2CRequestEnterMap.PositionX, g2CRequestEnterMap.PositionY, g2CRequestEnterMap.PositionZ)); //获取其它在地图里的玩家 hotfixSession.Send(new C2G_GetOtherPlayer() { Account = playerInfo.account }); //添加网络同步脚本 playerCube.AddComponent <PlayerCubeNetComponent, int>(playerInfo.account); nowPlayerCube = playerCube; Game.EventSystem.Run(EventIdType.EnterMapFinish); } catch (Exception e) { Log.Error(e); } }