本文由 @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.运行
感觉项目做不完了……