private void net_onAskEnterWorldResponse(NetworkMessage netMsg) { S2GC_EnterWorldResponse Message = netMsg.ReadMessage <S2GC_EnterWorldResponse>(); if (Message.errorCode == -1) { e.getScene().scene_LoadLevel("World_Client"); } else { Client.Disconnect(); e.getUI().ui_login_Disconnected("Something went wrong..."); } }
public void World_Tick() { if (e.State == GAME_STATE.STATE_WORLD && e.getScene().State == SCENE_STATE.STATE_READY && e.getNetwork().State == NETWORK_STATE.STATE_CONNECTED) { if (Player_Self != null && Player_Self.Ready) { e.getNetwork().net_sendPlayerStateUpdate(); } /*if (PlayerList.Count > 0) * { * foreach (PlayerData playerData in PlayerList) * { * if (playerData.Object != null) * { * if (playerData.LerpPos != null && playerData.LerpPos != Vector3.zero) * { * playerData.Object.transform.position = Vector3.Lerp(playerData.Object.transform.position, playerData.LerpPos, Time.fixedDeltaTime * 2.5f); * } * if (playerData.LerpRot != null) * { * playerData.Object.transform.rotation = Quaternion.Lerp(playerData.Object.transform.rotation, playerData.LerpRot, Time.fixedDeltaTime * 2.5f); * } * } * } * } * if (NPCList.Count > 0) * { * foreach (NPCData npcData in NPCList) * { * npcData.getNPCInfo().client_behaviorUpdate(); * } * }*/ } }
public void Input_Tick() { if (e.State == GAME_STATE.STATE_WORLD && e.getScene().State == SCENE_STATE.STATE_READY) { /*if (e.getUI().State == UI_STATE.STATE_FREE || e.getUI().State == UI_STATE.STATE_HIDDEN) * { * if (Input.GetKeyDown(KeyCode.Return) || Input.GetKeyDown(KeyCode.KeypadEnter)) * { * e.getUI().ui_chat_GiveFocus(); * } * if (e.getNetwork().State == NETWORK_STATE.STATE_CONNECTED) * { * if (Input.GetKeyDown(KeyCode.F)) * { * e.getWorld().world_PlayerInteract(); * } * } * } * else * { * if (Input.GetKeyDown(KeyCode.Escape)) * { * e.getUI().ui_chat_BreakFocus(); * } * * }*/ } }
void LateUpdate() { if (!Ready || e == null) { return; } if (e.State == GAME_STATE.STATE_WORLD && e.getUI().KState == UI_KEYBOARD_STATE.STATE_FREE && e.getScene().State == SCENE_STATE.STATE_READY) { _MovementInput.x = Input.GetAxis("Horizontal"); _MovementInput.z = Input.GetAxis("Vertical"); _Animator.SetFloat("InputFB", _MovementInput.z); _Animator.SetFloat("InputLR", _MovementInput.x); if (Input.GetButtonDown("Jump")) { if (_isGrounded && !_isJumping) { _JumpTimer = _JumpAirTime; _isJumping = true; /* * if (_rigidbody.velocity.magnitude < 1) * animator.CrossFadeInFixedTime("Jump", 0.1f); * else * animator.CrossFadeInFixedTime("JumpMove", 0.2f); */ } } if (Input.GetMouseButtonDown(1)) { _isStrafing = true; _Animator.SetBool("Strafe", true); } else if (Input.GetMouseButtonUp(1)) { _isStrafing = false; _Animator.SetBool("Strafe", false); } if (Input.GetKeyDown(KeyCode.LeftShift)) { _isSprinting = true; _Animator.SetBool("Sprint", true); } else if (Input.GetKeyUp(KeyCode.LeftShift)) { _isSprinting = false; _Animator.SetBool("Sprint", false); } } }
void Update() { if (!Ready || e == null) { return; } if (e.State == GAME_STATE.STATE_WORLD && e.getScene().State == SCENE_STATE.STATE_READY) { if (TargetMovement != null && TargetMovement != Vector3.zero) { transform.position = Vector3.Lerp(transform.position, TargetMovement, Time.fixedDeltaTime * 2.5f); } if (TargetRotation != null) { transform.rotation = Quaternion.Lerp(transform.rotation, TargetRotation, Time.fixedDeltaTime * 2.5f); } if (TargetMovement != Vector3.zero) { Vector3 WorldMovement = transform.position - TargetMovement; float dX = Mathf.Round(Mathf.Clamp(Vector3.Dot(transform.right, WorldMovement), -1.0f, 1.0f) * 10f) / 10f; float dY = Mathf.Round(Mathf.Clamp(Vector3.Dot(transform.forward, WorldMovement), -1.0f, 1.0f) * 10f) / 10f; MovementVector = new Vector2(-dX, -dY); if (State == OTHER_PLAYER_STATE.STATE_RUNNING) { //_Animator.SetBool("Idle", false); _Animator.SetBool("Sprint", true); } else if (State == OTHER_PLAYER_STATE.STATE_WALKING) { //_Animator.SetBool("Idle", false); _Animator.SetBool("Sprint", false); } else if (State == OTHER_PLAYER_STATE.STATE_IDLE) { //_Animator.SetBool("Idle", true); _Animator.SetBool("Sprint", false); _Animator.SetFloat("InputLR", 0); _Animator.SetFloat("InputFB", 0); } if (State != OTHER_PLAYER_STATE.STATE_IDLE) { if (!_isStrafing) { _Animator.SetFloat("InputLR", 0f); //_Animator.SetFloat("Rotating", MovementVector.x); _Animator.SetFloat("InputFB", MovementVector.y); _Animator.SetBool("Strafing", false); } else { _Animator.SetFloat("InputLR", MovementVector.x); _Animator.SetFloat("InputFB", MovementVector.y); _Animator.SetBool("Strafing", true); } } } StatePrevious = State; } }
// Update is called once per frame public void UI_Tick() { if (e.State == GAME_STATE.STATE_LOBBY && e.getScene().State == SCENE_STATE.STATE_READY) { // Maybe stuff like rotating the 3d character preview etc. } if (e.State == GAME_STATE.STATE_WORLD && e.getScene().State == SCENE_STATE.STATE_READY) { // Keyboard input, movement blocking etc if (KState == UI_KEYBOARD_STATE.STATE_FREE) { if (chat_Input.isFocused) { KState = UI_KEYBOARD_STATE.STATE_TYPING; } else { if (Input.GetKeyUp(KeyCode.Escape)) { ui_world_DeselectTarget(); } else if (Input.GetKeyUp(KeyCode.Return) || Input.GetKeyUp(KeyCode.KeypadEnter)) { ui_chat_GiveFocus(); KState = UI_KEYBOARD_STATE.STATE_TYPING; } } } else if (KState == UI_KEYBOARD_STATE.STATE_TYPING) { if (!chat_Input.isFocused) { KState = UI_KEYBOARD_STATE.STATE_FREE; } else { if (Input.GetKeyUp(KeyCode.Return) || Input.GetKeyUp(KeyCode.KeypadEnter)) { e.getNetwork().net_sendChatMessage(); } } } //Chat input has focus, don't cast spells etc. Escape key breaks focus. //ui_ingame_updatePlayerFrame(); /*if (Input.GetKeyDown(KeyCode.Escape)) * { * ui_world_DeselectTarget(); * } * if (wasChatFocused && Input.GetKeyDown(KeyCode.Return)) * { * e.getNetwork().net_sendChatMessage(); * } * wasChatFocused = chat_Input.isFocused; * if (chat_Input.isFocused) * { * State = UI_STATE.STATE_TYPING; * } * else if (Input.GetKeyDown(KeyCode.Return) || Input.GetKeyDown(KeyCode.KeypadEnter)) * { * ui_chat_GiveFocus(); * } * else if (Input.GetMouseButton(1) || Input.GetMouseButton(0)) * { * if (!EventSystem.current.IsPointerOverGameObject()) * { * if (Mathf.Abs(Input.GetAxis("Mouse X")) >= 0.01f || Mathf.Abs(Input.GetAxis("Mouse Y")) >= 0.01f) * { * if (!shouldHideCursor) * { * //Cursor.visible = false; * GetCursorPos(out lastCursorPosition); * Cursor.visible = false; * Cursor.lockState = CursorLockMode.Confined; * shouldHideCursor = true; * State = UI_STATE.STATE_HIDDEN; * } * * } * } * * } * else if (Input.GetMouseButtonUp(0) || Input.GetMouseButtonUp(1)) * { * if (shouldHideCursor) * { * Cursor.lockState = CursorLockMode.None; * Cursor.visible = true; * shouldHideCursor = false; * State = UI_STATE.STATE_FREE; * SetCursorPos(lastCursorPosition.x, lastCursorPosition.y); * } * } * else * { * State = UI_STATE.STATE_FREE; * } * } * else * { * State = UI_STATE.STATE_FREE;*/ } }
// Update is called once per frame void Update() { if (e == null) { return; } if (e.State == GAME_STATE.STATE_WORLD && e.getScene().State == SCENE_STATE.STATE_READY) { if (TargetMovement != null && TargetMovement != Vector3.zero) { transform.position = Vector3.Lerp(transform.position, TargetMovement, Time.fixedDeltaTime * 2.5f); } if (TargetRotation != null) { transform.rotation = Quaternion.Lerp(transform.rotation, TargetRotation, Time.fixedDeltaTime * 2.5f); } if (TargetMovement != Vector3.zero) { Vector3 WorldMovement = transform.position - TargetMovement; float dX = Mathf.Round(Mathf.Clamp(Vector3.Dot(transform.right, WorldMovement), -1.0f, 1.0f) * 10f) / 10f; float dY = Mathf.Round(Mathf.Clamp(Vector3.Dot(transform.forward, WorldMovement), -1.0f, 1.0f) * 10f) / 10f; MovementVector = new Vector2(-dX, -dY); if (State == OTHER_PLAYER_STATE.STATE_RUNNING) { _Animator.SetBool("Idle", false); _Animator.SetBool("Sprint", true); } else if (State == OTHER_PLAYER_STATE.STATE_WALKING) { _Animator.SetBool("Idle", false); _Animator.SetBool("Sprint", false); } else if (State == OTHER_PLAYER_STATE.STATE_IDLE) { _Animator.SetBool("Idle", true); _Animator.SetBool("Sprint", false); _Animator.SetFloat("Horizontal", 0); _Animator.SetFloat("Vertical", 0); } if (State != OTHER_PLAYER_STATE.STATE_IDLE) { if (!isStrafing) { _Animator.SetFloat("Horizontal", 0f); _Animator.SetFloat("Rotating", MovementVector.x); _Animator.SetFloat("Vertical", MovementVector.y); _Animator.SetBool("Strafing", false); } else { _Animator.SetFloat("Horizontal", MovementVector.x); _Animator.SetFloat("Vertical", MovementVector.y); _Animator.SetBool("Strafing", true); } } } StatePrevious = State; /* * CheckGroundDistance(); * if (isStrafing) * { * if (Input.GetAxis("Mouse X") != 0.0f) * { * var newRotation = new Vector3(transform.eulerAngles.x, _PlayerCamera.transform.eulerAngles.y, transform.eulerAngles.z); * transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.Euler(newRotation), 1.0f); * } * _Animator.SetFloat("Rotating", Input.GetAxis("Mouse X")); * _Animator.SetBool("Strafing", true); * } * else * { * _Animator.SetBool("Strafing", false); * if (Input.GetAxis("Horizontal") != 0f) * { * transform.Rotate(0f, Input.GetAxis("Horizontal") * rotationSpeed * Time.deltaTime, 0); * _Animator.SetFloat("Rotating", Movement.x); * Movement.x = 0f; * } * * } * * if (!isGrounded || StatePrevious == PLAYER_STATE.STATE_JUMPING) * { * if (StatePrevious != PLAYER_STATE.STATE_JUMPING) * { * if(groundDistance >= 0.95f) * _Animator.SetBool("Falling", true); * JumpVector = transform.TransformDirection(Movement); * fallingSpeed = (State == PLAYER_STATE.STATE_WALKING) ? walkSpeed : runSpeed; * } * State = PLAYER_STATE.STATE_FALLING; * JumpVector = JumpVector * fallingSpeed * Time.deltaTime; * VerticalMovement -= 0.6f * Time.deltaTime; * if(VerticalMovement < 0 && groundDistance >= 0.95f) * _Animator.SetBool("Falling", true); * JumpVector.y = VerticalMovement; * _Controller.Move(JumpVector); * } * else if (isGrounded) * { * _Animator.SetBool("Falling", false); * VerticalMovement = 0f; * if (Movement == Vector3.zero) * { * State = PLAYER_STATE.STATE_IDLE; * _Animator.SetBool("Idle", true); * _Animator.SetBool("Sprint", false); * } * else if (isSprinting) * { * State = PLAYER_STATE.STATE_RUNNING; * _Animator.SetBool("Idle", false); * _Animator.SetBool("Sprint", true); * } * else * { * State = PLAYER_STATE.STATE_WALKING; * _Animator.SetBool("Idle", false); * _Animator.SetBool("Sprint", false); * } * _Animator.SetFloat("Horizontal", Movement.x); * _Animator.SetFloat("Vertical", Movement.z); * MovementVector = transform.TransformDirection(Movement); * if (MovementVector.magnitude > 1) * MovementVector = Vector3.Normalize(MovementVector); * * if (isJumping) * { * fallingSpeed = (State == PLAYER_STATE.STATE_WALKING) ? walkSpeed : runSpeed; * VerticalMovement = 0.23f; * JumpVector = MovementVector; * } * MovementVector = MovementVector * ((State == PLAYER_STATE.STATE_WALKING) ? walkSpeed : runSpeed) * Time.deltaTime; * if (MovementVector != Vector3.zero) * _Controller.Move(MovementVector); * if (isJumping) * { * if(State == PLAYER_STATE.STATE_IDLE) * _Animator.CrossFadeInFixedTime("Idle_Jump", 0.1f); * if(State == PLAYER_STATE.STATE_WALKING) * _Animator.CrossFadeInFixedTime("Walk_Jump", 0.1f); * if(State == PLAYER_STATE.STATE_RUNNING) * _Animator.CrossFadeInFixedTime("Run_Jump", 0.1f); * State = PLAYER_STATE.STATE_JUMPING; * * } * * } */ } }