From cf5d47eca9ee87d3808b0a4054e2210213d13a10 Mon Sep 17 00:00:00 2001 From: juliuse98 Date: Mon, 29 Nov 2021 12:21:32 +0100 Subject: [PATCH] SearchForNext Overhaul --- Assets/Scenes/TestScene.unity | 4 +-- Assets/Scripts/Player/PlayerController.cs | 2 -- Assets/Scripts/Weapons/WeaponManager.cs | 38 ++++++++++++++++++++--- ProjectSettings/ProjectVersion.txt | 4 +-- 4 files changed, 37 insertions(+), 11 deletions(-) diff --git a/Assets/Scenes/TestScene.unity b/Assets/Scenes/TestScene.unity index d616526..2f85073 100644 --- a/Assets/Scenes/TestScene.unity +++ b/Assets/Scenes/TestScene.unity @@ -38,7 +38,7 @@ RenderSettings: m_ReflectionIntensity: 1 m_CustomReflection: {fileID: 0} m_Sun: {fileID: 705507994} - m_IndirectSpecularColor: {r: 0.44657898, g: 0.4964133, b: 0.5748178, a: 1} + m_IndirectSpecularColor: {r: 0.44657826, g: 0.49641263, b: 0.57481676, a: 1} m_UseRadianceAmbientProbe: 0 --- !u!157 &3 LightmapSettings: @@ -2375,7 +2375,7 @@ PrefabInstance: - target: {fileID: 5784756223373504909, guid: 5cd2e2b44dc49ae44b48fc76a1e09712, type: 3} propertyPath: playerPrefab value: - objectReference: {fileID: 6272346181302961293, guid: 2935eead9a075fd489d6a6dc273a5999, type: 3} + objectReference: {fileID: 6272346181302961293, guid: a14d876ac00bdf6498e30b3e58b68fdf, type: 3} m_RemovedComponents: [] m_SourcePrefab: {fileID: 100100000, guid: 5cd2e2b44dc49ae44b48fc76a1e09712, type: 3} --- !u!1001 &3454029965885532949 diff --git a/Assets/Scripts/Player/PlayerController.cs b/Assets/Scripts/Player/PlayerController.cs index f58c4c0..962b6b8 100644 --- a/Assets/Scripts/Player/PlayerController.cs +++ b/Assets/Scripts/Player/PlayerController.cs @@ -124,8 +124,6 @@ public class PlayerController : NetworkBehaviour if(isGrounded && velocity.y < -fallDamageSpeed) { - Debug.Log(velocity.y); - Debug.Log("Fall Damage"); CmdFallDamage((int)Mathf.Abs(velocity.y)); } diff --git a/Assets/Scripts/Weapons/WeaponManager.cs b/Assets/Scripts/Weapons/WeaponManager.cs index 8d98d24..160e13d 100644 --- a/Assets/Scripts/Weapons/WeaponManager.cs +++ b/Assets/Scripts/Weapons/WeaponManager.cs @@ -27,13 +27,15 @@ public class WeaponManager : NetworkBehaviour if (isLocalPlayer) { if (Input.GetAxis("Mouse ScrollWheel") > 0f) { // Scroll up lastWeaponIndex = currentWeaponIndex; + activeWeapons[currentWeaponIndex].SetActive(false); switchWeapon(-1); } else if (Input.GetAxis("Mouse ScrollWheel") < 0f) { // Scroll down lastWeaponIndex = currentWeaponIndex; + activeWeapons[currentWeaponIndex].SetActive(false); switchWeapon(1); } - + activeWeapons[currentWeaponIndex].SetActive(true); if (Input.GetButtonDown("Interact")) { // e PickupWeapon(); @@ -41,6 +43,7 @@ public class WeaponManager : NetworkBehaviour if (activeWeapons[currentWeaponIndex] != null) { dropWeapon(); // Throws weapon away switchWeapon(1); + activeWeapons[currentWeaponIndex].SetActive(true); } } } @@ -48,21 +51,46 @@ public class WeaponManager : NetworkBehaviour private bool switchWeapon(int direction) { + int nextActive = searchForNext(activeWeapons, lastWeaponIndex, direction); - if (nextActive != -1) { // -1 no next found + currentWeaponIndex = nextActive; - activeWeapons[currentWeaponIndex].SetActive(true); + procedualAnimationController.OnSwitchWeapon(activeWeapons[currentWeaponIndex]); shoot.setWeapon(activeWeapons[currentWeaponIndex]); Weapon weaponData = activeWeapons[currentWeaponIndex].GetComponent(); procedualAnimationController.GunRightHandREF = weaponData.GunRightREF; procedualAnimationController.GunLeftHandREF = weaponData.GunLeftREF; // play weapon switch animation - } return false; } - private int searchForNext(List l, int lastActive = 0, int direction = 1) { + + private int searchForNext(List l, int lastActive = 0, int direction = 1) + { + int current = lastActive + direction; + + for (int trys = 0; trys < l.Count; trys++) + { + //Check if you are at the start or end of the list and loop around accordingly + if (current < 0) current = l.Count - 1; + else if (current >= l.Count) current = 0; + + //Check if in the current position is a gun or not + if (l[current] != null) + { + return current; + } + //if there is no gun go to the next + current = current + direction; + } + //If no next gun can be found return the index of the gun that was already selected + return lastActive; + } + + + + private int searchForNextOld(List l, int lastActive = 0, int direction = 1) { int size = l.Count; bool condition = true; int counter = 0; diff --git a/ProjectSettings/ProjectVersion.txt b/ProjectSettings/ProjectVersion.txt index 03f4c05..d1f16a3 100644 --- a/ProjectSettings/ProjectVersion.txt +++ b/ProjectSettings/ProjectVersion.txt @@ -1,2 +1,2 @@ -m_EditorVersion: 2021.2.0f1 -m_EditorVersionWithRevision: 2021.2.0f1 (4bf1ec4b23c9) +m_EditorVersion: 2021.2.3f1 +m_EditorVersionWithRevision: 2021.2.3f1 (32358a8527b4)