using System;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
namespace ShrinkTutorial
{
public class ShrinkTutorialDialog : MonoBehaviour
{
[Header("Explicit scene bindings")]
[SerializeField] private RectTransform _rectTransform;
[SerializeField] private RectTransform _arrowRectTransform;
[SerializeField] private TextMeshProUGUI _contentText;
[SerializeField] private GameObject _skipButtonObject;
private Action _skipAction;
///
/// Uses UI objects that already exist in the scene. This path intentionally does not
/// create children or add listeners at runtime; scene-authored persistent callbacks
/// remain the source of truth.
///
public bool BindExisting()
{
if (!_rectTransform)
_rectTransform = GetComponent();
if (_rectTransform && _arrowRectTransform && _contentText)
return true;
Debug.LogError("[ShrinkTutorial] Explicit dialog bindings are incomplete.", this);
return false;
}
public void Initialize(Transform parent, Action skipAction)
{
_skipAction = skipAction;
_rectTransform = GetComponent();
if (!_rectTransform)
_rectTransform = gameObject.AddComponent();
_rectTransform.SetParent(parent, false);
_rectTransform.sizeDelta = new Vector2(360f, 180f);
_rectTransform.anchorMin = new Vector2(0.5f, 0.5f);
_rectTransform.anchorMax = new Vector2(0.5f, 0.5f);
_rectTransform.pivot = new Vector2(0.5f, 0.5f);
var background = gameObject.AddComponent();
background.color = new Color(0.08f, 0.1f, 0.14f, 0.96f);
background.raycastTarget = true;
var content = CreateText("Content", "Tutorial", 24, TextAlignmentOptions.TopLeft);
var contentRect = content.rectTransform;
contentRect.SetParent(_rectTransform, false);
contentRect.anchorMin = new Vector2(0f, 0f);
contentRect.anchorMax = new Vector2(1f, 1f);
contentRect.offsetMin = new Vector2(24f, 64f);
contentRect.offsetMax = new Vector2(-24f, -24f);
_contentText = content;
var skipButton = new GameObject("SkipButton", typeof(RectTransform), typeof(Image), typeof(Button));
var skipRect = skipButton.GetComponent();
skipRect.SetParent(_rectTransform, false);
skipRect.anchorMin = new Vector2(1f, 0f);
skipRect.anchorMax = new Vector2(1f, 0f);
skipRect.pivot = new Vector2(1f, 0f);
skipRect.anchoredPosition = new Vector2(-16f, 16f);
skipRect.sizeDelta = new Vector2(96f, 36f);
var skipImage = skipButton.GetComponent();
skipImage.color = new Color(0.22f, 0.34f, 0.5f, 1f);
var skipButtonComponent = skipButton.GetComponent