国产亚洲精品福利在线无卡一,国产精久久一区二区三区,亚洲精品无码国模,精品久久久久久无码专区不卡

當前位置: 首頁 > news >正文

免費發(fā)布招聘的網(wǎng)站愛站seo

免費發(fā)布招聘的網(wǎng)站,愛站seo,長寧區(qū)網(wǎng)站建設(shè)公,做網(wǎng)站需要相機嗎Horizontal Layout Group | Unity UI | 1.0.0 1. 什么是HorizontalLayoutGroup組件? HorizontalLayoutGroup是Unity UGUI中的一種布局組件,用于在水平方向上對子物體進行排列和布局。它可以根據(jù)一定的規(guī)則自動調(diào)整子物體的位置和大小,使它們…

Horizontal Layout Group | Unity UI | 1.0.0

1. 什么是HorizontalLayoutGroup組件?

HorizontalLayoutGroup是Unity UGUI中的一種布局組件,用于在水平方向上對子物體進行排列和布局。它可以根據(jù)一定的規(guī)則自動調(diào)整子物體的位置和大小,使它們在水平方向上均勻分布。

Property:Function:
PaddingThe padding inside the edges of the layout group.
SpacingThe spacing between the layout elements.
Child AlignmentThe alignment to use for the child layout elements if they don't fill out all the available space.
Control Child SizeWhether the Layout Group controls the width and height of its child layout elements.
Use Child ScaleWhether the Layout Group considers the scale of its child layout elements when sizing and laying out elements.

Width?and?Height?correspond to the?Scale > X?and?Scale > Y?values in each child layout element's?Rect Transform?component.

You cannot animate the Scale values using the?Animator Controller
Child Force ExpandWhether to force the child layout elements to expand to fill additional available space.

2. HorizontalLayoutGroup的工作原理

HorizontalLayoutGroup組件通過以下步驟實現(xiàn)水平布局:

  • 獲取所有子物體的RectTransform組件。
  • 根據(jù)子物體的大小和布局規(guī)則,計算出每個子物體的位置和大小。
  • 調(diào)整子物體的位置和大小,使它們在水平方向上均勻分布。

3. HorizontalLayoutGroup的常用屬性

  • Spacing:子物體之間的間距。
  • ChildForceExpandWidth:是否強制子物體擴展寬度以填充整個水平布局。
  • ChildForceExpandHeight:是否強制子物體擴展高度以填充整個水平布局。
  • ChildControlWidth:是否控制子物體的寬度。
  • ChildControlHeight:是否控制子物體的高度。

4. HorizontalLayoutGroup的常用函數(shù)

  • CalculateLayoutInputHorizontal():計算水平布局的輸入。
  • CalculateLayoutInputVertical():計算垂直布局的輸入。
  • SetLayoutHorizontal():設(shè)置水平布局。
  • SetLayoutVertical():設(shè)置垂直布局。

5. 例子代碼

例子1:創(chuàng)建一個水平布局,并添加三個子物體

using UnityEngine;
using UnityEngine.UI;public class Example : MonoBehaviour
{public HorizontalLayoutGroup layoutGroup;public GameObject childPrefab;void Start(){for (int i = 0; i < 3; i++){GameObject child = Instantiate(childPrefab, layoutGroup.transform);child.GetComponent<Text>().text = "Child " + (i + 1);}}
}

操作步驟:

  1. 創(chuàng)建一個空物體,并添加HorizontalLayoutGroup組件。
  2. 創(chuàng)建一個子物體預(yù)制體,包含一個Text組件。
  3. 將子物體預(yù)制體拖拽到layoutGroup的Child Prefab屬性中。
  4. 運行游戲,可以看到三個子物體在水平方向上均勻分布。

例子2:設(shè)置子物體之間的間距

using UnityEngine;
using UnityEngine.UI;public class Example : MonoBehaviour
{public HorizontalLayoutGroup layoutGroup;public GameObject childPrefab;void Start(){layoutGroup.spacing = 20f;for (int i = 0; i < 3; i++){GameObject child = Instantiate(childPrefab, layoutGroup.transform);child.GetComponent<Text>().text = "Child " + (i + 1);}}
}

操作步驟:

  1. 創(chuàng)建一個空物體,并添加HorizontalLayoutGroup組件。
  2. 創(chuàng)建一個子物體預(yù)制體,包含一個Text組件。
  3. 將子物體預(yù)制體拖拽到layoutGroup的Child Prefab屬性中。
  4. 將layoutGroup的Spacing屬性設(shè)置為20。
  5. 運行游戲,可以看到子物體之間的間距變?yōu)?0。

例子3:強制子物體擴展寬度以填充整個水平布局

using UnityEngine;
using UnityEngine.UI;public class Example : MonoBehaviour
{public HorizontalLayoutGroup layoutGroup;public GameObject childPrefab;void Start(){layoutGroup.childForceExpandWidth = true;for (int i = 0; i < 3; i++){GameObject child = Instantiate(childPrefab, layoutGroup.transform);child.GetComponent<Text>().text = "Child " + (i + 1);}}
}

操作步驟:

  1. 創(chuàng)建一個空物體,并添加HorizontalLayoutGroup組件。
  2. 創(chuàng)建一個子物體預(yù)制體,包含一個Text組件。
  3. 將子物體預(yù)制體拖拽到layoutGroup的Child Prefab屬性中。
  4. 將layoutGroup的Child Force Expand Width屬性設(shè)置為true。
  5. 運行游戲,可以看到子物體的寬度被擴展以填充整個水平布局。

例子4:控制子物體的寬度和高度

using UnityEngine;
using UnityEngine.UI;public class Example : MonoBehaviour
{public HorizontalLayoutGroup layoutGroup;public GameObject childPrefab;void Start(){layoutGroup.childControlWidth = false;layoutGroup.childControlHeight = false;for (int i = 0; i < 3; i++){GameObject child = Instantiate(childPrefab, layoutGroup.transform);child.GetComponent<Text>().text = "Child " + (i + 1);}}
}

操作步驟:

  1. 創(chuàng)建一個空物體,并添加HorizontalLayoutGroup組件。
  2. 創(chuàng)建一個子物體預(yù)制體,包含一個Text組件。
  3. 將子物體預(yù)制體拖拽到layoutGroup的Child Prefab屬性中。
  4. 將layoutGroup的Child Control Width和Child Control Height屬性都設(shè)置為false。
  5. 運行游戲,可以看到子物體的寬度和高度不受控制,保持原始大小。

例子5:自定義布局規(guī)則

using UnityEngine;
using UnityEngine.UI;public class Example : MonoBehaviour
{public HorizontalLayoutGroup layoutGroup;public GameObject childPrefab;void Start(){layoutGroup.childAlignment = TextAnchor.MiddleCenter;for (int i = 0; i < 3; i++){GameObject child = Instantiate(childPrefab, layoutGroup.transform);child.GetComponent<Text>().text = "Child " + (i + 1);}}
}

操作步驟:

  1. 創(chuàng)建一個空物體,并添加HorizontalLayoutGroup組件。
  2. 創(chuàng)建一個子物體預(yù)制體,包含一個Text組件。
  3. 將子物體預(yù)制體拖拽到layoutGroup的Child Prefab屬性中。
  4. 將layoutGroup的Child Alignment屬性設(shè)置為Middle Center。
  5. 運行游戲,可以看到子物體在水平方向上居中對齊。

注意事項

  • HorizontalLayoutGroup組件只能用于水平布局,如果需要垂直布局,可以使用VerticalLayoutGroup組件。
  • 子物體的RectTransform組件的錨點和位置會影響布局效果,需要根據(jù)實際需求進行調(diào)整。

參考資料

  • Unity官方文檔 - HorizontalLayoutGroup



作者:AlianBlank
鏈接:https://www.jianshu.com/p/c5cdb16a7562
來源:簡書
著作權(quán)歸作者所有。商業(yè)轉(zhuǎn)載請聯(lián)系作者獲得授權(quán),非商業(yè)轉(zhuǎn)載請注明出處。

http://m.aloenet.com.cn/news/37299.html

相關(guān)文章:

  • html在wordpress中的作用刷關(guān)鍵詞優(yōu)化排名
  • 響應(yīng)式網(wǎng)站管理win7優(yōu)化軟件
  • 電子商務(wù)網(wǎng)站建設(shè)的一般步驟有重慶人力資源和社會保障網(wǎng)
  • wordpress的用戶名密碼網(wǎng)站優(yōu)化seo培
  • 郴州建設(shè)網(wǎng)站贛州網(wǎng)站seo
  • 杭州外貿(mào)網(wǎng)站制作網(wǎng)推資源渠道
  • 做網(wǎng)站用哪個office推廣普通話文字內(nèi)容
  • 類似WordPress的Pythonseo網(wǎng)站優(yōu)化工具大全
  • 附近做app的公司重慶seo論壇
  • 網(wǎng)站建設(shè)經(jīng)費立項報告網(wǎng)絡(luò)營銷發(fā)展方案策劃書
  • 那個網(wǎng)站可以做視頻app制作的企業(yè)網(wǎng)站建設(shè)方案模板
  • 網(wǎng)站要交錢嗎電腦培訓(xùn)學(xué)校哪家好
  • 手機微網(wǎng)站怎么做的網(wǎng)絡(luò)軟文營銷案例3篇
  • 西安網(wǎng)站建設(shè)公司云網(wǎng)北京網(wǎng)站優(yōu)化排名推廣
  • 張家港高端網(wǎng)站制作百度總部公司地址在哪里
  • 蘇州 網(wǎng)站 建設(shè) 公司微信營銷模式有哪些
  • 做企業(yè)網(wǎng)站比較好的公司互動營銷案例都有哪些
  • 建筑工程網(wǎng)站源碼市場營銷證書含金量
  • 天津高端品牌網(wǎng)站建設(shè)企業(yè)培訓(xùn)課程名稱大全
  • 網(wǎng)站開發(fā)畢業(yè)論文范文微博推廣方法有哪些
  • 自適應(yīng)網(wǎng)站什么做2022今天剛剛發(fā)生地震了
  • 哈爾濱住房和城鄉(xiāng)建設(shè)廳官方網(wǎng)站如何軟件網(wǎng)站優(yōu)化公司
  • wordpress 數(shù)據(jù)庫青島網(wǎng)站關(guān)鍵詞排名優(yōu)化
  • 政府網(wǎng)站建設(shè)情況調(diào)查表內(nèi)蒙古seo
  • 汽車app網(wǎng)站建設(shè)內(nèi)容企業(yè)推廣
  • h5長圖怎么做口碑優(yōu)化
  • windows系統(tǒng)做網(wǎng)站滄州網(wǎng)站建設(shè)優(yōu)化公司
  • html+jsp個人網(wǎng)站模板百度認證證書
  • 北京網(wǎng)站建設(shè)工作室百度的合作網(wǎng)站有哪些
  • 谷歌網(wǎng)站收錄入口seo優(yōu)化的常用手法