From 07d3a82ac32963f51c66c2baa634bb2086b0a3b6 Mon Sep 17 00:00:00 2001 From: Anonymous Raccoon <32224410+AnonymusRaccoon@users.noreply.github.com> Date: Wed, 7 Mar 2018 17:00:30 +0100 Subject: [PATCH] Lobby created --- .../Prefabs/Network Prefabs/GamePlayer.prefab | 2 + .../Network Prefabs/LobbyPlayer.prefab | 101 +++++++++++++- Assets/Scenes/Lobby.unity | 4 +- Assets/Script/LobbyPlayer.cs | 9 +- Assets/Script/NetworkManager.cs | 98 +++++++++++-- Assets/Script/PlayerMovement.cs | 13 +- ProjectSettings/InputManager.asset | 132 +++++++++++++++++- 7 files changed, 335 insertions(+), 24 deletions(-) diff --git a/Assets/Prefabs/Network Prefabs/GamePlayer.prefab b/Assets/Prefabs/Network Prefabs/GamePlayer.prefab index e5838b4..9413e69 100644 --- a/Assets/Prefabs/Network Prefabs/GamePlayer.prefab +++ b/Assets/Prefabs/Network Prefabs/GamePlayer.prefab @@ -124,6 +124,8 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 5d21adc90a3a0c5498d394337d4f81fb, type: 3} m_Name: m_EditorClassIdentifier: + Horizontal: + JumpKey: 0 speed: 10 airSpeed: 7 jumpForce: 8 diff --git a/Assets/Prefabs/Network Prefabs/LobbyPlayer.prefab b/Assets/Prefabs/Network Prefabs/LobbyPlayer.prefab index 5c5e497..e0761b0 100644 --- a/Assets/Prefabs/Network Prefabs/LobbyPlayer.prefab +++ b/Assets/Prefabs/Network Prefabs/LobbyPlayer.prefab @@ -21,9 +21,14 @@ GameObject: - component: {fileID: 4285622672537878} - component: {fileID: 114478164937343286} - component: {fileID: 114828863404442468} + - component: {fileID: 114243081584280124} + - component: {fileID: 33342890433238342} + - component: {fileID: 23327928353891206} + - component: {fileID: 54431066813788928} + - component: {fileID: 65433760954385860} m_Layer: 0 m_Name: LobbyPlayer - m_TagString: Untagged + m_TagString: Player m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 @@ -35,12 +40,104 @@ Transform: m_PrefabInternal: {fileID: 100100000} m_GameObject: {fileID: 1251834283741038} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: -620.73285, y: -317.8522, z: 414.98773} + m_LocalPosition: {x: 93.2, y: 1.84, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 0} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!23 &23327928353891206 +MeshRenderer: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 1251834283741038} + m_Enabled: 1 + m_CastShadows: 1 + m_ReceiveShadows: 1 + m_DynamicOccludee: 1 + m_MotionVectors: 1 + m_LightProbeUsage: 1 + m_ReflectionProbeUsage: 1 + m_Materials: + - {fileID: 10303, guid: 0000000000000000f000000000000000, type: 0} + m_StaticBatchInfo: + firstSubMesh: 0 + subMeshCount: 0 + m_StaticBatchRoot: {fileID: 0} + m_ProbeAnchor: {fileID: 0} + m_LightProbeVolumeOverride: {fileID: 0} + m_ScaleInLightmap: 1 + m_PreserveUVs: 1 + m_IgnoreNormalsForChartDetection: 0 + m_ImportantGI: 0 + m_StitchLightmapSeams: 0 + m_SelectedEditorRenderState: 3 + m_MinimumChartSize: 4 + m_AutoUVMaxDistance: 0.5 + m_AutoUVMaxAngle: 89 + m_LightmapParameters: {fileID: 0} + m_SortingLayerID: 0 + m_SortingLayer: 0 + m_SortingOrder: 0 +--- !u!33 &33342890433238342 +MeshFilter: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 1251834283741038} + m_Mesh: {fileID: 10208, guid: 0000000000000000e000000000000000, type: 0} +--- !u!54 &54431066813788928 +Rigidbody: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 1251834283741038} + serializedVersion: 2 + m_Mass: 1 + m_Drag: 0 + m_AngularDrag: 0.05 + m_UseGravity: 1 + m_IsKinematic: 0 + m_Interpolate: 0 + m_Constraints: 112 + m_CollisionDetection: 0 +--- !u!65 &65433760954385860 +BoxCollider: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 1251834283741038} + m_Material: {fileID: 0} + m_IsTrigger: 0 + m_Enabled: 1 + serializedVersion: 2 + m_Size: {x: 1, y: 2, z: 1} + m_Center: {x: 0, y: 0, z: 0} +--- !u!114 &114243081584280124 +MonoBehaviour: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 1251834283741038} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 5d21adc90a3a0c5498d394337d4f81fb, type: 3} + m_Name: + m_EditorClassIdentifier: + Horizontal: Horizontal + JumpKey: 0 + speed: 10 + airSpeed: 7 + jumpForce: 8 + smallJump: 4 + gravity: -10 + wallJump: 4 + wallJumpPush: 10 + wallJumpSpeed: 0 + wallMask: + serializedVersion: 2 + m_Bits: 512 --- !u!114 &114478164937343286 MonoBehaviour: m_ObjectHideFlags: 1 diff --git a/Assets/Scenes/Lobby.unity b/Assets/Scenes/Lobby.unity index 0a8a461..59d8a89 100644 --- a/Assets/Scenes/Lobby.unity +++ b/Assets/Scenes/Lobby.unity @@ -188,7 +188,7 @@ Transform: m_PrefabInternal: {fileID: 0} m_GameObject: {fileID: 581671511} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 132, z: -705} + m_LocalPosition: {x: 0, y: 6.7, z: -15.6} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 0} @@ -398,7 +398,7 @@ Transform: m_GameObject: {fileID: 1058006445} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalPosition: {x: 0, y: 0, z: 0} - m_LocalScale: {x: 2022.1465, y: 66.638954, z: 66.638954} + m_LocalScale: {x: 200, y: 1, z: 1} m_Children: [] m_Father: {fileID: 0} m_RootOrder: 2 diff --git a/Assets/Script/LobbyPlayer.cs b/Assets/Script/LobbyPlayer.cs index 5c36053..73e6bf9 100644 --- a/Assets/Script/LobbyPlayer.cs +++ b/Assets/Script/LobbyPlayer.cs @@ -11,18 +11,19 @@ public class LobbyPlayer : NetworkLobbyPlayer int playerNumber = 0; - if (netManager.ControllerP1 != 0) + if (netManager.ControllerP1 != 0 && GameObject.Find("LobbyPlayer (1)") == null) playerNumber = 1; - if (netManager.ControllerP2 != 0) + if (netManager.ControllerP2 != 0 && GameObject.Find("LobbyPlayer (2)") == null) playerNumber = 2; - if (netManager.ControllerP3 != 0) + if (netManager.ControllerP3 != 0 && GameObject.Find("LobbyPlayer (3)") == null) playerNumber = 3; - if (netManager.ControllerP4 != 0) + if (netManager.ControllerP4 != 0 && GameObject.Find("LobbyPlayer (4)") == null) playerNumber = 4; if (playerNumber == 0) playerNumber = 1; gameObject.name = "LobbyPlayer (" + playerNumber + ")"; + netManager.SetupPlayerController(gameObject.GetComponent(), playerNumber); } } diff --git a/Assets/Script/NetworkManager.cs b/Assets/Script/NetworkManager.cs index 4b6a90f..919e31c 100644 --- a/Assets/Script/NetworkManager.cs +++ b/Assets/Script/NetworkManager.cs @@ -54,31 +54,33 @@ public class NetworkManager : NetworkLobbyManager CheckControllerToAdd(Controller); } //Check if user want to remove his player - if ((Input.GetKeyDown(KeyCode.JoystickButton1) && Input.GetKeyDown(KeyCode.JoystickButton4) && Input.GetKeyDown(KeyCode.JoystickButton5)) || Input.GetKeyDown(KeyCode.Escape)) + if ((Input.GetKey(KeyCode.JoystickButton1) && Input.GetKey(KeyCode.JoystickButton4) && Input.GetKey(KeyCode.JoystickButton5)) || Input.GetKey(KeyCode.Escape)) { int Controller = 0; - if (Input.GetKeyDown(KeyCode.Joystick1Button1) && Input.GetKeyDown(KeyCode.Joystick1Button4) && Input.GetKeyDown(KeyCode.Joystick1Button5)) + if (Input.GetKey(KeyCode.Joystick1Button1) && Input.GetKey(KeyCode.Joystick1Button4) && Input.GetKey(KeyCode.Joystick1Button5)) Controller = 1; - if (Input.GetKeyDown(KeyCode.Joystick2Button1) && Input.GetKeyDown(KeyCode.Joystick2Button4) && Input.GetKeyDown(KeyCode.Joystick2Button5)) + if (Input.GetKey(KeyCode.Joystick2Button1) && Input.GetKey(KeyCode.Joystick2Button4) && Input.GetKey(KeyCode.Joystick2Button5)) Controller = 2; - if (Input.GetKeyDown(KeyCode.Joystick3Button1) && Input.GetKeyDown(KeyCode.Joystick3Button4) && Input.GetKeyDown(KeyCode.Joystick3Button5)) + if (Input.GetKey(KeyCode.Joystick3Button1) && Input.GetKey(KeyCode.Joystick3Button4) && Input.GetKey(KeyCode.Joystick3Button5)) Controller = 3; - if (Input.GetKeyDown(KeyCode.Joystick4Button1) && Input.GetKeyDown(KeyCode.Joystick4Button4) && Input.GetKeyDown(KeyCode.Joystick4Button5)) + if (Input.GetKey(KeyCode.Joystick4Button1) && Input.GetKey(KeyCode.Joystick4Button4) && Input.GetKey(KeyCode.Joystick4Button5)) Controller = 4; - if (Input.GetKeyDown(KeyCode.Joystick5Button1) && Input.GetKeyDown(KeyCode.Joystick5Button4) && Input.GetKeyDown(KeyCode.Joystick5Button5)) + if (Input.GetKey(KeyCode.Joystick5Button1) && Input.GetKey(KeyCode.Joystick5Button4) && Input.GetKey(KeyCode.Joystick5Button5)) Controller = 5; - if (Input.GetKeyDown(KeyCode.Joystick6Button1) && Input.GetKeyDown(KeyCode.Joystick6Button4) && Input.GetKeyDown(KeyCode.Joystick6Button5)) + if (Input.GetKey(KeyCode.Joystick6Button1) && Input.GetKey(KeyCode.Joystick6Button4) && Input.GetKey(KeyCode.Joystick6Button5)) Controller = 6; - if (Input.GetKeyDown(KeyCode.Joystick7Button1) && Input.GetKeyDown(KeyCode.Joystick7Button4) && Input.GetKeyDown(KeyCode.Joystick7Button5)) + if (Input.GetKey(KeyCode.Joystick7Button1) && Input.GetKey(KeyCode.Joystick7Button4) && Input.GetKey(KeyCode.Joystick7Button5)) Controller = 7; - if (Input.GetKeyDown(KeyCode.Joystick8Button1) && Input.GetKeyDown(KeyCode.Joystick8Button4) && Input.GetKeyDown(KeyCode.Joystick8Button5)) + if (Input.GetKey(KeyCode.Joystick8Button1) && Input.GetKey(KeyCode.Joystick8Button4) && Input.GetKey(KeyCode.Joystick8Button5)) Controller = 8; if (Input.GetKeyDown(KeyCode.Escape)) Controller = 9; CheckControllerToRemove(Controller); } + //Check for ready calls + } private void CheckControllerToAdd(int Controller) @@ -116,13 +118,19 @@ public class NetworkManager : NetworkLobbyManager private void AddLocalPlayer(int player) { if (player == 1 && GameObject.Find("LobbyPlayer (1)") != null) + { + SetupPlayerController(GameObject.Find("LobbyPlayer (1)").GetComponent(), 1); return; + } TryToAddPlayer(); } private void CheckControllerToRemove(int Controller) { + if (Controller == 0) + return; + if(Controller == ControllerP1) { ControllerP1 = 0; @@ -151,6 +159,78 @@ public class NetworkManager : NetworkLobbyManager private void RemoveLocalPlayer(int player) { + LobbyPlayer lobbyPlayer = GameObject.Find("LobbyPlayer (" + player + ")").GetComponent(); + lobbyPlayer.RemovePlayer(); + } + public void SetupPlayerController(PlayerMovement pMovement, int player) + { + if(player == 1) + { + if (ControllerP1 == 0) + return; + + if(ControllerP1 == 9) + { + pMovement.Horizontal = "Horizontal_Keyboard"; + pMovement.JumpKey = KeyCode.Space; + } + else + { + pMovement.Horizontal = "Horizontal_J" + ControllerP1; + pMovement.JumpKey = (KeyCode)System.Enum.Parse(typeof(KeyCode), "Joystick" + ControllerP1 + "Button0"); + } + } + else if (player == 2) + { + if (ControllerP2 == 0) + return; + + if (ControllerP2 == 9) + { + pMovement.Horizontal = "Horizontal_Keyboard"; + pMovement.JumpKey = KeyCode.Space; + } + else + { + pMovement.Horizontal = "Horizontal_J" + ControllerP2; + pMovement.JumpKey = (KeyCode)System.Enum.Parse(typeof(KeyCode), "Joystick" + ControllerP2 + "Button0"); + } + } + else if (player == 3) + { + if (ControllerP3 == 0) + return; + + if (ControllerP3 == 9) + { + pMovement.Horizontal = "Horizontal_Keyboard"; + pMovement.JumpKey = KeyCode.Space; + } + else + { + pMovement.Horizontal = "Horizontal_J" + ControllerP3; + pMovement.JumpKey = (KeyCode)System.Enum.Parse(typeof(KeyCode), "Joystick" + ControllerP3 + "Button0"); + } + } + else if (player == 4) + { + if (ControllerP4 == 0) + return; + + if (ControllerP4 == 9) + { + pMovement.Horizontal = "Horizontal_Keyboard"; + pMovement.JumpKey = KeyCode.Space; + } + else + { + pMovement.Horizontal = "Horizontal_J" + ControllerP4; + pMovement.JumpKey = (KeyCode)System.Enum.Parse(typeof(KeyCode), "Joystick" + ControllerP4 + "Button0"); + } + } + + pMovement.gameObject.transform.position = new Vector3(0, 2, 0); + pMovement.gameObject.GetComponent().velocity = new Vector3(0, 10, 0); } } diff --git a/Assets/Script/PlayerMovement.cs b/Assets/Script/PlayerMovement.cs index 3c0612e..e71b4fe 100644 --- a/Assets/Script/PlayerMovement.cs +++ b/Assets/Script/PlayerMovement.cs @@ -3,8 +3,8 @@ [RequireComponent(typeof(Rigidbody))] public class PlayerMovement : MonoBehaviour { - [SerializeField] private const string Horizontal = "Horizontal"; - [SerializeField] private const string Jump = "Jump"; + public string Horizontal; + public KeyCode JumpKey = KeyCode.None; [Space] [SerializeField] private int speed = 10; @@ -121,6 +121,9 @@ public class PlayerMovement : MonoBehaviour private void FixedUpdate() { + if (JumpKey == KeyCode.None || Horizontal == null) + return; + bool isGrounded = IsGrounded(); bool isSliding = IsSliding(); bool airControl = AirControl(isGrounded); @@ -160,13 +163,13 @@ public class PlayerMovement : MonoBehaviour } //Make user jump - if (Input.GetButtonDown(Jump) && isGrounded) + if (Input.GetKeyDown(JumpKey) && isGrounded) { jumpDirection = Input.GetAxis(Horizontal); rb.velocity = new Vector3(rb.velocity.x, jumpForce + (movingPlateform != null ? movingPlateform.rb.velocity.y : 0) , rb.velocity.z); } //Make a small jump if user drop the button - if (Input.GetButtonUp(Jump) && !isGrounded && rb.velocity.y > smallJump && !wallJumped) + if (Input.GetKeyUp(JumpKey) && !isGrounded && rb.velocity.y > smallJump && !wallJumped) rb.velocity = new Vector3(rb.velocity.x, smallJump, rb.velocity.z); //Move with the plateform @@ -181,7 +184,7 @@ public class PlayerMovement : MonoBehaviour if (wallJumpTimer > 0) { //Wall Jump - if (Input.GetButtonDown(Jump) && !isGrounded) + if (Input.GetKeyDown(JumpKey) && !isGrounded) { wallJumped = true; jumpDirection = -wallDirection; diff --git a/ProjectSettings/InputManager.asset b/ProjectSettings/InputManager.asset index 172da6b..7201520 100644 --- a/ProjectSettings/InputManager.asset +++ b/ProjectSettings/InputManager.asset @@ -6,7 +6,7 @@ InputManager: serializedVersion: 2 m_Axes: - serializedVersion: 3 - m_Name: Horizontal + m_Name: Horizontal_Keyboard descriptiveName: descriptiveNegativeName: negativeButton: left @@ -20,7 +20,135 @@ InputManager: invert: 0 type: 0 axis: 0 - joyNum: 0 + joyNum: 16 + - serializedVersion: 3 + m_Name: Horizontal_J1 + descriptiveName: + descriptiveNegativeName: + negativeButton: left + positiveButton: right + altNegativeButton: a + altPositiveButton: d + gravity: 3 + dead: 0.001 + sensitivity: 3 + snap: 1 + invert: 0 + type: 2 + axis: 0 + joyNum: 1 + - serializedVersion: 3 + m_Name: Horizontal_J2 + descriptiveName: + descriptiveNegativeName: + negativeButton: left + positiveButton: right + altNegativeButton: a + altPositiveButton: d + gravity: 3 + dead: 0.001 + sensitivity: 3 + snap: 1 + invert: 0 + type: 2 + axis: 0 + joyNum: 2 + - serializedVersion: 3 + m_Name: Horizontal_J3 + descriptiveName: + descriptiveNegativeName: + negativeButton: left + positiveButton: right + altNegativeButton: a + altPositiveButton: d + gravity: 3 + dead: 0.001 + sensitivity: 3 + snap: 1 + invert: 0 + type: 2 + axis: 0 + joyNum: 3 + - serializedVersion: 3 + m_Name: Horizontal_J4 + descriptiveName: + descriptiveNegativeName: + negativeButton: left + positiveButton: right + altNegativeButton: a + altPositiveButton: d + gravity: 3 + dead: 0.001 + sensitivity: 3 + snap: 1 + invert: 0 + type: 2 + axis: 0 + joyNum: 4 + - serializedVersion: 3 + m_Name: Horizontal_J5 + descriptiveName: + descriptiveNegativeName: + negativeButton: left + positiveButton: right + altNegativeButton: a + altPositiveButton: d + gravity: 3 + dead: 0.001 + sensitivity: 3 + snap: 1 + invert: 0 + type: 2 + axis: 0 + joyNum: 5 + - serializedVersion: 3 + m_Name: Horizontal_J6 + descriptiveName: + descriptiveNegativeName: + negativeButton: left + positiveButton: right + altNegativeButton: a + altPositiveButton: d + gravity: 3 + dead: 0.001 + sensitivity: 3 + snap: 1 + invert: 0 + type: 2 + axis: 0 + joyNum: 5 + - serializedVersion: 3 + m_Name: Horizontal_J7 + descriptiveName: + descriptiveNegativeName: + negativeButton: left + positiveButton: right + altNegativeButton: a + altPositiveButton: d + gravity: 3 + dead: 0.001 + sensitivity: 3 + snap: 1 + invert: 0 + type: 2 + axis: 0 + joyNum: 7 + - serializedVersion: 3 + m_Name: Horizontal_J8 + descriptiveName: + descriptiveNegativeName: + negativeButton: left + positiveButton: right + altNegativeButton: a + altPositiveButton: d + gravity: 3 + dead: 0.001 + sensitivity: 3 + snap: 1 + invert: 0 + type: 2 + axis: 0 + joyNum: 8 - serializedVersion: 3 m_Name: Vertical descriptiveName: