From c28d9147d2a6966eb8eb6c43f3dffcfca9629e33 Mon Sep 17 00:00:00 2001 From: Noah4ever <66632359+Noah4ever@users.noreply.github.com> Date: Mon, 17 Jan 2022 13:51:03 +0100 Subject: [PATCH] Revert "idk" This reverts commit e5e44eeb55e822e50f2314bb4036206ea5edac1a. --- Assets/Scenes/TestScene.unity | 57 ------------ Assets/Scripts/Weapons/Shoot.cs | 3 +- Assets/Scripts/Weapons/WeaponManager.cs | 102 +++++++--------------- ProjectSettings/EditorBuildSettings.asset | 4 +- UserSettings/EditorUserSettings.asset | 4 +- 5 files changed, 38 insertions(+), 132 deletions(-) diff --git a/Assets/Scenes/TestScene.unity b/Assets/Scenes/TestScene.unity index a138115..d3b9d1f 100644 --- a/Assets/Scenes/TestScene.unity +++ b/Assets/Scenes/TestScene.unity @@ -1208,63 +1208,6 @@ MeshCollider: m_Convex: 0 m_CookingOptions: 30 m_Mesh: {fileID: -2477511411847689622, guid: 823e8b39d52b71b4eb5a91dbc8d6d59e, type: 3} ---- !u!1001 &229718357 -PrefabInstance: - m_ObjectHideFlags: 0 - serializedVersion: 2 - m_Modification: - m_TransformParent: {fileID: 0} - m_Modifications: - - target: {fileID: 8254144844365660484, guid: 2e0b09b5d2317e945be571bf04f89521, type: 3} - propertyPath: m_RootOrder - value: 12 - objectReference: {fileID: 0} - - target: {fileID: 8254144844365660484, guid: 2e0b09b5d2317e945be571bf04f89521, type: 3} - propertyPath: m_LocalPosition.x - value: 10.781815 - objectReference: {fileID: 0} - - target: {fileID: 8254144844365660484, guid: 2e0b09b5d2317e945be571bf04f89521, type: 3} - propertyPath: m_LocalPosition.y - value: -12.906637 - objectReference: {fileID: 0} - - target: {fileID: 8254144844365660484, guid: 2e0b09b5d2317e945be571bf04f89521, type: 3} - propertyPath: m_LocalPosition.z - value: 7.690632 - objectReference: {fileID: 0} - - target: {fileID: 8254144844365660484, guid: 2e0b09b5d2317e945be571bf04f89521, type: 3} - propertyPath: m_LocalRotation.w - value: 1 - objectReference: {fileID: 0} - - target: {fileID: 8254144844365660484, guid: 2e0b09b5d2317e945be571bf04f89521, type: 3} - propertyPath: m_LocalRotation.x - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 8254144844365660484, guid: 2e0b09b5d2317e945be571bf04f89521, type: 3} - propertyPath: m_LocalRotation.y - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 8254144844365660484, guid: 2e0b09b5d2317e945be571bf04f89521, type: 3} - propertyPath: m_LocalRotation.z - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 8254144844365660484, guid: 2e0b09b5d2317e945be571bf04f89521, type: 3} - propertyPath: m_LocalEulerAnglesHint.x - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 8254144844365660484, guid: 2e0b09b5d2317e945be571bf04f89521, type: 3} - propertyPath: m_LocalEulerAnglesHint.y - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 8254144844365660484, guid: 2e0b09b5d2317e945be571bf04f89521, type: 3} - propertyPath: m_LocalEulerAnglesHint.z - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 8254144844365660489, guid: 2e0b09b5d2317e945be571bf04f89521, type: 3} - propertyPath: m_Name - value: Network Manager - objectReference: {fileID: 0} - m_RemovedComponents: [] - m_SourcePrefab: {fileID: 100100000, guid: 2e0b09b5d2317e945be571bf04f89521, type: 3} --- !u!1 &243809592 stripped GameObject: m_CorrespondingSourceObject: {fileID: -7640558969779515294, guid: 823e8b39d52b71b4eb5a91dbc8d6d59e, type: 3} diff --git a/Assets/Scripts/Weapons/Shoot.cs b/Assets/Scripts/Weapons/Shoot.cs index 97d8647..0dea42d 100644 --- a/Assets/Scripts/Weapons/Shoot.cs +++ b/Assets/Scripts/Weapons/Shoot.cs @@ -62,8 +62,7 @@ public class Shoot : NetworkBehaviour // Throw Grenade throwGrenade(); } // If current weapon kind is kinfe - else { - Debug.Log("Throw Hands"); + else { // Throw hands (punch) } } diff --git a/Assets/Scripts/Weapons/WeaponManager.cs b/Assets/Scripts/Weapons/WeaponManager.cs index c966eac..5a9cf83 100644 --- a/Assets/Scripts/Weapons/WeaponManager.cs +++ b/Assets/Scripts/Weapons/WeaponManager.cs @@ -3,54 +3,44 @@ using System.Collections.Generic; using UnityEngine; using Mirror; -[System.Serializable] -public struct WeaponStruct -{ - public GameObject weapon; -} public class WeaponManager : NetworkBehaviour { public int currentWeaponIndex = 2; // Hand private int lastWeaponIndex = 0; - [SyncVar] - public SyncList activeWeapons = new SyncList(new WeaponStruct[4]); + public List activeWeapons = new List(); private ProcedualAnimationController procedualAnimationController; private Weapon weaponData; [SerializeField] Shoot shoot; [SerializeField] GameObject gunHolster; - [SerializeField] Camera cam; + [SerializeField] Camera cam; - private void Awake() { + private void Awake() + { procedualAnimationController = GetComponent(); currentWeaponIndex = 2; // Hand - GameObject hand = gunHolster.transform.Find("Hand").gameObject; - WeaponStruct addHand = new WeaponStruct(); - addHand.weapon = hand; - activeWeapons[currentWeaponIndex] = addHand; - weaponData = activeWeapons[currentWeaponIndex].weapon.GetComponent(); // Hand + weaponData = activeWeapons[currentWeaponIndex].GetComponent(); // Hand } - void Update() { + void Update() { if (isLocalPlayer) { - if (Input.GetAxis("Mouse ScrollWheel") > 0f) { // Scroll up lastWeaponIndex = currentWeaponIndex; - activeWeapons[currentWeaponIndex].weapon.SetActive(false); + activeWeapons[currentWeaponIndex].SetActive(false); switchWeapon(-1); } else if (Input.GetAxis("Mouse ScrollWheel") < 0f) { // Scroll down lastWeaponIndex = currentWeaponIndex; - activeWeapons[currentWeaponIndex].weapon.SetActive(false); + activeWeapons[currentWeaponIndex].SetActive(false); switchWeapon(1); } if (Input.GetButtonDown("Interact")) { // e - PickupWeapon(); + PickupWeapon(); }else if (Input.GetButtonDown("Drop")) { // q Droping weapon - if (activeWeapons[currentWeaponIndex].weapon != null) { - dropWeapon(activeWeapons[currentWeaponIndex].weapon.GetComponent().DropForce, currentWeaponIndex); // Throws weapon away + if (activeWeapons[currentWeaponIndex] != null) { + dropWeapon(activeWeapons[currentWeaponIndex].GetComponent().DropForce, currentWeaponIndex); // Throws weapon away switchWeapon(1); } } @@ -66,33 +56,21 @@ public class WeaponManager : NetworkBehaviour } }*/ } - + public bool switchWeapon(int direction) { // Get next active weapon index int nextActive = searchForNext(activeWeapons, lastWeaponIndex, direction); currentWeaponIndex = nextActive; - procedualAnimationController.OnSwitchWeapon(activeWeapons[currentWeaponIndex].weapon); - shoot.setWeapon(activeWeapons[currentWeaponIndex].weapon); - weaponData = activeWeapons[currentWeaponIndex].weapon.GetComponent(); + procedualAnimationController.OnSwitchWeapon(activeWeapons[currentWeaponIndex]); + shoot.setWeapon(activeWeapons[currentWeaponIndex]); + weaponData = activeWeapons[currentWeaponIndex].GetComponent(); procedualAnimationController.GunRightHandREF = weaponData.GunRightREF; procedualAnimationController.GunLeftHandREF = weaponData.GunLeftREF; // Play weapon switch animation switchAnimation(weaponData.WeaponKind.ToString()); - activeWeapons[currentWeaponIndex].weapon.SetActive(true); - CmdPrintInventory(); - return true; - } - - [Command] - private void CmdPrintInventory() - { - for (int i = 0; i < 4; i++) - { - if(activeWeapons[i].weapon) - Debug.Log((i + 1) + ". " + activeWeapons[i].weapon); - } - Debug.Log("-------------------"); + activeWeapons[currentWeaponIndex].SetActive(true); + return false; } private void switchAnimation(string weaponType) { switch (weaponType) { @@ -102,7 +80,7 @@ public class WeaponManager : NetworkBehaviour case "Grenade": ; procedualAnimationController.changePistole(true); break; } } - private int searchForNext(SyncList l, int lastActive = 0, int direction = 1) + private int searchForNext(List l, int lastActive = 0, int direction = 1) { int current = lastActive + direction; @@ -113,7 +91,7 @@ public class WeaponManager : NetworkBehaviour else if (current >= l.Count) current = 0; //Check if in the current position is a gun or not - if (l[current].weapon != null) + if (l[current] != null) { return current; } @@ -126,18 +104,18 @@ public class WeaponManager : NetworkBehaviour public GameObject getCurrentWeapon() { - return activeWeapons[currentWeaponIndex].weapon.gameObject; + return activeWeapons[currentWeaponIndex].gameObject; } private void PickupWeapon() { if (Physics.Raycast(cam.transform.position, cam.transform.forward, out RaycastHit hit)) { // If Object is a weapon and the weapon is not in the current active weapons - if (hit.transform.tag == "Weapon") - { + if (hit.transform.tag == "Weapon") + { // Disable all weapons - foreach (WeaponStruct obj in activeWeapons) { - if (obj.weapon != null) { obj.weapon.SetActive(false); } + foreach (GameObject obj in activeWeapons) { + if (obj != null) { obj.SetActive(false); } } // Parent weapon to gunHolster hit.transform.parent = gunHolster.transform; @@ -158,19 +136,17 @@ public class WeaponManager : NetworkBehaviour } private bool putWeaponInArray(int index, RaycastHit hit) { - if (activeWeapons[index].weapon != null) { + if (activeWeapons[index] != null) { // Throws weapon away - dropWeapon(activeWeapons[index].weapon.GetComponent().DropForce, index); + dropWeapon(activeWeapons[index].GetComponent().DropForce, index); } - WeaponStruct addWeapon = new WeaponStruct(); - addWeapon.weapon = hit.transform.gameObject; - activeWeapons[index] = addWeapon; - activeWeapons[index].weapon.SetActive(true); + activeWeapons[index] = hit.transform.gameObject; + activeWeapons[index].SetActive(true); // \/ Same as in switchWeapon() currentWeaponIndex = index; - procedualAnimationController.OnSwitchWeapon(activeWeapons[currentWeaponIndex].weapon); - shoot.setWeapon(activeWeapons[currentWeaponIndex].weapon); - Weapon weaponData = activeWeapons[currentWeaponIndex].weapon.GetComponent(); + procedualAnimationController.OnSwitchWeapon(activeWeapons[currentWeaponIndex]); + shoot.setWeapon(activeWeapons[currentWeaponIndex]); + Weapon weaponData = activeWeapons[currentWeaponIndex].GetComponent(); procedualAnimationController.GunRightHandREF = weaponData.GunRightREF; procedualAnimationController.GunLeftHandREF = weaponData.GunLeftREF; return true; @@ -178,7 +154,7 @@ public class WeaponManager : NetworkBehaviour public bool dropWeapon(float dropForce, int index) { if(index != 2) { - GameObject currentWeapon = activeWeapons[index].weapon; + GameObject currentWeapon = activeWeapons[index]; currentWeapon.SetActive(true); Rigidbody rigid = currentWeapon.GetComponent(); rigid.useGravity = true; @@ -187,10 +163,7 @@ public class WeaponManager : NetworkBehaviour // Activate all Collider SetAllColliderStatus(currentWeapon, true); currentWeapon.gameObject.transform.SetParent(null); - - WeaponStruct emptyWeapon = new WeaponStruct(); - emptyWeapon.weapon = null; - activeWeapons[index] = emptyWeapon; + activeWeapons[index] = null; return true; } else { @@ -207,13 +180,4 @@ public class WeaponManager : NetworkBehaviour } } - #region hook - - public void updateInventory(List oldList, List newList) - { - Debug.Log("UpdateInventory"); - } - - #endregion - } diff --git a/ProjectSettings/EditorBuildSettings.asset b/ProjectSettings/EditorBuildSettings.asset index f816b61..b35555d 100644 --- a/ProjectSettings/EditorBuildSettings.asset +++ b/ProjectSettings/EditorBuildSettings.asset @@ -8,13 +8,13 @@ EditorBuildSettings: - enabled: 0 path: Assets/Scenes/TestOfflineScene.unity guid: 20dba395f2cd9824288c340124ce9d6f - - enabled: 0 + - enabled: 1 path: Assets/Scenes/HomeScene.unity guid: 68e95db5b9c629148994409c6c7f814a - enabled: 1 path: Assets/Scenes/TestScene.unity guid: 9fc0d4010bbf28b4594072e72b8655ab - - enabled: 0 + - enabled: 1 path: Assets/Scenes/Lobby.unity guid: 33f487c6a0f179a4cb0f9cd2f080aca8 m_configObjects: {} diff --git a/UserSettings/EditorUserSettings.asset b/UserSettings/EditorUserSettings.asset index 4f21591..007dbb6 100644 --- a/UserSettings/EditorUserSettings.asset +++ b/UserSettings/EditorUserSettings.asset @@ -21,10 +21,10 @@ EditorUserSettings: value: 500252525d020a0d0c5e0a73477a5e441515482c752b22622b794563e3e33560 flags: 0 RecentlyUsedSceneGuid-5: - value: 5509515f50510b0e0f570f74427a0e444e4e417e78787f337b2a4a35bab16039 + value: 5a5757560101590a5d0c0e24427b5d44434e4c7a7b7a23677f2b4565b7b5353a flags: 0 RecentlyUsedSceneGuid-6: - value: 5a5757560101590a5d0c0e24427b5d44434e4c7a7b7a23677f2b4565b7b5353a + value: 5509515f50510b0e0f570f74427a0e444e4e417e78787f337b2a4a35bab16039 flags: 0 RecentlyUsedScenePath-0: value: 22424703114646680e0b0227036c6c111b07142f1f2b233e2867083debf42d