NGUI (七)获得文件名且加到PopupList里

本文由 @EGWriket出品,转载请注明出处。
http://blog.csdn.net/egwriket

环境

软件:untiy5.0.2f1
插件:NGUI3.6.7

步骤

1.UI及资源放置

1.UI
需要一个PopupList的控件,NGUI→Open,直接从Prefab Toolbar拖一个出来就好了
2.把视频放在Project面板中的Resources文件夹(不一定要叫这个名,要用Resources.Load方法加载的话就用这个名),以图片为例
这里写图片描述

2.代码及绑定

using UnityEngine;
using System.Collections;
using System.IO;
using System.Collections.Generic;

public class PanelManager : MonoBehaviour {

    public UIPanel panel;

    //下拉框
    public UIPopupList popListPicture;
    string path="Evaluation/swallow/Picture(到文件夹为止)";

    //获得图片资源
    public void SelectBirdPictureFile()
    {
        //获取指定路径下面的所有资源文件  
        if (Directory.Exists(path))
        {
            DirectoryInfo direction = new DirectoryInfo(path);
            //搜索当前目录
            FileInfo[] files = direction.GetFiles("*", SearchOption.AllDirectories);
            //文件数量files.Length;
            for (int i = 0; i < files.Length; i++)
            {
                if (files[i].Name.EndsWith(".meta"))
                {
                    continue;
                }
                Debug.Log("Name:" + files[i].Name);
                //添加到UIPopupList里
                popListPicture.items.Add(files[i].Name);
                //Debug.Log( "FullName:" + files[i].FullName );  
                //Debug.Log( "DirectoryName:" + files[i].DirectoryName );  
            }
        }
    }
}

1.Hierarchy面板选中UIRoot(可选其他),把代码绑定
2.Hierarchy面板选中Texture,拖入脚本中的未定义的控件变量PopList绑定
这里写图片描述
3.Hierarchy面板选中PopulList,选择On Value Change
6把UIRoot拖进Notify,method选择PanelManager/SelectBirdPictureFile
这里写图片描述

3.运行

这里写图片描述

感觉项目做不完了……

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值