ºÇ½ª¹¹¿·¡§ orika_ex_miyako 2024ǯ03·î01Æü(¶â) 10:47:12ÍúÎò
ScrollView ¤ò»ý¤Ä¥³¥ó¥Ý¡¼¥Í¥ó¥È¤¬ LayoutGroup Æâ¤Ë´Þ¤Þ¤ì¤Æ¤¤¤ë¾ì¹ç¤Ë¡¢³ÆUI ÍÑ¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¤Î°ÌÃÖ¤òưŪ¤Ë¼«Æ°Ä´À°¤¹¤ëÊýË¡¤Î¼ÂÁõÎã¤Ç¤¹¡£
¡¡Á°²ó¤Ë°ú¤Â³¤¡¢¤³¤Á¤é¤Ç¤Ï¥¹¥¯¥ê¥×¥È¤òºîÀ®¤·¤Æ´°À®¤µ¤»¤Þ¤¹¡£
Æ°²è¥Õ¥¡¥¤¥ë¤Ø¤Î¥ê¥ó¥¯
¡¡¤Ê¤ª¡£LayoutGroup Æâ¤Ë Slider ¤ä ScrollView ¤Ê¤É¤Î»Ò¥ª¥Ö¥¸¥§¥¯¥È¤òÊ£¿ô»ý¤Ä UI ¤¬´Þ¤Þ¤ì¤Æ¤¤¤Ê¤¤¾ì¹ç¤Ë¤Ï¡¢²¼µ¤Îµ»ö¤ò»²¹Í¤Ë¤¹¤ë¤³¤È¤Çµ¡Ç½¼ÂÁõ¤Ç¤¤Þ¤¹¡£
¡Ú¥Ï¥ë¥·¥ª¥ó¥Ö¥í¥°¡ÛÍÍ
Layout¥°¥ë¡¼¥×¤ÎÃæ¤Ç¡¢¤Û¤«¤Î¥ª¥Ö¥¸¥§¥¯¥È¤Î¥µ¥¤¥º¤¬ÊѤï¤Ã¤¿¤È¤¤Ë¼«Æ°¤Ç¾¤Î¥ª¥Ö¥¸¥§¥¯¥È¤Î°ÌÃÖ¤òÄ´À°¤¹¤ëÊýË¡
http://halcyonsystemblog.jp/blog-entry-1045.html
¡¡¥¹¥¯¥ê¥×¥¿¥Ö¥ë¡¦¥ª¥Ö¥¸¥§¥¯¥È¡¢¥¯¥é¥¹¤Î·Ñ¾µ¡¢UniRx ¤òÍøÍѤ·¤¿¹ØÆɽèÍý¤¬´Þ¤Þ¤ì¤Æ¤¤¤Þ¤¹¡£
¤³¤Á¤é¤Î³Ø½¬¼«ÂΤϴޤޤì¤Æ¤¤¤Þ¤»¤ó¤Î¤Ç¡¢¤³¤ì¤é¤Î³µÇ°¤äµ¡Ç½¤òÍý²ò¤·¤Æ¤¤¤ëÊý¤òÂоݤȤ·¤Æ¤¤¤Þ¤¹¡£
¡¡Unity ¤Ç¤Ï UI ¤Î¼«Æ°À°Îóµ¡Ç½¤È¤·¤Æ LayoutGroup ¤¬¤¢¤ê¤Þ¤¹¡£
Î㤨¤Ð¡¢Image ¤È Text ¤ò²£°ìÎó¤Ëɽ¼¨¤µ¤»¡¢¤½¤Î¸å¡¢Text ¤ä Image ¤Î²£¥µ¥¤¥º¤ÎÊѹ¹¤Ë±þ¤¸¤Æ
³Æ¥ª¥Ö¥¸¥§¥¯¥È¤Î°ÌÃÖ¤ò¼«Æ°Ä´À°¤¹¤ë¡¢¤È¤¤¤¦¤è¤¦¤Ê»È¤¤Êý¤Ç¤¹¡£
¡¡¤³¤ì¤Ï LayoutGroup ¤ò¥¢¥¿¥Ã¥Á¤·¤¿¤À¤±¤Ç¤Ï¼ÂÁõ¤¬¹Ô¤¨¤Þ¤»¤ó¡£
LayoutGroup ¤ÎÀßÄê¤Î¤Û¤«¡¢À©¸æ²¼¤È¤Ê¤ë³Æ»Ò¥ª¥Ö¥¸¥§¥¯¥È¤Ë¤âÀßÄ꤬ɬÍפȤʤê¤Þ¤¹¡£
¡¡¤³¤³¤Ç¤Ï»²¹ÍÍÑ¤Ë UI ¤òºîÀ®¤·¡¢¤«¤Ä¡¢¤½¤ì¤òưŪ¤ËÊѲ½¤µ¤»¤ë¥µ¥ó¥×¥ë¤Î¥¹¥¯¥ê¥×¥È¤òÍÑ°Õ¤·¤ÆÆ°ºî¸¡¾Ú¤ò¹Ô¤¤¤Þ¤¹¡£
¡¡Æä˽ÅÍפÊÅÀ¤¬»Ò¥ª¥Ö¥¸¥§¥¯¥È¤òÊ£¿ô»ý¤Ä UI ¥ª¥Ö¥¸¥§¥¯¥È¤¬ LayoutGroup Æâ¤Ë´Þ¤Þ¤ì¤Æ¤¤¤ë¾ì¹ç¤ÎµóÆ°¤Ç¤¹¡£
ScrollView ¤Ë¤Ï»Ò¥ª¥Ö¥¸¥§¥¯¥È¤¬¤¢¤ê¡¢¤½¤ì¤é¤Î³Æ¥µ¥¤¥º¤ÎÄ´À°¤âɬÍפˤʤê¤Þ¤¹¡£
¡¡¥Ý¥Ã¥×¥¢¥Ã¥×¤ÎÀ©¸æ¤ò¹Ô¤¤¡¢UpgradeElement ¥×¥ì¥Ï¥Ö¤ò»ØÄꤷ¤¿°ÌÃÖ¤ËÀ¸À®¤¹¤ë¤¿¤á¤Î¥¹¥¯¥ê¥×¥È¤Ç¤¹¡£
PopupBase ¤ò·Ñ¾µ¤·¤Æ¤¤¤Þ¤¹¡£
¡¡Setup ¥á¥½¥Ã¥É¤Ï³°Éô¥¯¥é¥¹¤«¤é¼Â¹Ô¤¹¤ëÁÛÄê¤Ç¤¹¤¬¡¢¥Ç¥Ð¥Ã¥°¤¹¤ë¾ì¹ç¤Ë¤Ï¡¢ÊÌÅÓ Start ¥á¥½¥Ã¥É¤òÍÑ°Õ¤·¤Æ¼Â¹Ô¤·¤Æ³Îǧ¤ò¤ª¤³¤Ê¤Ã¤Æ¤¯¤À¤µ¤¤¡£
UpgradePop.cs
¡¡¥²¡¼¥à¤ò¼Â¹Ô¤·¡¢Content ¤Î¥µ¥¤¥º¤¬³Æ ElementPlace Æâ¤ËÀ¸À®¤µ¤ì¤¿¥×¥ì¥Ï¥Ö¤Î¿ô¤Ë±þ¤¸¤ÆÊѹ¹¤È¤Ê¤ê¡¢
¤«¤Ä¡¢ScrollView ¤Î VerticalLayoutGroup Æâ¤Î°ÌÃÖ¤¬¼«Æ°¤Ç¹¹¿·¤µ¤ì¤Æ¡¢¼êÆ°¤ÇÀßÄꤷ¤¿¾ì¹ç¤ÈƱ¤¸µóÆ°¤Ë¤Ê¤Ã¤Æ¤¤¤ì¤ÐÀ©¸æÀ®¸ù¤Ç¤¹¡£
¡¡½èÍý¤Î¥Ý¥¤¥ó¥È¤Ï UpdragePop Æâ¤Î°Ê²¼¤ÎÉôʬ¤Ç¤¹¡£
¤¦¤Þ¤¯¤¤¤«¤Ê¤¤¾ì¹ç¤Î½èÍý¤âÊ»¤»¤Æ½ñ¤¤¤Æ¤¢¤ê¤Þ¤¹¤Î¤Ç¡¢¤É¤Á¤é¤â»î¤·¤Æ¤ß¤Æ¤¯¤À¤µ¤¤¡£
/// <summary> /// ½é´üÀßÄê /// </summary> public override void SetUp() { base.SetUp(); txtPurpleGemCount.text = GameData.instance.PurpleGemCount.ToString(); txtGoldGemCount.text = GameData.instance.GoldGemCount.ToString(); txtDiamondGemCount.text = GameData.instance.DiamondGemCount.ToString(); txtRubyGemCount.text = GameData.instance.RubyGemCount.ToString(); // ³Æ¥¸¥§¥à¤Î¹ØÆɽèÍý GameData.instance.PurpleGemCount .Subscribe(value => txtPurpleGemCount.text = Mathf.Clamp(value, 0, int.MaxValue).ToString()) .AddTo(this); GameData.instance.GoldGemCount .Subscribe(value => txtGoldGemCount.text = Mathf.Clamp(value, 0, int.MaxValue).ToString()) .AddTo(this); GameData.instance.DiamondGemCount .Subscribe(value => txtDiamondGemCount.text = Mathf.Clamp(value, 0, int.MaxValue).ToString()) .AddTo(this); GameData.instance.RubyGemCount .Subscribe(value => txtRubyGemCount.text = Mathf.Clamp(value, 0, int.MaxValue).ToString()) .AddTo(this); // ¥²¡¼¥à¼Â¹ÔÃæ¤Ë¥¹¥¯¥ê¥×¥È¤«¤éLayoutGroupÆâ¤Ë»Ò¥ª¥Ö¥¸¥§¥¯¥È¤òÀ¸À®¤·¤ÆScrollViewÆâ¤Î¥µ¥¤¥º¤¬²ÄÊѤ¹¤ë¤ÈÀµ¤·¤¯É½¼¨¤µ¤ì¤Ê¤¤¤Î¤Ç¡¢°Ê²¼¤Î1¡¢2¡¢3¤Ç½¤Àµ (¤³¤ì¤ÏCanvas¤Î²èÌÌɽ¼¨¹¹¿·¤Î¥¿¥¤¥ß¥ó¥°¤ÈLayoutGroupÆâ¤Î¥µ¥¤¥ºÊѹ¹¤Î¥¿¥¤¥ß¥ó¥°¤¬¤º¤ì¤Æ¤¤¤ë¤¿¤á¤ËÀ¸¤¸¤ë) //Canvas.ForceUpdateCanvases(); // 1.CanvasÆâ¤Îɽ¼¨¹¹¿· // ¥¢¥Ã¥×¥°¥ì¡¼¥ÉÍ×ÁǤÎÀ¸À®¡£¼ïÎऴ¤È¤ËŬÀڤʾì½ê¤ËÀ¸À®¤¹¤ë foreach (var data in upgradeDataSO.upgradeDataList) { Canvas.ForceUpdateCanvases(); // 1 switch (data.gemType) { case GemType.Purple: var purpleElement = Instantiate(upgradeElementPrefab, purpleElementTran); purpleElement.SetUp(data); break; case GemType.Gold: var goldElement = Instantiate(upgradeElementPrefab, goldElementTran); goldElement.SetUp(data); break; case GemType.Diamond: var diamondElement = Instantiate(upgradeElementPrefab, diamondElementTran); diamondElement.SetUp(data); break; case GemType.Ruby: var rubyElement = Instantiate(upgradeElementPrefab, rubyElementTran); rubyElement.SetUp(data); break; default: Debug.Log("³ºÅö¤Î¥¢¥Ã¥×¥°¥ì¡¼¥ÉÍ×ÁǤ¬¸«¤Ä¤«¤ê¤Þ¤»¤ó"); break; } verticalLayoutGroup.CalculateLayoutInputVertical(); // 2 verticalLayoutGroup.SetLayoutVertical(); // 3 } // 2.LayoutGroupÆâ¤ÎÆþÎÏÃͤòºÆ·×»» //verticalLayoutGroup.CalculateLayoutInputVertical(); // 3.¥ì¥¤¥¢¥¦¥ÈºÆÀßÄê(ɽ¼¨¹¹¿·) //verticalLayoutGroup.SetLayoutVertical(); }
¡¡¡¤Þ¤ººÇ½é¤Ë Canvas.ForceUpdateCanvases()¤¬¸Æ¤Ó½Ð¤µ¤ì¡¢¥¥ã¥ó¥Ð¥¹¤È¤½¤Î»ÒÍ×ÁǤ¬¹¹¿·¤µ¤ì¤Þ¤¹¡£
Ä̾ï Canvas Æâ¤Î¥ª¥Ö¥¸¥§¥¯¥È¤Îɽ¼¨¹¹¿·¤Ï 1¥Õ¥ì¡¼¥à¤Þ¤¿¤°É¬Íפ¬¤¢¤ê¤Þ¤¹¤¬¡¢¤³¤Î¥á¥½¥Ã¥É¤ò¼Â¹Ô¤¹¤ë¤³¤È¤Ç¨ºÂ¤Ë¹¹¿·¤µ¤ì¤Þ¤¹¡£
¡¡¢verticalLayoutGroup.CalculateLayoutInputVertical()¤¬¸Æ¤Ó½Ð¤µ¤ì¡¢¿âľÊý¸þ¤Î¥ì¥¤¥¢¥¦¥È¤ÎÆþÎϤ¬ºÆ·×»»¤µ¤ì¤Þ¤¹¡£
¤³¤ì¤Ë¤è¤ê¡¢VerticalLayoutGroup Æâ¤Î¥ª¥Ö¥¸¥§¥¯¥È¤Î¥µ¥¤¥º¤È¡¢¤½¤Î»Ò¥ª¥Ö¥¸¥§¥¯¥È¤Î¥µ¥¤¥º¤¬ºÆ·×»»¤µ¤ì¤Þ¤¹¡£
¡¡£ºÇ¸å¤Ë verticalLayoutGroup.SetLayoutVertical()¤¬¸Æ¤Ó½Ð¤µ¤ì¡¢¿âľÊý¸þ¤Î¥ì¥¤¥¢¥¦¥È¤¬ºÆÀßÄꤵ¤ì¡¢UIÍ×ÁǤ¬ÉÁ²è¤µ¤ì¤ë¹¹¿·¤¬¹Ô¤ï¤ì¤Þ¤¹¡£
¡¡°Ê¾å¤Î½èÍý¤ÎÆâÍƤˤè¤ê¡¢¤³¤Î½ç½ø¤Ç½èÍý¤ò¹Ô¤¦¤³¤È¤Ç¡¢UIÍ×ÁǤΥµ¥¤¥ºÊѹ¹¤¬Àµ¾ï¤Ë²èÌ̤ËÈ¿±Ç¤µ¤ì¤ë¤è¤¦¤Ë¤Ê¤ê¤Þ¤¹¡£
¡¡ÆÃ¤Ë LayoutGroup ÍøÍÑ»þ¤Î ScrollView ¤Î¥µ¥¤¥ºÆ°Åª¤Ê¹¹¿·¤Ë¤ª¤¤¤Æ¤Ï¡¢¡¢£¤Î½èÍý¤È¡¢¤½¤Î¼Â¹Ô¤¹¤ë½çÈ֤Ⱦì½ê¤¬½ÅÍפǤ¹¡£
ScrollView ¤Ë¤Ï»Ò¥ª¥Ö¥¸¥§¥¯¥È¤¬¤¢¤ë¤¿¤á¡¢¤³¤Î½èÍý¤òŬÀڤʽçÈ֤Ǽ¹Ԥ¹¤ë¤³¤È¤Ë¤è¤ê¡¢LayoutGroup Æâ¤Î³Æ¥ª¥Ö¥¸¥§¥¯¥È¤Î°ÌÃÖ¤òưŪ¤Ë¼«Æ°Ä´À°¤¹¤ë¤³¤È¤¬²Äǽ¤Ç¤¹¡£
¡¡LayoutGroup Æâ¤Ë£±¤Ä¿·¤·¤¤¥ª¥Ö¥¸¥§¥¯¥È¤¬À¸À®¤µ¤ì¤ë¡¢¤È¤¤¤¦¤³¤È¤Ï¡¢¤½¤ÎÃæ¤Ë¤¢¤ë¤Û¤«¤Î¥ª¥Ö¥¸¥§¥¯¥È¤Î°ÌÃÖ¤¬ºÆ·×»»¤·¤Ê¤¤¤È¡¢¤É¤Î°ÌÃÖ¤ËÇÛÃÖ¤·¤Æ¤¤¤¤¤Î¤«¡¢¤ï¤«¤é¤Ê¤¤¾õÂ֤ˤʤê¤Þ¤¹¡£
¤½¤Î¤¿¤á¡¢²¿¤«£±¤Ä¤Ç¤âÊѲ½¤¬¤¢¤Ã¤¿¤é¡¢¤½¤ì¤Ë´ØÏ¢¤¹¤ë¤¹¤Ù¤Æ¤Î UI ¤¬¹¹¿·¤µ¤ì¤ëɬÍפ¬¤¢¤ê¤Þ¤¹¡£
¡¡Ä̾¤³¤Î¹¹¿·¤Î½èÍý¤Ë¤Ï 1¥Õ¥ì¡¼¥à¤«¤«¤ê¤Þ¤¹¡£
¤³¤ì¤Ï Canvas ¼«ÂΤλÅÍͤǡ¢²¿¤« UI ¤ËÊѹ¹¤¬¤¢¤Ã¤¿¤È¤¡Ê¥ª¥Ö¥¸¥§¥¯¥È¤¬Áý¸º¤·¤¿¡¢°ÌÃÖ¤¬ÊѤï¤Ã¤¿¡¢¥µ¥¤¥º¤¬ÊѤï¤Ã¤¿¤Ê¤É¡Ë¤¬ 1 ¥Õ¥ì¡¼¥à¸å¤Ë²èÌ̤ËÈ¿±Ç¤µ¤ì¤ë¤¿¤á¤Ç¤¹¡£
¡¡º£²ó¤Î½èÍý¤Ç¤¹¤¬¡¢LayoutGroup Æâ¤Ë¥ª¥Ö¥¸¥§¥¯¥È¤òºî¤Ã¤¿¤È¤·¤Æ¤â¡¢¤½¤Î¥¿¥¤¥ß¥ó¥°¤Ç¤Ï¡¢Canvas ¤Î¹¹¿·¤Ï¼«Æ°Åª¤Ë¤ÏÆþ¤ê¤Þ¤»¤ó¡£¤Ê¤¼¤Ê¤é¡¢À¸À®¤·¤Æ¤â 1 ¥Õ¥ì¡¼¥à·Ð²á¤·¤Ê¤¤¤¿¤á¤Ç¤¹¡£
¤È¤¤¤¦¤³¤È¤Ï¡¢¿·¤·¤¯Äɲ䵤줿¥ª¥Ö¥¸¥§¥¯¥È¤È¡¢°ÊÁ°¤«¤é¤¢¤Ã¤¿¥ª¥Ö¥¸¥§¥¯¥È¤Ï¡¢¤½¤Î°ÌÃÖ´Ø·¸¤¬¹¹¿·¤µ¤ì¤Ê¤¤¤Þ¤Þ²èÌ̤˱Ǥê¤Þ¤¹¡£
¡¡¤³¤Î¤È¤¡¢Slider ¤ä ScrollView ¤Î¤è¤¦¤Ê¡¢»Ò¥ª¥Ö¥¸¥§¥¯¥È¤òÊ£¿ô»ý¤Ä¥ª¥Ö¥¸¥§¥¯¥È¤Ë¤Ä¤¤¤Æ¤Ï¡¢Àµ¤·¤¤°ÌÃÖ¤¬È¿±Ç¤µ¤ì¤Ê¤¤¤Ç¥²¡¼¥à²èÌ̤¬ºî¤é¤ì¤Æ¤·¤Þ¤¤¤Þ¤¹¡£
¡¡¤è¤Ã¤Æ¡¢
£±¡¥LayoutGroup ¤òÍøÍѤ·¤Æ¤¤¤ë UI Æâ¤Ë²¿¤«¥ª¥Ö¥¸¥§¥¯¥È¤òºî¤ë £²¡¥LayoutGroup Æâ¤ÎºÆ·×»»¤ò¤·¤Ê¤¤¤È¡¢Àµ¤·¤¤°ÌÃ֤ˤʤé¤Ê¤¤ £³¡¥Àµ¤·¤¤°ÌÃ֤ˤʤ俤顢¤½¤ì¤òÀßÄꤷ¤Ê¤¤¤È²èÌ̤ËÈ¿±Ç¤µ¤ì¤Ê¤¤¡Ê¤³¤ì¤Ï Canvas ¤Î¹¹¿·¤ò´Þ¤ß¤Þ¤¹¡Ë
¡¡¤³¤Î¤è¤¦¤Êή¤ì¤¬À¸¤¸¤Þ¤¹¡£
¡¡ÆÃ¤Ë Slider ¤ä ScrollView ¤Î¤è¤¦¤Ê¡¢»Ò¥ª¥Ö¥¸¥§¥¯¥È¤ò»ý¤Ä¥ª¥Ö¥¸¥§¥¯¥È¤Î¾ì¹ç¡¢¥ª¥Ö¥¸¥§¥¯¥ÈÆâ¤Î¥ª¥Ö¥¸¥§¥¯¥È¤Î¿ô¤¬ÊѤï¤Ã¤Æ°ÌÃÖ¤¬ÊѤ¨¤ë¤´¤È¤ËºÆ·×»»¤ò¤·¤Æ²èÌ̤ι¹¿·¤ò¤½¤ÎÅÔÅÙ¤·¤Æ¤¢¤²¤Ê¤¤¤È¡¢
Î㤨¤Ð¡¢£³¤Ä¥ª¥Ö¥¸¥§¥¯¥È¤¬ºî¤é¤ì¤¿¤È¤·¤¿¤é¡¢¤½¤ÎÁ°¤Ë¤Ç¤¤Æ¤¤¤¿£²¤Ä¤Î¥ª¥Ö¥¸¥§¥¯¥È¤¬Àµ¤·¤¤°ÌÃ֤ˤʤäƤ¤¤Ê¤¤¤¿¤á¡¢·ë²Ì¡¢¤É¤ó¤É¤ó¤È¤º¤ì¤Æ¤¤¤¯¤è¤¦¤Ë¤Ê¤ê¤Þ¤¹¡£
- ¥«¥Æ¥´¥ê¡§
- ¿Ê³Ø/¥¹¥¯¡¼¥ë
- ¥×¥í¥°¥é¥ß¥ó¥°
¥³¥á¥ó¥È¤ò¤«¤¯