FM/Assets/Test/v1.0/RenderCartItemManager.cs

213 lines
7.1 KiB
C#

// using System;
// using System.Collections;
// using System.Collections.Generic;
// using UnityEngine;
// using UnityEngine.UI;
//
// public class RenderCartItemManager : MonoBehaviour
// {
//
// public static RenderCartItemManager instance;
// public Camera renderCam;
//
// private void Awake()
// {
// instance = this;
// }
//
// [HideInInspector] public Texture2D readyTexture;
// //[HideInInspector] public List<Texture2D> printingTexture = new List<Texture2D>();
//
// public void ClearTextureMemory()
// {
// Destroy(readyTexture);
// //foreach (Texture2D tex in printingTexture)
// // Destroy(tex);
// //printingTexture.Clear();
// }
//
// public bool IsEmptyTexture = false;
// public IEnumerator RenderToSprite(GameObject obj)
// {
// if (renderCam.targetTexture != null)
// {
// renderCam.targetTexture.Release();
// }
//
// GameObject productImage = Instantiate(obj, transform);
//
// // Product product = productImage.GetComponent<Product>();
// //
// // product.SetUpForPreviewProcess();
//
// RenderTexture rendtx = new RenderTexture(0, 0, 24);
// int previewC = 1;
// // Debug.Log(product.previewProcess.Count);
// foreach (Action action in product.previewProcess)
// {
//
// Debug.Log("preview process: " + previewC);
//
// action();
//
// float smallerScale = Mathf.Max(product.renderCartSize.x / 400f, product.renderCartSize.y / 400f);
// rendtx = new RenderTexture((int)(product.renderCartSize.x / smallerScale), (int)(product.renderCartSize.y / smallerScale), 24, RenderTextureFormat.ARGB32);
// product.transform.localScale = Vector3.one / smallerScale;
//
// renderCam.targetTexture = rendtx;
// yield return null;
// Texture2D tex = ToTexture2D(rendtx);
// TextureSaver.NewSaveImage(tex, "preview" + previewC);
// if (previewC == 1)
// readyTexture = tex;
// else
// Destroy(tex);
// previewC++;
// }
//
// rendtx.Release();
//
// //product.MakeCartTexture();
//
// //productImage.GetComponent<RectTransform>().anchoredPosition = Vector2.zero;
// //productImage.transform.rotation = Quaternion.Euler(rotation);
// // RenderTexture rendtx = new RenderTexture((int)(product.renderCartSize.x / smallerScale), (int)(product.renderCartSize.y / smallerScale), 24, RenderTextureFormat.ARGB32);
// //rendtx.Release();
// //rendtx.width = (int)size.x;
// //rendtx.height = (int)size.y;
//
//
// //bool IsEmptyTexture = false;
// //get the print version now;
// //printingTexture.Clear();
// product.transform.localScale = Vector3.one;
// product.SetUpForPrintProcess();
// //Debug.Log(product.printProcess.Count);
// int i = 1;
// foreach(Action action in product.printProcess)
// {
// //Debug.Log("new shit");
// action();
// Vector2 printSize = product.renderPrintSize;
// rendtx = new RenderTexture((int)printSize.x, (int)printSize.y, 24, RenderTextureFormat.ARGB32);
// renderCam.targetTexture = rendtx;
// yield return null;
// Texture2D print_tex = ToTexture2D(rendtx);
// if (product is ImagePrintProduct p && ReceiptPrinterManager.instance.IsPrintImage)
// {
// string uploadTmp = TextureSaver.SpecialSaveImageFile(print_tex, "printing" + i);
// //imgRequest.MakeTif(uploadTmp,);
// Debug.Log(uploadTmp);
// var dirPath = SaveLoadPlace.GetSavePath() + ShoppingCartManager.instance.GetCurrentProductID() + "\\";
// //imgRequest.retryAmount = 0;
// imgRequest.MakeTif(dirPath, uploadTmp, p.IsHorizontal, ShoppingCartManager.instance.GetCurrentProductID());
// }
// else
// {
// IsEmptyTexture = IsTextureTransparent(print_tex);
// var path = TextureSaver.NewSaveImage(print_tex, "printing" + i);
// Debug.Log(path);
// if (!IsEmptyTexture)
// {
// try
// {
// #if !UNITY_EDITOR
//
// System.Diagnostics.Process.Start("spot", "\"" + path + "\""); //photoshop轉tiff add spot channel
// #endif
// }
// catch (Exception e)
// {
// Debug.Log(e.Message);
// }
// }
//
// }
//
//
//
// Destroy(print_tex);
// i++;
// //printingTexture.Add(ToTexture2D(rendtx));
// }
//
// product.EndOfPrintingProcess();
// //product.MakePrintingTexture();
//
// //img.texture = readyTexture;
// //img.gameObject.SetActive(true);
// //img.GetComponent<RectTransform>().sizeDelta = size;
// Destroy(productImage);
// rendtx.Release();
//
//
//
// }
//
// bool IsTextureTransparent(Texture2D texture)
// {
// if (texture == null)
// {
// return false;
// }
//
// // Get the pixel array
// Color[] pixels = texture.GetPixels();
//
// // Check if all pixels are fully transparent
// foreach (Color pixel in pixels)
// {
// if (pixel.a != 0)
// {
// return false; // Found a non-transparent pixel
// }
// }
//
// return true; // All pixels are transparent
// }
//
// //public RawImage img;
//
// Texture2D ToTexture2D(RenderTexture rTex)
// {
// RenderTexture currentActiveRT = RenderTexture.active;
// Texture2D tex = new Texture2D(rTex.width, rTex.height, TextureFormat.ARGB32, false);
// RenderTexture.active = rTex;
// tex.ReadPixels(new Rect(0, 0, rTex.width, rTex.height), 0, 0);
// tex.Apply();
// RenderTexture.active = currentActiveRT;
// return tex;
// }
//
//
//
// public RenderTexture cart3D, texture3D;
//
//
// Texture2D ToTexture2D(RenderTexture rTex, int width, int height)
// {
// RenderTexture currentActiveRT = RenderTexture.active;
// Texture2D tex = new Texture2D(width, height, TextureFormat.ARGB32, false);
// RenderTexture.active = rTex;
// tex.ReadPixels(new Rect(rTex.width/2 - width / 2, rTex.height/2 - height /2 - 100, width, height), 0, 0);
// tex.Apply();
// RenderTexture.active = currentActiveRT;
// return tex;
// }
//
// public IEnumerator RenderThreeDPrint()
// {
// yield return null;
// //printingTexture = ToTexture2D(texture3D);
// }
//
// public IEnumerator RenderThreeDCart()
// {
// yield return null;
// readyTexture = ToTexture2D(cart3D, 760, 1024);
//
//
// }
//
// }