Make weapon switching work

This commit is contained in:
Sofia 2020-08-20 21:55:11 +03:00
parent 79852b52fb
commit 6c40f7bb6f
5 changed files with 68 additions and 23 deletions

View File

@ -381,7 +381,7 @@ Animator:
m_PrefabInstance: {fileID: 0} m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6228136265624521654} m_GameObject: {fileID: 6228136265624521654}
m_Enabled: 1 m_Enabled: 0
m_Avatar: {fileID: 0} m_Avatar: {fileID: 0}
m_Controller: {fileID: 9100000, guid: 8468d9a1f10314a4c998349493611489, type: 2} m_Controller: {fileID: 9100000, guid: 8468d9a1f10314a4c998349493611489, type: 2}
m_CullingMode: 0 m_CullingMode: 0

View File

@ -157,6 +157,36 @@ Transform:
m_Father: {fileID: 4677107243738498813} m_Father: {fileID: 4677107243738498813}
m_RootOrder: 0 m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &4990576539229878572
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1602672112052966102}
m_Layer: 0
m_Name: ScopeCamera
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &1602672112052966102
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4990576539229878572}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 50, y: 50, z: 50}
m_Children: []
m_Father: {fileID: 4677107243738498813}
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &5022353220472231776 --- !u!1 &5022353220472231776
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -187,6 +217,7 @@ Transform:
m_Children: m_Children:
- {fileID: 1605033999665909937} - {fileID: 1605033999665909937}
- {fileID: 264070833573311472} - {fileID: 264070833573311472}
- {fileID: 1602672112052966102}
m_Father: {fileID: 0} m_Father: {fileID: 0}
m_RootOrder: 0 m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
@ -207,7 +238,7 @@ MonoBehaviour:
Handle: {fileID: 1605033999665909937} Handle: {fileID: 1605033999665909937}
LaserPrefab: {fileID: 8009551885746485900, guid: 5c99da0361d098646b319a35fcc80095, type: 3} LaserPrefab: {fileID: 8009551885746485900, guid: 5c99da0361d098646b319a35fcc80095, type: 3}
RaygunAnimator: {fileID: 823779526010534736} RaygunAnimator: {fileID: 823779526010534736}
ScopeCamera: {fileID: 0} ScopeCamera: {fileID: 1602672112052966102}
BulletSourcePoint: {fileID: 9048980524933835922} BulletSourcePoint: {fileID: 9048980524933835922}
BulletHitLayer: BulletHitLayer:
serializedVersion: 2 serializedVersion: 2
@ -309,31 +340,31 @@ PrefabInstance:
m_Modifications: m_Modifications:
- target: {fileID: -8679921383154817045, guid: 6a5fc221f07cc47409a6118dbbb9258a, type: 3} - target: {fileID: -8679921383154817045, guid: 6a5fc221f07cc47409a6118dbbb9258a, type: 3}
propertyPath: m_LocalPosition.x propertyPath: m_LocalPosition.x
value: 0 value: 0.049091168
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: 6a5fc221f07cc47409a6118dbbb9258a, type: 3} - target: {fileID: -8679921383154817045, guid: 6a5fc221f07cc47409a6118dbbb9258a, type: 3}
propertyPath: m_LocalPosition.y propertyPath: m_LocalPosition.y
value: 0 value: 0.063
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: 6a5fc221f07cc47409a6118dbbb9258a, type: 3} - target: {fileID: -8679921383154817045, guid: 6a5fc221f07cc47409a6118dbbb9258a, type: 3}
propertyPath: m_LocalPosition.z propertyPath: m_LocalPosition.z
value: 0 value: 0.17629232
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: 6a5fc221f07cc47409a6118dbbb9258a, type: 3} - target: {fileID: -8679921383154817045, guid: 6a5fc221f07cc47409a6118dbbb9258a, type: 3}
propertyPath: m_LocalRotation.x propertyPath: m_LocalRotation.x
value: -0.5 value: -0.5604943
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: 6a5fc221f07cc47409a6118dbbb9258a, type: 3} - target: {fileID: -8679921383154817045, guid: 6a5fc221f07cc47409a6118dbbb9258a, type: 3}
propertyPath: m_LocalRotation.y propertyPath: m_LocalRotation.y
value: -0.5 value: -0.3032949
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: 6a5fc221f07cc47409a6118dbbb9258a, type: 3} - target: {fileID: -8679921383154817045, guid: 6a5fc221f07cc47409a6118dbbb9258a, type: 3}
propertyPath: m_LocalRotation.z propertyPath: m_LocalRotation.z
value: -0.5 value: -0.43109903
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: 6a5fc221f07cc47409a6118dbbb9258a, type: 3} - target: {fileID: -8679921383154817045, guid: 6a5fc221f07cc47409a6118dbbb9258a, type: 3}
propertyPath: m_LocalRotation.w propertyPath: m_LocalRotation.w
value: 0.5 value: 0.63875824
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: 6a5fc221f07cc47409a6118dbbb9258a, type: 3} - target: {fileID: -8679921383154817045, guid: 6a5fc221f07cc47409a6118dbbb9258a, type: 3}
propertyPath: m_RootOrder propertyPath: m_RootOrder
@ -341,11 +372,11 @@ PrefabInstance:
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: 6a5fc221f07cc47409a6118dbbb9258a, type: 3} - target: {fileID: -8679921383154817045, guid: 6a5fc221f07cc47409a6118dbbb9258a, type: 3}
propertyPath: m_LocalEulerAnglesHint.x propertyPath: m_LocalEulerAnglesHint.x
value: -90 value: -77.834
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: 6a5fc221f07cc47409a6118dbbb9258a, type: 3} - target: {fileID: -8679921383154817045, guid: 6a5fc221f07cc47409a6118dbbb9258a, type: 3}
propertyPath: m_LocalEulerAnglesHint.y propertyPath: m_LocalEulerAnglesHint.y
value: 0 value: 27.035
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: 6a5fc221f07cc47409a6118dbbb9258a, type: 3} - target: {fileID: -8679921383154817045, guid: 6a5fc221f07cc47409a6118dbbb9258a, type: 3}
propertyPath: m_LocalEulerAnglesHint.z propertyPath: m_LocalEulerAnglesHint.z

View File

@ -32,7 +32,7 @@ TextureImporter:
maxTextureSize: 2048 maxTextureSize: 2048
textureSettings: textureSettings:
serializedVersion: 2 serializedVersion: 2
filterMode: -1 filterMode: 0
aniso: -1 aniso: -1
mipBias: -100 mipBias: -100
wrapU: 1 wrapU: 1

View File

@ -1,7 +1,7 @@
using UnityEngine; using System;
using UnityEngine;
using UnityEngine.InputSystem; using UnityEngine.InputSystem;
using NeonTea.Quakeball.Interface; using NeonTea.Quakeball.Interface;
using NeonTea.Quakeball.Networking;
using NeonTea.Quakeball.Networking.Packets; using NeonTea.Quakeball.Networking.Packets;
namespace NeonTea.Quakeball.Players { namespace NeonTea.Quakeball.Players {
@ -20,6 +20,8 @@ namespace NeonTea.Quakeball.Players {
private InputAction ShootAction; private InputAction ShootAction;
private InputAction SwitchUpAction; private InputAction SwitchUpAction;
private InputAction[] WeaponSwitchActions = new InputAction[9];
private float PreviousPlayerUpdate = -1; private float PreviousPlayerUpdate = -1;
private float PreviousPlayerFullSync = -1; private float PreviousPlayerFullSync = -1;
private bool WantsToJump = false; private bool WantsToJump = false;
@ -53,15 +55,17 @@ namespace NeonTea.Quakeball.Players {
Networking.Net.Singleton.Instance.LocalPlayerAction(PlayerAction.Shoot, shootData); Networking.Net.Singleton.Instance.LocalPlayerAction(PlayerAction.Shoot, shootData);
} }
Player.Shoot(); Player.Shoot();
};/* };
ShootAction = new InputAction("Shoot", binding: "<Mouse>/leftButton"); Action<InputAction.CallbackContext> CreateLambda(int number) {
ShootAction.performed += _ => { return (context) => {
if (Networking.Net.Singleton.Instance != null) { Player.SwitchItem(number);
ShootData shootData = new ShootData(Player.Pitch, Player.Yaw, Player.CreateSyncPacket()); Player.CurrentItem.Animator.enabled = true;
Networking.Net.Singleton.Instance.LocalPlayerAction(PlayerAction.Shoot, shootData); };
}
for (int i = 0; i < 9; i++) {
WeaponSwitchActions[i] = new InputAction($"Switch to weapon {i + 1}", binding: $"<Keyboard>/{i + 1}");
WeaponSwitchActions[i].performed += CreateLambda(i);
} }
Player.Shoot();
};*/
Terminal.Singleton.RegisterCommand("tp", args => { Terminal.Singleton.RegisterCommand("tp", args => {
if (args.Length != 3) { if (args.Length != 3) {
@ -79,6 +83,9 @@ namespace NeonTea.Quakeball.Players {
LookAction.Disable(); LookAction.Disable();
MoveAction.Disable(); MoveAction.Disable();
ShootAction.Disable(); ShootAction.Disable();
foreach (InputAction action in WeaponSwitchActions) {
action.Disable();
}
Cursor.lockState = CursorLockMode.None; Cursor.lockState = CursorLockMode.None;
Cursor.visible = true; Cursor.visible = true;
} else { } else {
@ -87,6 +94,9 @@ namespace NeonTea.Quakeball.Players {
LookAction.Enable(); LookAction.Enable();
MoveAction.Enable(); MoveAction.Enable();
ShootAction.Enable(); ShootAction.Enable();
foreach (InputAction action in WeaponSwitchActions) {
action.Enable();
}
Cursor.visible = false; Cursor.visible = false;
Cursor.lockState = CursorLockMode.Locked; Cursor.lockState = CursorLockMode.Locked;
} }

View File

@ -224,9 +224,13 @@ namespace NeonTea.Quakeball.Players {
CurrentItem.SwitchedOut(); CurrentItem.SwitchedOut();
} }
GameObject obj = GameObject.Instantiate(PossibleItems[index]); GameObject obj = GameObject.Instantiate(PossibleItems[index]);
Vector3 localPos = obj.transform.localPosition; Vector3 localPos = obj.transform.localPosition;
Quaternion localRot = obj.transform.localRotation;
obj.transform.parent = ItemRoot.transform; obj.transform.parent = ItemRoot.transform;
obj.transform.localPosition = localPos; obj.transform.localPosition = localPos;
obj.transform.localRotation = localRot;
CurrentItem = obj.GetComponent<Item>(); CurrentItem = obj.GetComponent<Item>();
CurrentItem.Holder = this; CurrentItem.Holder = this;
CurrentItem.Switched(); CurrentItem.Switched();