using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using System.IO; public class PhotoPanel : MonoBehaviour { public struct ImageData { public long timestamp; public byte[] data; } public Button SaveBtn; public Button N_SaveBtn; public RawImage m_Rawimage; string path = Application.streamingAssetsPath + "/RobotFiles/Photo/"; // Start is called before the first frame update void Start() { SaveBtn.onClick.AddListener(SaveTexture); N_SaveBtn.onClick.AddListener(DontSaveTexture); } public void Init(Texture2D _tex) { m_Rawimage.texture = _tex; _tex.EncodeToPNG(); } void SaveTexture() { // FolderBrowserHelper.SaveFile(path, SaveFiledPath, FolderBrowserHelper.IMAGEFILTER); SaveFiledPath(path); } private void SaveFiledPath(string str) { string path3 = path.Replace(@"\", "/"); Texture2D tex = m_Rawimage.texture as Texture2D; ImageData pack; pack.data = tex.EncodeToPNG(); pack.timestamp = System.DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(); //string name = str.Replace("D:\\Unity_Project\\IntelligentICTVirtualSimulation\\U.P.A\\Assets\\StreamingAssets\\RobotFiles\\Photo\\", ""); //Debug.Log( name); FileStream file = File.Create(path3 + name); file.Write(pack.data, 0, pack.data.Length); file.Close(); gameObject.SetActive(false); } void DontSaveTexture() { gameObject.SetActive(false); } // Update is called once per frame void Update() { } }