您好,登錄后才能下訂單哦!
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){} ? } } ?
Unity3D簡單的音樂播放器【代碼】
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。