- 最后登录
- 2016-8-29
- 注册时间
- 2012-8-25
- 阅读权限
- 90
- 积分
- 23585
- 纳金币
- 20645
- 精华
- 62
|
- import System.IO;
- import System.Collections;
- import System.Text;
- var www : WWW;
- var file:ArrayList;
- var scrollPosition :Vector2= Vector2.zero;
- var scrollVelocity:float = 0f;
- var timeTouchPhaseEnded:float = 0f;
- var inertiaDuration:float = 0.5f;
- var lastDeltaPos:Vector2 ;
- var skin:GUISkin;
- ?
- function Start () {
- file=new ArrayList();
- he("C:\\","*.mp3",file);
- } <!--DVFMTSC-->
- ?
- var play:Texture;
- var pause:Texture;
- var next:Texture;
- var last:Texture;
- var sound:Texture;
- ?
- function OnGUI(){
- GUI.skin=skin;
- var y:int=0;
- scrollPosition = GUI.BeginScrollView( Rect(0, 0, Screen.width, Screen.height), scrollPosition, Rect(0, 0,Screen.width, file.Count*60), false, false);
- //unity3d教程:www.unitymanual.com
- for(var f:String in file){
- //把系统编码转成utf-8,因为android上是utf-8
- var utf:Encoding =Encoding.UTF8;//utf-8
- var gb:Encoding =Encoding.Default;//系统的编码
- var temp:byte[] = gb.GetBytes(f);
- var temp1:byte[] = Encoding.Convert(gb, utf, temp);
- var f1:String=utf.GetString(temp1);
- ?
- //用lastindexof和substring方法获取文件名(不包括路径)
- var p:int=f1.LastIndexOf('\\',f1.Length-1); //必须是'\\',如果是‘\’会报错的。如果是手机要写‘/’
- var f2:String=f1.Substring(p+1,f1.Length-1-p);
- var b=GUI.Button(Rect(0,y,Screen.width,60)," "+f2);
- ?
- if(b){
- www=new WWW("file://"+f); //记住这里面的“//”别写成“\\”就行哈;
- audio.clip=www.audioClip;
- }
- y+=60;
- }
- GUI.EndScrollView();
- ?
- }
- ?
- ?
- function Update (){
- if(Input.touchCount > 0){
- if(Input.GetTouch(0).phase == TouchPhase.Moved){
- scrollPosition.y += Input.GetTouch(0).deltaPosition.y;
- lastDeltaPos = Input.GetTouch(0).deltaPosition;
- }
- else if (Input.GetTouch(0).phase == TouchPhase.Ended){
- print ("End:"+lastDeltaPos.y+"|"+Input.GetTouch(0).deltaTime);
- if(Mathf.Abs(lastDeltaPos.y)> 20.0f){
- scrollVelocity = lastDeltaPos.y * 0.5/ Input.GetTouch(0).deltaTime;
- print(scrollVelocity);
- }
- timeTouchPhaseEnded = Time.time;
- }
- ?
- }
- ?
- else{
- if(scrollVelocity != 0.0f){
- var t:float = (Time.time - timeTouchPhaseEnded)/inertiaDuration;
- var frameVelocity:float = Mathf.Lerp(scrollVelocity, 0, t);
- scrollPosition.y += frameVelocity * Time.deltaTime;
- if (t >= inertiaDuration)
- scrollVelocity = 0;
- }
- ?
- }
- if(Input.GetKey(KeyCode.Escape)){
- Application.Quit();
- }
- if(!audio.isPlaying)
- audio.Play();
- }
- ?
- function he(path:String,pattern:String,al:ArrayList){
- if(path!=null){
- var f1:String[]=Directory.GetFiles(path,pattern);
- var d1:String[];
- for(var f11:String in f1){
- al.Add(f11);
- }
- try{
- d1=Directory.GetDirectories(path);
- for(var d11:String in d1){
- try{ he(d11,pattern,al);}
- catch(Exception){}
- }
- }catch(Exception){}
- ?
- }
- }
- ?
复制代码 |
|