quantum-space-buddies/QSB/Tools/QSBTool.cs

113 lines
1.9 KiB
C#
Raw Normal View History

2021-12-14 22:53:53 +00:00
using QSB.Player;
2022-02-18 13:33:48 +00:00
using QSB.PlayerBodySetup.Remote;
2022-01-29 09:24:15 +00:00
using QSB.Utility;
2021-12-14 22:53:53 +00:00
using UnityEngine;
2020-07-29 21:04:50 +00:00
2022-03-03 03:46:33 +00:00
namespace QSB.Tools;
2022-08-27 18:44:52 +00:00
[UsedInUnityProject]
2022-03-03 03:46:33 +00:00
public class QSBTool : PlayerTool
2020-07-29 21:04:50 +00:00
{
2022-03-03 03:46:33 +00:00
public PlayerInfo Player { get; set; }
public ToolType Type { get; set; }
public GameObject ToolGameObject { get; set; }
[SerializeField]
private QSBDitheringAnimator _ditheringAnimator;
public DampedSpringQuat MoveSpring
{
2022-03-03 03:46:33 +00:00
get => _moveSpring;
set => _moveSpring = value;
}
2020-12-02 21:23:01 +00:00
2022-03-03 03:46:33 +00:00
public Transform StowTransform
{
get => _stowTransform;
set => _stowTransform = value;
}
2020-12-02 21:23:01 +00:00
2022-03-03 03:46:33 +00:00
public Transform HoldTransform
{
get => _holdTransform;
set => _holdTransform = value;
}
2020-12-02 21:23:01 +00:00
2022-03-03 03:46:33 +00:00
public float ArrivalDegrees
{
get => _arrivalDegrees;
set => _arrivalDegrees = value;
}
2022-03-03 03:46:33 +00:00
protected bool _isDitheringOut;
public override void Start()
{
base.Start();
ToolGameObject?.SetActive(false);
_ditheringAnimator.SetVisible(false);
}
2020-12-02 21:23:01 +00:00
2022-04-16 09:08:59 +00:00
public virtual void OnEnable()
{
2022-05-30 19:33:13 +00:00
if (!Player?.FlyingShip ?? false)
2022-04-16 09:08:59 +00:00
{
ToolGameObject?.SetActive(true);
}
}
2022-01-01 00:38:17 +00:00
2022-03-03 03:46:33 +00:00
public virtual void OnDisable()
{
if (!_isDitheringOut)
2022-01-01 00:38:17 +00:00
{
ToolGameObject?.SetActive(false);
}
2022-03-03 03:46:33 +00:00
}
2022-01-01 00:38:17 +00:00
2022-03-03 03:46:33 +00:00
public void ChangeEquipState(bool equipState)
{
if (equipState)
2022-01-01 00:38:17 +00:00
{
2022-03-03 03:46:33 +00:00
EquipTool();
return;
2022-01-01 00:38:17 +00:00
}
2020-12-02 21:23:01 +00:00
2022-03-03 03:46:33 +00:00
UnequipTool();
}
2021-06-18 21:38:32 +00:00
2022-03-03 03:46:33 +00:00
public override void EquipTool()
{
base.EquipTool();
2021-12-14 22:53:53 +00:00
2022-04-16 20:37:15 +00:00
if (!Player.FlyingShip)
2021-12-14 22:53:53 +00:00
{
2022-03-03 03:46:33 +00:00
ToolGameObject?.SetActive(true);
2022-04-16 20:37:15 +00:00
Player.AudioController.PlayEquipTool();
}
2022-01-01 00:38:17 +00:00
2022-04-16 20:37:15 +00:00
if (_ditheringAnimator != null)
2022-04-16 09:08:59 +00:00
{
2022-04-16 20:37:15 +00:00
_ditheringAnimator.SetVisible(true, .2f);
2022-04-16 09:08:59 +00:00
}
2022-03-03 03:46:33 +00:00
}
2022-03-03 03:46:33 +00:00
public override void UnequipTool()
{
base.UnequipTool();
2022-03-03 03:46:33 +00:00
if (_ditheringAnimator != null)
{
2022-03-03 03:46:33 +00:00
_isDitheringOut = true;
_ditheringAnimator.SetVisible(false, .2f);
Delay.RunWhen(() => _ditheringAnimator.FullyInvisible, FinishDitherOut);
}
2022-03-03 03:46:33 +00:00
Player.AudioController.PlayUnequipTool();
}
public virtual void FinishDitherOut()
{
ToolGameObject?.SetActive(false);
_isDitheringOut = false;
2020-12-02 21:23:01 +00:00
}
2022-03-03 03:46:33 +00:00
}