This commit is contained in:
Noah4ever
2022-01-17 13:31:14 +01:00
parent eff2619acd
commit e5e44eeb55
5 changed files with 132 additions and 38 deletions

View File

@@ -1208,6 +1208,63 @@ 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}

View File

@@ -62,7 +62,8 @@ public class Shoot : NetworkBehaviour
// Throw Grenade
throwGrenade();
} // If current weapon kind is kinfe
else {
else {
Debug.Log("Throw Hands");
// Throw hands (punch)
}
}

View File

@@ -3,44 +3,54 @@ 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;
public List<GameObject> activeWeapons = new List<GameObject>();
[SyncVar]
public SyncList<WeaponStruct> activeWeapons = new SyncList<WeaponStruct>(new WeaponStruct[4]);
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<ProcedualAnimationController>();
currentWeaponIndex = 2; // Hand
weaponData = activeWeapons[currentWeaponIndex].GetComponent<Weapon>(); // Hand
GameObject hand = gunHolster.transform.Find("Hand").gameObject;
WeaponStruct addHand = new WeaponStruct();
addHand.weapon = hand;
activeWeapons[currentWeaponIndex] = addHand;
weaponData = activeWeapons[currentWeaponIndex].weapon.GetComponent<Weapon>(); // Hand
}
void Update() {
void Update() {
if (isLocalPlayer) {
if (Input.GetAxis("Mouse ScrollWheel") > 0f) { // Scroll up
lastWeaponIndex = currentWeaponIndex;
activeWeapons[currentWeaponIndex].SetActive(false);
activeWeapons[currentWeaponIndex].weapon.SetActive(false);
switchWeapon(-1);
}
else if (Input.GetAxis("Mouse ScrollWheel") < 0f) { // Scroll down
lastWeaponIndex = currentWeaponIndex;
activeWeapons[currentWeaponIndex].SetActive(false);
activeWeapons[currentWeaponIndex].weapon.SetActive(false);
switchWeapon(1);
}
if (Input.GetButtonDown("Interact")) { // e
PickupWeapon();
PickupWeapon();
}else if (Input.GetButtonDown("Drop")) { // q Droping weapon
if (activeWeapons[currentWeaponIndex] != null) {
dropWeapon(activeWeapons[currentWeaponIndex].GetComponent<Weapon>().DropForce, currentWeaponIndex); // Throws weapon away
if (activeWeapons[currentWeaponIndex].weapon != null) {
dropWeapon(activeWeapons[currentWeaponIndex].weapon.GetComponent<Weapon>().DropForce, currentWeaponIndex); // Throws weapon away
switchWeapon(1);
}
}
@@ -56,21 +66,33 @@ 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]);
shoot.setWeapon(activeWeapons[currentWeaponIndex]);
weaponData = activeWeapons[currentWeaponIndex].GetComponent<Weapon>();
procedualAnimationController.OnSwitchWeapon(activeWeapons[currentWeaponIndex].weapon);
shoot.setWeapon(activeWeapons[currentWeaponIndex].weapon);
weaponData = activeWeapons[currentWeaponIndex].weapon.GetComponent<Weapon>();
procedualAnimationController.GunRightHandREF = weaponData.GunRightREF;
procedualAnimationController.GunLeftHandREF = weaponData.GunLeftREF;
// Play weapon switch animation
switchAnimation(weaponData.WeaponKind.ToString());
activeWeapons[currentWeaponIndex].SetActive(true);
return false;
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("-------------------");
}
private void switchAnimation(string weaponType) {
switch (weaponType) {
@@ -80,7 +102,7 @@ public class WeaponManager : NetworkBehaviour
case "Grenade": ; procedualAnimationController.changePistole(true); break;
}
}
private int searchForNext(List<GameObject> l, int lastActive = 0, int direction = 1)
private int searchForNext(SyncList<WeaponStruct> l, int lastActive = 0, int direction = 1)
{
int current = lastActive + direction;
@@ -91,7 +113,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] != null)
if (l[current].weapon != null)
{
return current;
}
@@ -104,18 +126,18 @@ public class WeaponManager : NetworkBehaviour
public GameObject getCurrentWeapon() {
return activeWeapons[currentWeaponIndex].gameObject;
return activeWeapons[currentWeaponIndex].weapon.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 (GameObject obj in activeWeapons) {
if (obj != null) { obj.SetActive(false); }
foreach (WeaponStruct obj in activeWeapons) {
if (obj.weapon != null) { obj.weapon.SetActive(false); }
}
// Parent weapon to gunHolster
hit.transform.parent = gunHolster.transform;
@@ -136,17 +158,19 @@ public class WeaponManager : NetworkBehaviour
}
private bool putWeaponInArray(int index, RaycastHit hit) {
if (activeWeapons[index] != null) {
if (activeWeapons[index].weapon != null) {
// Throws weapon away
dropWeapon(activeWeapons[index].GetComponent<Weapon>().DropForce, index);
dropWeapon(activeWeapons[index].weapon.GetComponent<Weapon>().DropForce, index);
}
activeWeapons[index] = hit.transform.gameObject;
activeWeapons[index].SetActive(true);
WeaponStruct addWeapon = new WeaponStruct();
addWeapon.weapon = hit.transform.gameObject;
activeWeapons[index] = addWeapon;
activeWeapons[index].weapon.SetActive(true);
// \/ Same as in switchWeapon()
currentWeaponIndex = index;
procedualAnimationController.OnSwitchWeapon(activeWeapons[currentWeaponIndex]);
shoot.setWeapon(activeWeapons[currentWeaponIndex]);
Weapon weaponData = activeWeapons[currentWeaponIndex].GetComponent<Weapon>();
procedualAnimationController.OnSwitchWeapon(activeWeapons[currentWeaponIndex].weapon);
shoot.setWeapon(activeWeapons[currentWeaponIndex].weapon);
Weapon weaponData = activeWeapons[currentWeaponIndex].weapon.GetComponent<Weapon>();
procedualAnimationController.GunRightHandREF = weaponData.GunRightREF;
procedualAnimationController.GunLeftHandREF = weaponData.GunLeftREF;
return true;
@@ -154,7 +178,7 @@ public class WeaponManager : NetworkBehaviour
public bool dropWeapon(float dropForce, int index) {
if(index != 2) {
GameObject currentWeapon = activeWeapons[index];
GameObject currentWeapon = activeWeapons[index].weapon;
currentWeapon.SetActive(true);
Rigidbody rigid = currentWeapon.GetComponent<Rigidbody>();
rigid.useGravity = true;
@@ -163,7 +187,10 @@ public class WeaponManager : NetworkBehaviour
// Activate all Collider
SetAllColliderStatus(currentWeapon, true);
currentWeapon.gameObject.transform.SetParent(null);
activeWeapons[index] = null;
WeaponStruct emptyWeapon = new WeaponStruct();
emptyWeapon.weapon = null;
activeWeapons[index] = emptyWeapon;
return true;
}
else {
@@ -180,4 +207,13 @@ public class WeaponManager : NetworkBehaviour
}
}
#region hook
public void updateInventory(List<GameObject> oldList, List<GameObject> newList)
{
Debug.Log("UpdateInventory");
}
#endregion
}

View File

@@ -8,13 +8,13 @@ EditorBuildSettings:
- enabled: 0
path: Assets/Scenes/TestOfflineScene.unity
guid: 20dba395f2cd9824288c340124ce9d6f
- enabled: 1
- enabled: 0
path: Assets/Scenes/HomeScene.unity
guid: 68e95db5b9c629148994409c6c7f814a
- enabled: 1
path: Assets/Scenes/TestScene.unity
guid: 9fc0d4010bbf28b4594072e72b8655ab
- enabled: 1
- enabled: 0
path: Assets/Scenes/Lobby.unity
guid: 33f487c6a0f179a4cb0f9cd2f080aca8
m_configObjects: {}

View File

@@ -21,10 +21,10 @@ EditorUserSettings:
value: 500252525d020a0d0c5e0a73477a5e441515482c752b22622b794563e3e33560
flags: 0
RecentlyUsedSceneGuid-5:
value: 5a5757560101590a5d0c0e24427b5d44434e4c7a7b7a23677f2b4565b7b5353a
value: 5509515f50510b0e0f570f74427a0e444e4e417e78787f337b2a4a35bab16039
flags: 0
RecentlyUsedSceneGuid-6:
value: 5509515f50510b0e0f570f74427a0e444e4e417e78787f337b2a4a35bab16039
value: 5a5757560101590a5d0c0e24427b5d44434e4c7a7b7a23677f2b4565b7b5353a
flags: 0
RecentlyUsedScenePath-0:
value: 22424703114646680e0b0227036c6c111b07142f1f2b233e2867083debf42d