/// <summary> /// AssetBundleの読み込みと展開 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="name"></param> /// <param name="assets"></param> /// <param name="action"></param> /// <param name="progress"></param> /// <returns></returns> public static IEnumerator AssetBundleFile <T>(string name, string[] assets, Action <T[]> action, Action <float> progress = null) where T : UnityEngine.Object { byte[] data = null; Debug.Log("Load File"); yield return(FileIOControl.ReadBytesFile(name, (d) => data = d)); Debug.Log("Load AssetBundle"); yield return(assetBundleData <T>(data, assets, action, progress)); Debug.Log("Load Complete"); }
/// <summary> /// Photoフォルダから画像ファイルを取得 /// </summary> /// <param name="name"></param> /// <param name="action"></param> /// <returns></returns> public static IEnumerator LoadPhoto(string name, Action <Texture2D> action) { Texture2D tex = null; byte[] data = null; #if UNITY_UWP uint w = 0, h = 0; var task = Task.Run(async() => { var file = await KnownFolders.CameraRoll.GetFileAsync(name); if (file != null) { var img = await file.OpenReadAsync(); var decoder = await BitmapDecoder.CreateAsync(img); var pixel = await decoder.GetPixelDataAsync(); var bytes = pixel.DetachPixelData(); w = decoder.PixelWidth; h = decoder.PixelHeight; data = new byte[bytes.Length]; // 取得データは上下が反転している for (var i = 0; i < h; i++) { for (var j = 0; j < w; j++) { data[(w * (h - 1 - i) + j) * 4 + 0] = bytes[(w * i + j) * 4 + 0]; data[(w * (h - 1 - i) + j) * 4 + 1] = bytes[(w * i + j) * 4 + 1]; data[(w * (h - 1 - i) + j) * 4 + 2] = bytes[(w * i + j) * 4 + 2]; data[(w * (h - 1 - i) + j) * 4 + 3] = bytes[(w * i + j) * 4 + 3]; } } } }); yield return(new WaitWhile(() => task.IsCompleted == false)); tex = new Texture2D((int)w, (int)h, TextureFormat.BGRA32, false); tex.LoadRawTextureData(data); #elif UNITY_EDITOR || UNITY_STANDALONE tex = new Texture2D(1, 1); yield return(FileIOControl.ReadBytesFile(FileIOControl.LocalFolderPath + "\\" + name, (b) => data = b)); tex.LoadImage(data); #endif tex.Apply(); yield return(null); if (action != null) { action.Invoke(tex); } }