From 68f9404555f8d551475ec6231b21f80f7a4122ae Mon Sep 17 00:00:00 2001 From: lucas-khaled <58189410+lucas-khaled@users.noreply.github.com> Date: Mon, 13 Sep 2021 07:57:26 -0300 Subject: [PATCH] =?UTF-8?q?Consertando=20rota=C3=A7=C3=A3o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../.idea/workspace.xml | 28 +++---- Assets/Resources/Player.prefab | 81 ++++++++++++++----- .../Script/Controllers/CorridaController.cs | 50 +++++++----- Assets/Script/EstadosPlayer/Grounded.cs | 1 + Assets/Script/EstadosPlayer/Stopped.cs | 25 ++++++ Assets/Script/EstadosPlayer/Stopped.cs.meta | 3 + Assets/Script/Player/Player.cs | 14 +++- ProjectSettings/DynamicsManager.asset | 9 ++- ProjectSettings/ProjectSettings.asset | 1 + 9 files changed, 150 insertions(+), 62 deletions(-) create mode 100644 Assets/Script/EstadosPlayer/Stopped.cs create mode 100644 Assets/Script/EstadosPlayer/Stopped.cs.meta diff --git a/.idea/.idea.Extreme-Snowboarding/.idea/workspace.xml b/.idea/.idea.Extreme-Snowboarding/.idea/workspace.xml index 3597b922..c1f3cd2a 100644 --- a/.idea/.idea.Extreme-Snowboarding/.idea/workspace.xml +++ b/.idea/.idea.Extreme-Snowboarding/.idea/workspace.xml @@ -2,22 +2,15 @@ + + - - - - - - - - - - + + + - - - @@ -198,7 +191,10 @@ - + + + + diff --git a/Assets/Resources/Player.prefab b/Assets/Resources/Player.prefab index b7f923c1..ddf9732e 100644 --- a/Assets/Resources/Player.prefab +++ b/Assets/Resources/Player.prefab @@ -65,26 +65,9 @@ MonoBehaviour: OwnershipTransfer: 0 ObservedComponents: - {fileID: 5047158400277881475} - - {fileID: 8686251071526131219} viewIdField: 0 InstantiationId: 0 isRuntimeInstantiated: 0 ---- !u!114 &8686251071526131219 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1384769323432956389} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 627855c7f81362d41938ffe0b1475957, type: 3} - m_Name: - m_EditorClassIdentifier: - m_SynchronizePosition: 1 - m_SynchronizeRotation: 1 - m_SynchronizeScale: 0 - m_UseLocal: 1 --- !u!1 &5797606892110252708 GameObject: m_ObjectHideFlags: 0 @@ -100,7 +83,7 @@ GameObject: - component: {fileID: -2960936140915857356} - component: {fileID: 7695480993240459834} - component: {fileID: 5471711173143376703} - m_Layer: 0 + m_Layer: 3 m_Name: Player m_TagString: Player m_Icon: {fileID: 0} @@ -115,7 +98,7 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 5797606892110252708} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: -0.0050461665, y: 0.012710025, z: 0} + m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: - {fileID: 1764391739971603295} @@ -303,14 +286,74 @@ PrefabInstance: propertyPath: m_LocalEulerAnglesHint.z value: 0 objectReference: {fileID: 0} + - target: {fileID: -7865630966810642468, guid: 3aabecf32c53147838d0a63a9d07438a, type: 3} + propertyPath: m_LocalRotation.w + value: 1 + objectReference: {fileID: 0} + - target: {fileID: -7865630966810642468, guid: 3aabecf32c53147838d0a63a9d07438a, type: 3} + propertyPath: m_LocalRotation.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: -7865630966810642468, guid: 3aabecf32c53147838d0a63a9d07438a, type: 3} + propertyPath: m_LocalRotation.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: -7865630966810642468, guid: 3aabecf32c53147838d0a63a9d07438a, type: 3} + propertyPath: m_LocalRotation.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: -7865630966810642468, guid: 3aabecf32c53147838d0a63a9d07438a, type: 3} + propertyPath: m_LocalEulerAnglesHint.y + value: 0 + objectReference: {fileID: 0} - target: {fileID: 919132149155446097, guid: 3aabecf32c53147838d0a63a9d07438a, type: 3} propertyPath: m_Name value: RenatoTCC objectReference: {fileID: 0} + - target: {fileID: 5184177756290302002, guid: 3aabecf32c53147838d0a63a9d07438a, type: 3} + propertyPath: m_LocalRotation.w + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 5184177756290302002, guid: 3aabecf32c53147838d0a63a9d07438a, type: 3} + propertyPath: m_LocalRotation.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 5184177756290302002, guid: 3aabecf32c53147838d0a63a9d07438a, type: 3} + propertyPath: m_LocalRotation.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 5184177756290302002, guid: 3aabecf32c53147838d0a63a9d07438a, type: 3} + propertyPath: m_LocalRotation.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 5184177756290302002, guid: 3aabecf32c53147838d0a63a9d07438a, type: 3} + propertyPath: m_LocalEulerAnglesHint.y + value: 0 + objectReference: {fileID: 0} - target: {fileID: 5866666021909216657, guid: 3aabecf32c53147838d0a63a9d07438a, type: 3} propertyPath: m_Controller value: objectReference: {fileID: 9100000, guid: c6c2530e171949e409633f713e47b9a1, type: 2} + - target: {fileID: 7022108065205083589, guid: 3aabecf32c53147838d0a63a9d07438a, type: 3} + propertyPath: m_LocalRotation.w + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 7022108065205083589, guid: 3aabecf32c53147838d0a63a9d07438a, type: 3} + propertyPath: m_LocalRotation.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 7022108065205083589, guid: 3aabecf32c53147838d0a63a9d07438a, type: 3} + propertyPath: m_LocalRotation.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 7022108065205083589, guid: 3aabecf32c53147838d0a63a9d07438a, type: 3} + propertyPath: m_LocalRotation.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 7022108065205083589, guid: 3aabecf32c53147838d0a63a9d07438a, type: 3} + propertyPath: m_LocalEulerAnglesHint.y + value: 0 + objectReference: {fileID: 0} m_RemovedComponents: [] m_SourcePrefab: {fileID: 100100000, guid: 3aabecf32c53147838d0a63a9d07438a, type: 3} --- !u!1 &1384769323432956389 stripped diff --git a/Assets/Script/Controllers/CorridaController.cs b/Assets/Script/Controllers/CorridaController.cs index 17b9f274..2e204a2f 100644 --- a/Assets/Script/Controllers/CorridaController.cs +++ b/Assets/Script/Controllers/CorridaController.cs @@ -1,3 +1,4 @@ +using System.Collections; using System.Collections.Generic; using System.Linq; using ExitGames.Client.Photon; @@ -188,12 +189,7 @@ private void Start() } InvokeRepeating("CheckPlayerClassification",0,0.1f); } - - private void InstantiatePlayers() - { - InstancePlayer(transform.position, _playerData); - } - + public void InstancePlayer(Vector3 position, PlayerData playerData) { Player.Player player = Instantiate(playerPrefab, position, playerPrefab.transform.rotation); @@ -204,7 +200,7 @@ public void InstancePlayer(Vector3 position, PlayerData playerData) Debug.Log("Allocated"); object[] data = { - player.transform.position, player.transform.rotation, photonView.ViewID, PlayerData.Serialize(playerData) + player.transform.position, photonView.ViewID, PlayerData.Serialize(playerData) }; RaiseEventOptions raiseEventOptions = new RaiseEventOptions @@ -223,12 +219,12 @@ public void InstancePlayer(Vector3 position, PlayerData playerData) else { Debug.LogError("Failed to allocate a ViewId."); - Destroy(player); + return; } - player.SetMaterials(playerData.color1, playerData.color2, playerData.playerMeshes, instantiationSettings); - _playersInGame.Add(player); + player.SetMaterialsAndMeshes(playerData.color1, playerData.color2, playerData.playerMeshes, instantiationSettings); + StartCoroutine(AddAPlayer(player)); camera.SetInitialPlayer(player); player.name = "My player"; @@ -239,30 +235,44 @@ public void InstancePlayer(Vector3 position, PlayerData playerData) public void OnEvent(EventData photonEvent) { - Debug.Log("On event"); if (photonEvent.Code == CustomManualInstantiationEventCode) { - Debug.Log("Custom instantiation"); object[] data = (object[]) photonEvent.CustomData; - - Player.Player player = Instantiate(playerPrefab, (Vector3) data[0], (Quaternion) data[1]); + + Player.Player player = Instantiate(playerPrefab, (Vector3) data[0], playerPrefab.transform.rotation); PhotonView photonView = player.GetComponent(); - photonView.ViewID = (int) data[2]; - PlayerData playerData = (PlayerData) PlayerData.Deserialize((byte[]) data[3]); + photonView.ViewID = (int) data[1]; + PlayerData playerData = (PlayerData) PlayerData.Deserialize((byte[]) data[2]); - player.SetMaterials(playerData.color1, playerData.color2, playerData.playerMeshes, instantiationSettings); - _playersInGame.Add(player); + player.SetMaterialsAndMeshes(playerData.color1, playerData.color2, playerData.playerMeshes, instantiationSettings); + StartCoroutine(AddAPlayer(player)); if(PlayerGeneralEvents.onPlayerInstantiate != null) PlayerGeneralEvents.onPlayerInstantiate.Invoke(player); } } + private IEnumerator AddAPlayer(Player.Player player) + { + if(!PhotonNetwork.IsMasterClient) + player.transform.GetChild(0).LookAt(player.transform.position+Vector3.right); + + _playersInGame.Add(player); + + if (_playersInGame.Count >= PhotonNetwork.CurrentRoom.PlayerCount) + { + Time.timeScale = 1; + yield return new WaitForSeconds(3); + _alivePlayers = _playersInGame.Count; + foreach (var playerInGame in _playersInGame) + playerInGame.ChangeState(new Grounded()); + } + } + private void LoadPlayers() { _playerData = GameController.gameController.playerData[0]; - /*alivePlayers = playersDatas.Length;*/ - InstantiatePlayers(); + InstancePlayer(transform.position, _playerData); } private void CheckPlayerClassification() diff --git a/Assets/Script/EstadosPlayer/Grounded.cs b/Assets/Script/EstadosPlayer/Grounded.cs index 97f4d0bc..e804aaa6 100644 --- a/Assets/Script/EstadosPlayer/Grounded.cs +++ b/Assets/Script/EstadosPlayer/Grounded.cs @@ -154,6 +154,7 @@ void UnsubscribeOnInputEvents() if (playerInput == null) playerInput = player.playerInput; + playerInput.currentActionMap.FindAction("Jump").started -= Jump; playerInput.currentActionMap.Disable(); } diff --git a/Assets/Script/EstadosPlayer/Stopped.cs b/Assets/Script/EstadosPlayer/Stopped.cs new file mode 100644 index 00000000..318d81f9 --- /dev/null +++ b/Assets/Script/EstadosPlayer/Stopped.cs @@ -0,0 +1,25 @@ +using UnityEngine; + +namespace ExtremeSnowboarding.Script.EstadosPlayer +{ + public class Stopped : PlayerState + { + private Rigidbody _rb; + public override void StateStart(Player.Player player) + { + base.StateStart(player); + _rb = player.GetComponent(); + _rb.useGravity = true; + } + + public override void StateEnd() + { + + } + + public override void StateUpdate() + { + + } + } +} \ No newline at end of file diff --git a/Assets/Script/EstadosPlayer/Stopped.cs.meta b/Assets/Script/EstadosPlayer/Stopped.cs.meta new file mode 100644 index 00000000..56e3a9c1 --- /dev/null +++ b/Assets/Script/EstadosPlayer/Stopped.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 99e2542a69994bfdbe69a8869e654aea +timeCreated: 1631196006 \ No newline at end of file diff --git a/Assets/Script/Player/Player.cs b/Assets/Script/Player/Player.cs index c5394f2b..87d18348 100644 --- a/Assets/Script/Player/Player.cs +++ b/Assets/Script/Player/Player.cs @@ -65,7 +65,7 @@ private set public Vector3 groundedVelocity { get; set; } - PlayerState playerState = new Grounded(); + PlayerState playerState = new Stopped(); private Player[] playerSpectating = new Player[4]; private Vector3 startPoint; @@ -152,9 +152,15 @@ public PlayerFeedbacksGroup GetPlayerFeedbackList() { return playerFeedbacksList; } - - - public void SetMaterials(Color firstColor, Color secondColor, string[] playerMeshes, MultiplayerInstantiationSettings settings) + + /// + /// Set the player Material and Meshes + /// + /// The primary color + /// The secondary color + /// The choosed meshes names + /// The Instantiation settings + public void SetMaterialsAndMeshes(Color firstColor, Color secondColor, string[] playerMeshes, MultiplayerInstantiationSettings settings) { Debug.Log("Player meshes names: "+playerMeshes[0]+" - "+playerMeshes[1]+" - "+playerMeshes[2]); Material material = new Material(settings.playerShader); diff --git a/ProjectSettings/DynamicsManager.asset b/ProjectSettings/DynamicsManager.asset index cdc1f3ea..5af46516 100644 --- a/ProjectSettings/DynamicsManager.asset +++ b/ProjectSettings/DynamicsManager.asset @@ -3,10 +3,11 @@ --- !u!55 &1 PhysicsManager: m_ObjectHideFlags: 0 - serializedVersion: 11 + serializedVersion: 13 m_Gravity: {x: 0, y: -9.81, z: 0} m_DefaultMaterial: {fileID: 0} m_BounceThreshold: 2 + m_DefaultMaxDepenetrationVelocity: 10 m_SleepThreshold: 0.005 m_DefaultContactOffset: 0.01 m_DefaultSolverIterations: 6 @@ -17,11 +18,12 @@ PhysicsManager: m_ClothInterCollisionDistance: 0 m_ClothInterCollisionStiffness: 0 m_ContactsGeneration: 1 - m_LayerCollisionMatrix: ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff + m_LayerCollisionMatrix: 59f8ffff50f8ffff50f8ffff51f8ffff5ff8ffff40f8ffff7ff8ffff00f8ffff00f8ffff00f8ffff00f8ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff m_AutoSimulation: 1 m_AutoSyncTransforms: 0 m_ReuseCollisionCallbacks: 1 m_ClothInterCollisionSettingsToggle: 0 + m_ClothGravity: {x: 0, y: -9.81, z: 0} m_ContactPairsMode: 0 m_BroadphaseType: 0 m_WorldBounds: @@ -31,4 +33,5 @@ PhysicsManager: m_FrictionType: 0 m_EnableEnhancedDeterminism: 0 m_EnableUnifiedHeightmaps: 1 - m_DefaultMaxAngluarSpeed: 7 + m_SolverType: 0 + m_DefaultMaxAngularSpeed: 7 diff --git a/ProjectSettings/ProjectSettings.asset b/ProjectSettings/ProjectSettings.asset index 824ede7d..9b9120c8 100644 --- a/ProjectSettings/ProjectSettings.asset +++ b/ProjectSettings/ProjectSettings.asset @@ -142,6 +142,7 @@ PlayerSettings: - {fileID: 0} - {fileID: 0} - {fileID: 0} + - {fileID: 0} metroInputSource: 0 wsaTransparentSwapchain: 0 m_HolographicPauseOnTrackingLoss: 1