2024-12-16 12:06:42 +00:00
|
|
|
using System;
|
|
|
|
using System.Collections;
|
|
|
|
using BlueWater.Utility;
|
|
|
|
using DG.Tweening;
|
|
|
|
using Sirenix.OdinInspector;
|
|
|
|
using TMPro;
|
|
|
|
using UnityEngine;
|
|
|
|
using UnityEngine.Localization;
|
|
|
|
using UnityEngine.Localization.Settings;
|
|
|
|
using UnityEngine.ResourceManagement.AsyncOperations;
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
|
|
|
namespace BlueWater
|
|
|
|
{
|
|
|
|
public class TutorialPageToggle : MonoBehaviour
|
|
|
|
{
|
2024-12-17 07:42:47 +00:00
|
|
|
[field: SerializeField]
|
|
|
|
public RectTransform Rect { get; private set; }
|
|
|
|
|
2024-12-16 12:06:42 +00:00
|
|
|
[SerializeField]
|
|
|
|
private Toggle _toggle;
|
|
|
|
|
|
|
|
[SerializeField]
|
|
|
|
private Image _toggleImage;
|
|
|
|
|
|
|
|
[SerializeField]
|
|
|
|
private TMP_Text _buttonText;
|
|
|
|
|
|
|
|
[SerializeField]
|
|
|
|
private Sprite _selectToggleSprite;
|
|
|
|
|
|
|
|
[SerializeField]
|
|
|
|
private Sprite _deselectToggleSprite;
|
|
|
|
|
|
|
|
[Title("연출")]
|
|
|
|
[SerializeField]
|
|
|
|
private Vector2 _buttonImageScale = new(1f, 1.3f);
|
|
|
|
|
|
|
|
[SerializeField]
|
|
|
|
private Vector2 _buttonTextPositionY = new(0f, 10f);
|
|
|
|
|
|
|
|
[SerializeField]
|
|
|
|
private float _duration = 0.2f;
|
|
|
|
|
|
|
|
private TutorialInfo _tutorialInfo;
|
|
|
|
private Coroutine _changedLocaleInstance;
|
|
|
|
private Sequence _selectSequence;
|
|
|
|
private Sequence _deselectSequence;
|
2024-12-17 07:42:47 +00:00
|
|
|
|
2024-12-16 12:06:42 +00:00
|
|
|
public Action<bool> OnToggleEvent;
|
|
|
|
|
|
|
|
private void Awake()
|
|
|
|
{
|
|
|
|
LocalizationSettings.SelectedLocaleChanged += OnChangedLocale;
|
|
|
|
}
|
2024-12-18 16:00:39 +00:00
|
|
|
|
|
|
|
private void OnEnable()
|
|
|
|
{
|
|
|
|
_buttonText.text = Utils.GetLocalizedString(_tutorialInfo.TitleTextIdx);
|
|
|
|
}
|
2024-12-16 12:06:42 +00:00
|
|
|
|
|
|
|
private void OnDestroy()
|
|
|
|
{
|
|
|
|
LocalizationSettings.SelectedLocaleChanged -= OnChangedLocale;
|
|
|
|
|
|
|
|
_selectSequence.Kill();
|
|
|
|
_deselectSequence.Kill();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void OnChangedLocale(Locale locale)
|
|
|
|
{
|
|
|
|
if (!gameObject.activeInHierarchy) return;
|
|
|
|
|
|
|
|
Utils.StartUniqueCoroutine(this, ref _changedLocaleInstance, ChangeLocaleCoroutine(locale));
|
|
|
|
StartCoroutine(ChangeLocaleCoroutine(locale));
|
|
|
|
}
|
|
|
|
|
|
|
|
private IEnumerator ChangeLocaleCoroutine(Locale locale)
|
|
|
|
{
|
|
|
|
var loadingOperation = Utils.GetTableAsync();
|
|
|
|
yield return loadingOperation;
|
|
|
|
|
|
|
|
if (loadingOperation.Status == AsyncOperationStatus.Succeeded)
|
|
|
|
{
|
|
|
|
_buttonText.text = Utils.GetLocalizedString(_tutorialInfo.TitleTextIdx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Initialize(TutorialInfo tutorialInfo)
|
|
|
|
{
|
|
|
|
_tutorialInfo = tutorialInfo;
|
|
|
|
|
|
|
|
gameObject.name = $"{_tutorialInfo.TutorialName}Toggle";
|
|
|
|
_buttonText.text = Utils.GetLocalizedString(_tutorialInfo.TitleTextIdx);
|
|
|
|
|
|
|
|
_selectSequence = DOTween.Sequence()
|
|
|
|
.Append(_toggleImage.transform.DOScaleY(_buttonImageScale.y, _duration).From(_buttonImageScale.x))
|
|
|
|
.Join(_buttonText.transform.DOLocalMoveY(_buttonTextPositionY.y, _duration).From(_buttonTextPositionY.x))
|
|
|
|
.SetEase(Ease.Linear)
|
|
|
|
.SetUpdate(true)
|
|
|
|
.SetAutoKill(false)
|
|
|
|
.Pause();
|
|
|
|
|
|
|
|
_deselectSequence = DOTween.Sequence()
|
|
|
|
.Append(_toggleImage.transform.DOScaleY(_buttonImageScale.x, _duration).From(_buttonImageScale.y))
|
|
|
|
.Join(_buttonText.transform.DOLocalMoveY(_buttonTextPositionY.x, _duration).From(_buttonTextPositionY.x))
|
|
|
|
.SetEase(Ease.Linear)
|
|
|
|
.SetUpdate(true)
|
|
|
|
.SetAutoKill(false)
|
|
|
|
.Pause();
|
2024-12-17 07:42:47 +00:00
|
|
|
|
|
|
|
_toggle.interactable = true;
|
|
|
|
_toggle.isOn = false;
|
|
|
|
_toggleImage.sprite = _deselectToggleSprite;
|
|
|
|
Vector3 newPosition = _buttonText.transform.localPosition;
|
|
|
|
newPosition.y = _buttonTextPositionY.x;
|
|
|
|
_buttonText.transform.localPosition = newPosition;
|
|
|
|
Vector3 newScale = _toggleImage.transform.localScale;
|
|
|
|
newScale.y = _buttonImageScale.x;
|
|
|
|
_toggleImage.transform.localScale = newScale;
|
2024-12-16 12:06:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void OnToggle(bool isOn)
|
|
|
|
{
|
2024-12-17 07:42:47 +00:00
|
|
|
_toggle.isOn = isOn;
|
|
|
|
_toggle.interactable = !_toggle.isOn;
|
2024-12-16 12:06:42 +00:00
|
|
|
|
|
|
|
if (isOn)
|
|
|
|
{
|
|
|
|
_toggleImage.sprite = _selectToggleSprite;
|
|
|
|
_deselectSequence?.Pause();
|
|
|
|
_selectSequence.Restart();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_toggleImage.sprite = _deselectToggleSprite;
|
|
|
|
_selectSequence?.Pause();
|
|
|
|
_deselectSequence.Restart();
|
|
|
|
}
|
2024-12-17 07:42:47 +00:00
|
|
|
|
2024-12-16 12:06:42 +00:00
|
|
|
OnToggleEvent?.Invoke(isOn);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|