projectEli/Assets/Inventory System/Scripts/NeoFPSPause.cs

75 lines
2.8 KiB
C#
Raw Normal View History

2022-12-23 03:50:16 +00:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using NeoFPS;
using NeoCC;
using NeoFPS.SinglePlayer;
namespace SimpleInventorySystem
{
public class NeoFPSPause : MonoBehaviour
{
NeoCharacterController ncc;
MouseAndGamepadAimController inputAim;
InputCharacterMotion inputMotion;
InputInventory inputInventory;
FpsInventoryQuickSwitch fpsIQS;
Rigidbody rb;
bool usingState;
FpsSoloCharacter fpsSoloCharacter;
Player_IS player;
InputFirearm[] inputFirearms;
NeoFPSAnimationController nfpsAC;
// Update is called once per frame
void Update()
{
if (player == null && InventorySystem.instance.player != null)
{
player = InventorySystem.instance.player;
inputMotion = player.GetComponent<InputCharacterMotion>();
inputAim = player.GetComponent<MouseAndGamepadAimController>();
ncc = player.GetComponent<NeoCharacterController>();
inputInventory = player.GetComponent<InputInventory>();
fpsIQS = player.GetComponent<FpsInventoryQuickSwitch>();
rb = player.GetComponent<Rigidbody>();
fpsSoloCharacter = player.GetComponent<FpsSoloCharacter>();
inputFirearms = player.GetComponentsInChildren<InputFirearm>();
nfpsAC = player.GetComponent<NeoFPSAnimationController>();
}
else if (usingState != InventorySystem.instance.IsUsingInventoryMenuUI())
{
switch (InventorySystem.instance.IsUsingInventoryMenuUI())
{
case true:
fpsSoloCharacter.motionController.inputMoveDirection = Vector2.zero;
rb.velocity = new Vector3(0, rb.velocity.y, 0);
//ncc.ResetVelocity(); // TODO: optimize this in case player is falling
//ncc.SetVelocity(new Vector3(0, ncc.velocity.y, 0));
SetEnabledComponents(false);
usingState = true;
break;
case false:
SetEnabledComponents(true);
usingState = false;
break;
}
}
}
void SetEnabledComponents(bool value)
{
inputMotion.enabled = value;
inputAim.enabled = value;
inputInventory.enabled = value;
fpsIQS.enabled = value;
ncc.enabled = value;
fpsSoloCharacter.enabled = value;
nfpsAC.enabled = value;
foreach (InputFirearm inputFirearm in inputFirearms)
{
inputFirearm.enabled = value;
}
}
}
}