using UnityEngine; using UnityEngine.UI; using UVC.UI.Toolbar.Model; namespace UVC.UI.Toolbar.View { /// /// Ç¥ÁØ Åø¹Ù ¹öư(ToolbarStandardButton)ÀÇ UI »ý¼º, À̺¥Æ® ¿¬°á, ½Ã°¢Àû ¾÷µ¥ÀÌÆ®¸¦ ó¸®Çϴ Ŭ·¡½ºÀÔ´Ï´Ù. /// IButtonViewProcessor ÀÎÅÍÆäÀ̽º¸¦ ±¸ÇöÇÏ¿© ToolbarView°¡ Ç¥ÁØ ¹öưÀ» ÀϰüµÈ ¹æ½ÄÀ¸·Î ´Ù·ê ¼ö ÀÖµµ·Ï ÇÕ´Ï´Ù. /// /// /// ÀÌ Å¬·¡½ºÀÇ ÁÖ¿ä ¿ªÇÒ: /// 1. UI »ý¼º: ToolbarView¿¡ ¼³Á¤µÈ 'Ç¥ÁØ ¹öư ÇÁ¸®ÆÕ'À» »ç¿ëÇÏ¿© ¹öưÀÇ GameObject¸¦ ¸¸µì´Ï´Ù. /// 2. »óÈ£ÀÛ¿ë ¼³Á¤: »ý¼ºµÈ ¹öư UI(UnityEngine.UI.Button)°¡ Ŭ¸¯µÇ¾úÀ» ¶§, /// ¿¬°áµÈ ToolbarStandardButton ¸ðµ¨ÀÇ ExecuteClick ¸Þ¼­µå°¡ È£ÃâµÇµµ·Ï ¼³Á¤ÇÕ´Ï´Ù. /// 3. ½Ã°¢Àû ¾÷µ¥ÀÌÆ®: ¹öư ¸ðµ¨ÀÇ »óÅÂ(ÅØ½ºÆ®, ¾ÆÀÌÄÜ, Ȱ¼ºÈ­ »óÅ µî)°¡ º¯°æµÇ¸é, /// È­¸é¿¡ º¸ÀÌ´Â ¹öưÀÇ ¸ð½Àµµ ±×¿¡ ¸Â°Ô ¾÷µ¥ÀÌÆ®ÇÕ´Ï´Ù. /// /// /// /// // ToolbarView ³»¿¡¼­ ÀÌ ÇÁ·Î¼¼¼­°¡ »ç¿ëµÇ´Â ¹æ½Ä (°£·«È­µÈ ¿¹½Ã): /// // 1. ToolbarModel·ÎºÎÅÍ ToolbarStandardButton °´Ã¼¸¦ °¡Á®¿É´Ï´Ù. /// // ToolbarStandardButton standardButtonModel = new ToolbarStandardButton { Text = "Save", ... }; /// /// // 2. ToolbarView´Â ÇØ´ç ¸ðµ¨ ŸÀÔ¿¡ ¸Â´Â Processor¸¦ ã½À´Ï´Ù. /// // IButtonViewProcessor processor = GetButtonViewProcessor(typeof(ToolbarStandardButton)); /// // (À̶§, ToolbarStandardButtonViewProcessor ÀνºÅϽº°¡ ¹ÝȯµË´Ï´Ù) /// /// // 3. UI »ý¼º ¿äû /// // GameObject buttonUI = processor.CreateButtonUI(standardButtonModel, toolbarContainer, this); /// /// // 4. »óÈ£ÀÛ¿ë ¹× Ãʱ⠽ð¢Àû ¿ä¼Ò ¼³Á¤ ¿äû /// // processor.SetupButtonInteractions(standardButtonModel, buttonUI, this); /// /// // 5. ¸ðµ¨ÀÇ »óŰ¡ º¯°æµÇ¸é(¿¹: standardButtonModel.Text = "Save As";) OnStateChanged À̺¥Æ®°¡ ¹ß»ýÇϰí, /// // ToolbarView´Â ´Ù½Ã processor.UpdateCommonButtonVisuals()¸¦ È£ÃâÇÏ¿© UI¸¦ ¾÷µ¥ÀÌÆ®ÇÕ´Ï´Ù. /// // standardButtonModel.OnStateChanged += () => processor.UpdateCommonButtonVisuals(standardButtonModel, buttonUI, this); /// /// public class ToolbarStandardButtonViewProcessor : IButtonViewProcessor { /// /// ToolbarStandardButton ¸ðµ¨¿¡ ÇØ´çÇÏ´Â UI GameObject¸¦ »ý¼ºÇÕ´Ï´Ù. /// ToolbarView¿¡ ÀÖ´Â standardButtonPrefabÀ» º¹Á¦ÇÏ¿© »ç¿ëÇÕ´Ï´Ù. /// /// UI¸¦ »ý¼ºÇÒ ±â¹ÝÀÌ µÇ´Â ¹öư µ¥ÀÌÅÍ ¸ðµ¨ (ToolbarButtonBase ŸÀÔÀÌÁö¸¸, ½ÇÁ¦·Î´Â ToolbarStandardButtonÀ¸·Î °£ÁÖµÊ). /// »ý¼ºµÈ ¹öư UI°¡ ÀÚ½ÄÀ¸·Î Ãß°¡µÉ ºÎ¸ð Transform °´Ã¼ÀÔ´Ï´Ù. /// ÇöÀç ToolbarViewÀÇ ÀνºÅϽº. ÇÁ¸®ÆÕ ÂüÁ¶³ª ´Ù¸¥ ºä °ü·Ã ±â´É¿¡ Á¢±ÙÇÒ ¶§ »ç¿ëµË´Ï´Ù. /// ¼º°øÀûÀ¸·Î »ý¼ºµÈ ¹öưÀÇ GameObject. ÇÁ¸®ÆÕÀÌ ¾øÀ¸¸é nullÀ» ¹ÝȯÇÕ´Ï´Ù. public GameObject CreateButtonUI(ToolbarButtonBase buttonModel, Transform parentContainer, ToolbarView viewContext) { if (viewContext.standardButtonPrefab == null) { Debug.LogError("StandardButtonViewProcessor: standardButtonPrefabÀÌ ToolbarView¿¡ ÇÒ´çµÇÁö ¾Ê¾Ò½À´Ï´Ù.", viewContext); return null; } // standardButtonPrefabÀ» º¹Á¦ÇÏ¿© »õ·Î¿î ¹öư UI GameObject¸¦ ¸¸µì´Ï´Ù. // parentContainerÀÇ ÀÚ½ÄÀ¸·Î »ý¼ºµÇ¾î Åø¹Ù ·¹À̾ƿô¿¡ Æ÷ÇԵ˴ϴÙ. return Object.Instantiate(viewContext.standardButtonPrefab, parentContainer); } /// /// »ý¼ºµÈ Ç¥ÁØ ¹öư UI GameObject¿¡ ÇÊ¿äÇÑ »óÈ£ÀÛ¿ëÀ» ¼³Á¤Çϰí Ãʱ⠽ð¢Àû »óŸ¦ ¾÷µ¥ÀÌÆ®ÇÕ´Ï´Ù. /// - UI ¹öư Ŭ¸¯ ½Ã ¸ðµ¨ÀÇ ExecuteClick ¸Þ¼­µå È£Ãâ ¼³Á¤ /// - ¸ðµ¨ÀÇ Ãʱâ ÅØ½ºÆ®, ¾ÆÀÌÄÜ, Ȱ¼ºÈ­ »óŸ¦ UI¿¡ ¹Ý¿µ /// /// ¼³Á¤ ´ë»ó ¹öưÀÇ µ¥ÀÌÅÍ ¸ðµ¨ (ToolbarStandardButtonÀ¸·Î ij½ºÆÃÇÏ¿© »ç¿ë). /// È­¸é¿¡ Ç¥½ÃµÈ, ¼³Á¤ÇÒ ¹öưÀÇ UI GameObject. /// ÇöÀç ToolbarViewÀÇ ÀνºÅϽº. public void SetupButtonInteractions(ToolbarButtonBase buttonModel, GameObject buttonUIObject, ToolbarView viewContext) { // buttonModelÀ» ½ÇÁ¦ ŸÀÔÀÎ ToolbarStandardButtonÀ¸·Î º¯È¯ÇÕ´Ï´Ù. ToolbarStandardButton standardModel = buttonModel as ToolbarStandardButton; if (standardModel == null) return; // ¹öư UI GameObject¿¡¼­ UnityEngine.UI.Button ÄÄÆ÷³ÍÆ®¸¦ °¡Á®¿É´Ï´Ù. Button uiButton = buttonUIObject.GetComponent