1
我想在Unity中創建一個媒體播放器,它從靜態文件夾中讀取所有媒體文件並播放所有媒體(圖像靜態持續時間,視頻長度視頻)。首先,我試圖讓它與圖像一起工作。Unity從媒體文件夾加載媒體和在RawImage上顯示
我對Unity非常陌生,對C#不太好。我能夠將所有媒體文件源(圖像)獲取到數組中,但接下來我需要將它們轉換爲紋理並放置在RawImage組件上。我堅持這部分。
如果我有src(例如C:\ medias \ img1.jpg)那麼我怎樣才能把它作爲一個圖像放在RawImage組件上?
我的代碼 - >
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEditor;
using System;
using System.IO;
using System.Linq;
public class Player : MonoBehaviour {
// Use this for initialization
void Start() {
DirectoryInfo dir = new DirectoryInfo(@"C:\medias");
string[] extensions = new[] { ".jpg", ".JPG", ".jpeg", ".JPEG", ".png", ".PNG", ".ogg", ".OGG" };
FileInfo[] info = dir.GetFiles().Where(f => extensions.Contains(f.Extension.ToLower())).ToArray();
Debug.Log (info[0]);
// Logs C:\medias\img1.jpg
}
// Update is called once per frame
void Update() {
}
}
謝謝:)