using System.Collections; using TMPro; using UnityEngine; using UnityEngine.UI; namespace ShrinkTutorial { public class ShrinkTutorialSampleSceneController : MonoBehaviour { public const string TutorialId = "sample.shrink_tutorial.basic"; public const string RewardAnchorId = "sample.reward.item"; public const string RewardClaimEventName = "sample.reward.claimed"; [SerializeField] private Button openInventoryButton; [SerializeField] private Button spawnRewardButton; [SerializeField] private GameObject inventoryPanel; [SerializeField] private RectTransform rewardContainer; [SerializeField] private TextMeshProUGUI statusText; private Button _spawnedRewardButton; private void Awake() { AutoWire(); BindButtons(); LogDebug($"Awake, openButton={DescribeObject(openInventoryButton)}, spawnButton={DescribeObject(spawnRewardButton)}, inventoryPanel={DescribeObject(inventoryPanel)}"); if (inventoryPanel) inventoryPanel.SetActive(false); ClearRewardItems(); SetStatus("Waiting for tutorial start."); } private IEnumerator Start() { yield return null; var tutorialManager = ShrinkTutorialManager.EnsureInstance(); tutorialManager.ClearProgress(TutorialId); tutorialManager.StartTutorial(TutorialId); } private void OnDestroy() { if (openInventoryButton) openInventoryButton.onClick.RemoveListener(HandleOpenInventory); if (spawnRewardButton) spawnRewardButton.onClick.RemoveListener(HandleSpawnReward); if (_spawnedRewardButton) _spawnedRewardButton.onClick.RemoveListener(HandleClaimReward); } private void Reset() { AutoWire(); } private void OnValidate() { AutoWire(); } public void HandleOpenInventory() { LogDebug($"HandleOpenInventory before, inventoryActive={inventoryPanel && inventoryPanel.activeSelf}"); if (inventoryPanel) inventoryPanel.SetActive(true); SetStatus("Inventory panel opened."); LogDebug($"HandleOpenInventory after, inventoryActive={inventoryPanel && inventoryPanel.activeSelf}"); } public void HandleSpawnReward() { LogDebug($"HandleSpawnReward start, hasReward={_spawnedRewardButton}"); if (!rewardContainer) return; if (_spawnedRewardButton) { SetStatus("Reward item has already been created."); return; } var buttonObject = new GameObject("RuntimeRewardButton", typeof(RectTransform), typeof(Image), typeof(Button), typeof(LayoutElement), typeof(ShrinkTutorialAnchor)); var rectTransform = buttonObject.GetComponent(); rectTransform.SetParent(rewardContainer, false); rectTransform.anchorMin = new Vector2(0f, 0.5f); rectTransform.anchorMax = new Vector2(1f, 0.5f); rectTransform.pivot = new Vector2(0.5f, 0.5f); rectTransform.offsetMin = new Vector2(0f, 0f); rectTransform.offsetMax = new Vector2(0f, 0f); rectTransform.sizeDelta = new Vector2(0f, 58f); var image = buttonObject.GetComponent(); image.color = new Color(0.18f, 0.48f, 0.28f, 1f); var button = buttonObject.GetComponent