private static async ETVoid CreateTargetArrow(Vector3 InitPos, PlayerCube playerCube, VariableJoystickComponent AttackUI, ETTaskCompletionSource <TargetArrow> tcs) { try { //创建一个TargetArrow的3D物体 GameObject resObj = await ETModel.Game.Scene.GetComponent <ResourcesAsyncComponent>().LoadAssetAsync <GameObject>(Assets.LoadAssetAsync("Assets/Bundles/Prefab/TargetArrow.prefab", typeof(GameObject))); ReferenceCollector rc = resObj.GetComponent <ReferenceCollector>(); GameObject targetArrowObj = GameObject.Instantiate <GameObject>(rc.Get <GameObject>("TargetArrow")); targetArrowObj.transform.position = InitPos; //创建TargetArrow实体脚本 TargetArrow targetArrow = ComponentFactory.Create <TargetArrow, GameObject>(targetArrowObj, false); //添加控制组件 targetArrow.AddComponent <TargetArrowComponent, PlayerCube, VariableJoystickComponent>(playerCube, AttackUI); tcs.SetResult(targetArrow); } catch (Exception e) { Log.Error(e); tcs.SetResult(null); } }
public static ETTask <TargetArrow> Create(Vector3 InitPos, PlayerCube playerCube, UI AttackUI) { ETTaskCompletionSource <TargetArrow> tcs = new ETTaskCompletionSource <TargetArrow>(); CreateTargetArrow(InitPos, playerCube, AttackUI.GetComponent <VariableJoystickComponent>(), tcs).Coroutine(); return(tcs.Task); }
public void Start() { //查找引用 playerInfoUIComponent = playerInfoUI.GetComponent <UIPlayerInfoComponent>(); playerDieUIComponent = playerDieUI.GetComponent <UIPlayerDieComponent>(); playerCube = this.GetParent <PlayerCube>(); }
public void Awake(PlayerCube playerCube, VariableJoystickComponent AttackUI) { this.cube_GameObject = playerCube.cube_GameObject; this.AttackUI = AttackUI; //查找相关引用 targetArrow_Transform = this.GetParent <TargetArrow>().targetArrow_GameObject.GetComponent <Transform>(); SetTargetArrowPosition(cube_GameObject.transform.position); cubePlayer_CameraBaseTransform = cube_GameObject.transform.Find("PlayerCameraBase"); }
public void Start() { playerCube = this.GetParent <PlayerCube>(); cube_Transform = playerCube.cube_GameObject.GetComponent <Transform>(); body_Transform = cube_Transform.Find("CubeBody"); cube_CharacterController = cube_Transform.GetComponent <CharacterController>(); hotfixSession = Game.Scene.GetComponent <SessionComponent>().Session; NetPackge = new C2G_PlayerRoleNetwork(); NetPackge.Account = playerAccount; playerCubeAttackComponent = this.GetParent <PlayerCube>().GetComponent <PlayerCubeAttackComponent>(); }
public void Awake(UI ui) { //查找相关引用 playerCube = this.GetParent <PlayerCube>(); cubePlayer_Transform = playerCube.cube_GameObject.GetComponent <Transform>(); cubePlayerBody_Transform = cubePlayer_Transform.Find("CubeBody"); cubePlayer_CameraBaseTransform = cubePlayer_Transform.Find("PlayerCameraBase"); groundCheck = cubePlayerBody_Transform.Find("GroundCheck"); cubePlayer_Controller = cubePlayer_Transform.GetComponent <CharacterController>(); cubePlayer_ControllerUI = ui.GetComponent <VariableJoystickComponent>(); }
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); } }