using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class DropdownDirectionExample : MonoBehaviour
{
public Dropdown dropdownContent;
/// <summary>
/// 展开状态true:向上,false:向下
/// </summary>
public bool mIsUnfoldState = false;
void Start()
{
if (mIsUnfoldState)
{
SetDownUnfold();
}
else
{
SetUpUnfold();
}
}
/// <summary>
/// 向上展开
/// </summary>
private void SetUpUnfold()
{
dropdownContent.template.GetComponent<RectTransform>().pivot = new Vector2(0.5f, 0);
dropdownContent.template.GetComponent<RectTransform>().anchorMin = new Vector2(0, 1);
dropdownContent.template.GetComponent<RectTransform>().anchorMax = Vector2.one;
dropdownContent.template.GetComponent<RectTransform>().anchoredPosition = Vector3.zero;
}
/// <summary>
/// 向下展开
/// </summary>
private void SetDownUnfold()
{
dropdownContent.template.GetComponent<RectTransform>().pivot = new Vector2(0.5f, 1);
dropdownContent.template.GetComponent<RectTransform>().anchorMin = Vector2.zero;
dropdownContent.template.GetComponent<RectTransform>().anchorMax = new Vector2(1, 0);
dropdownContent.template.GetComponent<RectTransform>().anchoredPosition = Vector3.zero;
}
}
Unity UGUI设置下拉框默认向上展开
最新推荐文章于 2024-05-02 23:00:56 发布