mirror of
https://github.com/RaindropViewer/RaindropViewer.git
synced 2026-07-30 02:52:14 +00:00
Make demo scene to browse tga files in openmetaverse_data added BetterStreamingAssets to read from SA some refactoring.
53 lines
1.7 KiB
C#
53 lines
1.7 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using System.IO;
|
|
using UnityEngine.Networking;
|
|
|
|
// Class to help read the assets residing in the streamingassets folder; mostly binary and image/tga files.
|
|
public class StreamAssetsReader
|
|
{
|
|
|
|
//reads file at relative path into bytearray
|
|
public static void read(string path, byte[] readInto)
|
|
{
|
|
// all at once
|
|
byte[] data = BetterStreamingAssets.ReadAllBytes(path);
|
|
|
|
}
|
|
|
|
//callback when the web asset is loaded.
|
|
//private static void StreamAssetsReader_completed(UnityWebRequestAsyncOperation obj)
|
|
//{
|
|
// byte[] result = obj.webRequest.downloadHandler.data;
|
|
// File.WriteAllText(Application.persistentDataPath + relative_path, ((byte)obj.webRequest.result));
|
|
// //throw new System.NotImplementedException();
|
|
//}
|
|
|
|
|
|
|
|
//you can use the coroutine way, or you can use the callback function way.
|
|
//private void OnLoadDone(UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationHandle<TextAsset> obj)
|
|
//{
|
|
// // In a production environment, you should add exception handling to catch scenarios such as a null result.
|
|
// TextAsset data = obj.Result;
|
|
// byte[] data_bytes = data.bytes;
|
|
// var tex = OpenMetaverse.Imaging.LoadTGAClass.LoadTGA(data_bytes);
|
|
|
|
// float timeEnd = Time.realtimeSinceStartup;
|
|
|
|
// if (tex == null)
|
|
// {
|
|
// Debug.Log("reading of TGA addressable failed");
|
|
// }
|
|
// else
|
|
// {
|
|
// Debug.Log("reading of TGA addressable SUCCESS! \nTook: " + (timeEnd - timeStart) + "seconds");
|
|
// iv.setRawImage(tex);
|
|
// }
|
|
|
|
//}
|
|
|
|
|
|
}
|