100 lines
3.2 KiB
C#
100 lines
3.2 KiB
C#
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
using UnityEngine.UI;
|
|
|
|
namespace Watermelon
|
|
{
|
|
public class UISettings : UIPage
|
|
{
|
|
public override bool IsPopup => true;
|
|
|
|
[BoxGroup("References", "References")]
|
|
[SerializeField] Image backgroundImage;
|
|
[BoxGroup("References", "References")]
|
|
[SerializeField] RectTransform panelRectTransform;
|
|
[BoxGroup("References", "References")]
|
|
[SerializeField] RectTransform contentRectTransform;
|
|
public RectTransform ContentRectTransform => contentRectTransform;
|
|
|
|
[BoxGroup("Buttons", "Buttons")]
|
|
[SerializeField] Button closeButton;
|
|
|
|
private float fadeIntensity;
|
|
|
|
public override void Init()
|
|
{
|
|
closeButton.onClick.AddListener(OnCloseButtonClicked);
|
|
backgroundImage.AddEvent(EventTriggerType.PointerDown, OnBackgroundClicked);
|
|
|
|
fadeIntensity = backgroundImage.color.a;
|
|
}
|
|
|
|
protected override void OnShow()
|
|
{
|
|
RecalculatePanelSize();
|
|
|
|
panelRectTransform.anchoredPosition = Vector2.down * 2000;
|
|
panelRectTransform.DOAnchoredPosition(Vector2.zero, 0.3f).SetEasing(Ease.Type.SineOut);
|
|
|
|
backgroundImage.SetAlpha(0f);
|
|
backgroundImage.DOFade(fadeIntensity, 0.3f).OnComplete(() =>
|
|
{
|
|
NotifyOpened();
|
|
});
|
|
}
|
|
|
|
protected override void OnHide()
|
|
{
|
|
panelRectTransform.DOAnchoredPosition(Vector2.down * 2000, 0.3f).SetEasing(Ease.Type.SineIn);
|
|
|
|
backgroundImage.DOFade(0f, 0.3f).OnComplete(() =>
|
|
{
|
|
NotifyClosed();
|
|
});
|
|
}
|
|
|
|
private void RecalculatePanelSize()
|
|
{
|
|
float height = Mathf.Abs(contentRectTransform.sizeDelta.y);
|
|
|
|
int childCount = contentRectTransform.childCount;
|
|
for(int i = 0; i < childCount; i++)
|
|
{
|
|
Transform childTransform = contentRectTransform.GetChild(i);
|
|
if (childTransform != null)
|
|
{
|
|
SettingsElementsGroup settingsElementsGroup = childTransform.GetComponent<SettingsElementsGroup>();
|
|
if(settingsElementsGroup != null)
|
|
{
|
|
if (settingsElementsGroup.IsGroupActive())
|
|
{
|
|
height += ((RectTransform)childTransform).sizeDelta.y;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if(childTransform.gameObject.activeSelf)
|
|
{
|
|
height += ((RectTransform)childTransform).sizeDelta.y;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
panelRectTransform.sizeDelta = new Vector2(panelRectTransform.sizeDelta.x, height);
|
|
}
|
|
|
|
public void OnCloseButtonClicked()
|
|
{
|
|
AudioController.PlaySound(AudioController.GetClip("button_sound"));
|
|
|
|
UIController.HidePage<UISettings>();
|
|
}
|
|
|
|
private void OnBackgroundClicked(PointerEventData data)
|
|
{
|
|
UIController.HidePage<UISettings>();
|
|
}
|
|
}
|
|
}
|