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

111 lines
2.1 KiB
C#
Raw Normal View History

2021-12-14 22:53:53 +00:00
using QSB.Player;
using UnityEngine;
2020-07-29 21:04:50 +00:00
namespace QSB.Tools
2020-07-29 21:04:50 +00:00
{
2020-12-02 21:23:01 +00:00
public class QSBTool : PlayerTool
{
2021-12-14 22:53:53 +00:00
public PlayerInfo Player { get; set; }
2020-12-02 21:23:01 +00:00
public ToolType Type { get; set; }
2022-01-01 00:38:17 +00:00
public GameObject ToolGameObject
{
get => _toolGameObject;
set
{
_toolGameObject = value;
QSBCore.UnityEvents.FireInNUpdates(
() => DitheringAnimator = _toolGameObject.AddComponent<DitheringAnimator>(),
5);
}
}
private GameObject _toolGameObject;
public DitheringAnimator DitheringAnimator { get; set; }
2020-12-02 21:23:01 +00:00
public DampedSpringQuat MoveSpring
{
get => _moveSpring;
set => _moveSpring = value;
}
public Transform StowTransform
{
get => _stowTransform;
set => _stowTransform = value;
}
public Transform HoldTransform
{
get => _holdTransform;
set => _holdTransform = value;
}
public float ArrivalDegrees
{
get => _arrivalDegrees;
set => _arrivalDegrees = value;
}
2022-01-01 00:38:17 +00:00
protected bool _isDitheringOut;
public override void Start()
{
base.Start();
ToolGameObject?.SetActive(false);
}
2021-11-10 09:12:05 +00:00
public virtual void OnEnable() => ToolGameObject?.SetActive(true);
2022-01-01 00:38:17 +00:00
public virtual void OnDisable()
{
if (!_isDitheringOut)
{
ToolGameObject?.SetActive(false);
}
}
2020-12-02 21:23:01 +00:00
public void ChangeEquipState(bool equipState)
{
if (equipState)
{
EquipTool();
2020-12-11 23:13:13 +00:00
return;
2020-12-02 21:23:01 +00:00
}
2021-06-18 21:38:32 +00:00
2020-12-11 23:13:13 +00:00
UnequipTool();
2020-12-02 21:23:01 +00:00
}
2021-12-14 22:53:53 +00:00
public override void EquipTool()
{
base.EquipTool();
2022-01-01 00:38:17 +00:00
if (DitheringAnimator != null && DitheringAnimator._renderers != null)
{
ToolGameObject?.SetActive(true);
DitheringAnimator.SetVisible(true, 5f);
}
2021-12-14 22:53:53 +00:00
Player.AudioController.PlayEquipTool();
}
public override void UnequipTool()
{
base.UnequipTool();
2022-01-01 00:38:17 +00:00
if (DitheringAnimator != null && DitheringAnimator._renderers != null)
{
_isDitheringOut = true;
DitheringAnimator.SetVisible(false, 5f);
QSBCore.UnityEvents.RunWhen(() => DitheringAnimator._visibleFraction == 0, FinishDitherOut);
}
2021-12-14 22:53:53 +00:00
Player.AudioController.PlayUnequipTool();
}
2022-01-01 00:38:17 +00:00
public virtual void FinishDitherOut()
{
ToolGameObject?.SetActive(false);
_isDitheringOut = false;
}
2020-12-02 21:23:01 +00:00
}
2020-07-29 21:04:50 +00:00
}