Firstborn/Assets/Scripts/ScreenShotContent.cs

60 lines
1.9 KiB
C#
Raw Normal View History

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.UI;
using System.IO;
using System;
namespace RPGCreationKit
{
public class ScreenShotContent : MonoBehaviour
{
[SerializeField] public GameObject Screenshot;
[SerializeField] public GameObject MyGalleryGO;
[SerializeField] public string FileDir;
[SerializeField] public ButtonSounds Image;
[SerializeField] public ButtonSounds DeleteButton;
public void LoadCurrentImage (string imagePath) {
StartCoroutine(LoadCurrentImageX(imagePath));
}
IEnumerator LoadCurrentImageX(string imagePath) {
UnityWebRequest WWW = UnityWebRequestTexture.GetTexture(imagePath);
yield return WWW.SendWebRequest();
if (WWW.result != UnityWebRequest.Result.ConnectionError) {
Screenshot.GetComponent<RawImage> ().texture = DownloadHandlerTexture.GetContent(WWW);
Screenshot.GetComponent<RawImage> ().SetNativeSize();
Screenshot.GetComponent<RawImage> ().SizeToParent();
}
WWW.Dispose();
}
public void ExpandThisImage() {
MyGallery Manager = MyGalleryGO.GetComponent<MyGallery>();
Manager.ExpandImage(Screenshot.GetComponent<RawImage>());
FileInfo ThisImage = new FileInfo(FileDir);
Manager.PostInformation(ThisImage);
Manager.FileDir = FileDir;
}
public void DeleteMe() {
FileInfo ThisImage = new FileInfo(FileDir);
ThisImage.Delete();
}
// FileSize[i].text = BytesToString(int.Parse(TTempSize));
static string BytesToString(long byteCount) { //
string[] suf = { " B", " KB", " MB", " GB", " TB", " PB", " EB" }; //Longs run out around EB
if (byteCount == 0)
return "0" + suf[0];
long bytes = Math.Abs(byteCount);
int place = Convert.ToInt32(Math.Floor(Math.Log(bytes, 1024)));
double num = Math.Round(bytes / Math.Pow(1024, place), 1);
return (Math.Sign(byteCount) * num).ToString() + suf[place];
}
}
}