Unity UGUI(九)Dropdown(下拉列表框)

Dropdown(Script)

   

Interactable可交互是否可点击
Transition过渡
  • None:无
  • Color Tint:颜色色彩
    • Target Graphic:目标图形
    • Normal Color:正常颜色
    • Highlighted Color:高亮颜色
    • Pressed Color:按下颜色
    • Selected Color:选择颜色
    • Disabled Color:已禁用颜色
    • Color Multiplier:色彩乘数
    • Fade Duration:淡化持续时间
  • Sprite Swap:精灵交换
    • Target Graphic:目标图形
    • Highlighted Sprite:高亮精灵
    • Pressed Sprite:按下精灵
    • Selected Sprite:选择精灵
    • Disabled Sprite:已禁用精灵
  • Animation:动画
    • Normal Trigger:正常触发
    • Highlighted Trigger:高亮触发
    • Pressed Trigger:按下触发
    • Selected Trigger:选择触发
    • Disabled Trigger:引禁用触发
    • Auto Generate Animation 自动生成动画
Navigation导航
  • None:无
  • Horizontal:水平
  • Vertical:垂直
  • Automatic:自动
  • Explicit:显式
    • Select On Up:向上选择
    • Select On Down:向下选择
    • Select On Left:向左选择
    • Select On Right:向右选择
  • Visualize:可视化,把按键能够导航到的路径可视化,高亮的黄色箭头为当前按钮可导航到的目标
Template模板下拉使用的模板样式
Caption Text标题文本当前选择的显示文本
Caption Image标题图像当前选择的显示图片
Item Text项文本下拉框选项模板里的文字,不填会导致选项列表中的每个选项不会修改模板里的文字
Item Image项图像下拉框选项模板里的图片,不填会导致选项列表中的每个选项不会修改模板里的图片
Value当前选择的值(0开始)
Options选项可选择项
On Value Changed(Int32)值改变时(32位整数)值调整时触发的事件

自带Dropdown

Dropdown:图片,带Dropdown组件,作为选中框的底图。

Label:文本,作为标题文本,当前显示的文本。

Arrow:图片,作为下拉按钮。

运行时:

绑定事件

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class TestUI : MonoBehaviour
{
    Dropdown dropdown;
    void Start()
    {
        dropdown = GameObject.Find("Canvas/Dropdown").GetComponent<Dropdown>();
    }

    public void GetValue(int i)
    {
        switch (i)
        {
            case 0: Debug.Log("Option A"); break;
            case 1: Debug.Log("Option B"); break;
            case 2: Debug.Log("Option C"); break;
            case 3: Debug.Log("Option D"); break;
        }
    }
}

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class TesUI : MonoBehaviour
{

    public string[] showText;
    public Sprite[] sprite;
    Dropdown dropDownItem;
    List<string> temoNames;
    List<Sprite> sprite_list;
    void Start()
    {
        dropDownItem = this.GetComponent<Dropdown>();
        temoNames = new List<string>();
        sprite_list = new List<Sprite>();

        AddNames();
        UpdateDropDownItem(temoNames);
    }

    void UpdateDropDownItem(List<string> showNames)
    {
        dropDownItem.options.Clear();
        Dropdown.OptionData temoData;
        for (int i = 0; i < showNames.Count; i++)
        {
            temoData = new Dropdown.OptionData();
            temoData.text = showNames[i];
            temoData.image = sprite_list[i];
            dropDownItem.options.Add(temoData);
        }
        dropDownItem.captionText.text = showNames[0];
    }

    void AddNames()
    {
        for (int i = 0; i < showText.Length; i++)
        {
            temoNames.Add(showText[i]);
        }
        for (int i = 0; i < sprite.Length; i++)
        {
            sprite_list.Add(sprite[i]);
        }
    }
}

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值