78 lines
1.3 KiB
C#
78 lines
1.3 KiB
C#
using DG.Tweening;
|
|
using Obvious.Soap;
|
|
using SoapCustomVariable;
|
|
using UnityEngine;
|
|
|
|
public class UI_AttachmentDistance : MonoBehaviour
|
|
{
|
|
[SerializeField]
|
|
private FloatVariable attachmentDistance;
|
|
|
|
[SerializeField]
|
|
private Vector3Variable attachmentPosition;
|
|
|
|
[SerializeField]
|
|
private FSMVariable playerState;
|
|
|
|
private Camera mainCam;
|
|
|
|
private CanvasGroup canvasGroup;
|
|
|
|
private bool isEnabled;
|
|
|
|
private void Start()
|
|
{
|
|
canvasGroup = GetComponent<CanvasGroup>();
|
|
SetEnabled(value: false);
|
|
}
|
|
|
|
private void OnEnable()
|
|
{
|
|
playerState.OnValueChanged += PlayerState_OnValueChanged;
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
playerState.OnValueChanged -= PlayerState_OnValueChanged;
|
|
}
|
|
|
|
private void PlayerState_OnValueChanged(State state)
|
|
{
|
|
if (state == State.fishing || state == State.fight)
|
|
{
|
|
SetEnabled(value: true);
|
|
}
|
|
else
|
|
{
|
|
SetEnabled(value: false);
|
|
}
|
|
}
|
|
|
|
private void SetEnabled(bool value)
|
|
{
|
|
if (value)
|
|
{
|
|
canvasGroup.DOFade(1f, 0.5f).SetEase(Ease.Linear);
|
|
}
|
|
else
|
|
{
|
|
canvasGroup.DOKill();
|
|
canvasGroup.alpha = 0f;
|
|
}
|
|
isEnabled = value;
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (isEnabled)
|
|
{
|
|
if (mainCam == null)
|
|
{
|
|
mainCam = Camera.main;
|
|
}
|
|
Vector3 vector = mainCam.WorldToScreenPoint(attachmentPosition.Value);
|
|
base.transform.position = vector + Vector3.up * 35f;
|
|
}
|
|
}
|
|
}
|