2025-08-20 11:14:21 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using HK.FUJIFILM;
|
|
|
|
|
using TMPro;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
using ZGame;
|
|
|
|
|
using ZXL.Helper;
|
|
|
|
|
|
|
|
|
|
public class MugActualModel : MonoBehaviour
|
|
|
|
|
{
|
|
|
|
|
// public TextBox text;
|
|
|
|
|
//public static ThreeDeeStickerProduct currentMugProduct = null;
|
|
|
|
|
public int dimension;
|
|
|
|
|
|
|
|
|
|
public Camera frontCam;
|
|
|
|
|
public Renderer frontRender;
|
|
|
|
|
public RectTransform[] renderFaces;
|
|
|
|
|
public CanvasGroup[] faceGroup;
|
2025-08-23 10:08:36 +08:00
|
|
|
|
public Camera _3DCamera;
|
2025-08-20 11:14:21 +08:00
|
|
|
|
|
|
|
|
|
public void DisableFace(int i)
|
|
|
|
|
{
|
|
|
|
|
if (i >= faceGroup.Length)
|
|
|
|
|
return;
|
|
|
|
|
faceGroup[i].alpha = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void EnableFace(int i)
|
|
|
|
|
{
|
|
|
|
|
if (i >= faceGroup.Length)
|
|
|
|
|
return;
|
|
|
|
|
faceGroup[i].alpha = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//public ModelRotator rotator;
|
|
|
|
|
public void Awake()
|
|
|
|
|
{
|
|
|
|
|
if (IsInit)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
RenderTexture rendtx = new RenderTexture(dimension, dimension, 24, RenderTextureFormat.ARGB32);
|
|
|
|
|
frontCam.targetTexture = rendtx;
|
|
|
|
|
|
|
|
|
|
if (frontRender != null)
|
|
|
|
|
frontRender.material.mainTexture = rendtx;
|
|
|
|
|
|
|
|
|
|
//modelRenderer.material.mainTexture = rendtx;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnEnable()
|
|
|
|
|
{
|
|
|
|
|
EventManager.Instance.Subscribe(SavePreviewAndDesignEventArgs.EventId, SavePreviewAndDesignEvent);
|
2025-08-23 10:08:36 +08:00
|
|
|
|
EventManager.Instance.FireNow(this, new Set3DCameraEventArgs(_3DCamera));
|
2025-08-20 11:14:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnDisable()
|
|
|
|
|
{
|
2025-08-23 10:08:36 +08:00
|
|
|
|
EventManager.Instance.FireNow(this, new Set3DCameraEventArgs(null));
|
2025-08-20 11:14:21 +08:00
|
|
|
|
EventManager.Instance.Unsubscribe(SavePreviewAndDesignEventArgs.EventId, SavePreviewAndDesignEvent);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SavePreviewAndDesignEvent(object sender, GameEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
var args = e as SavePreviewAndDesignEventArgs;
|
2025-08-25 15:53:01 +08:00
|
|
|
|
args.shoppingCartData.designImage[0] = GetDesignImageData();
|
2025-08-20 11:14:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public byte[] GetDesignImageData()
|
|
|
|
|
{
|
|
|
|
|
var texture2D = TextureHelper.SaveCameraToTexture(frontCam);
|
|
|
|
|
return texture2D.EncodeToPNG();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[SerializeField] private bool IsInit = false;
|
|
|
|
|
|
|
|
|
|
public void InitModel(Vector2 dimension)
|
|
|
|
|
{
|
|
|
|
|
Debug.Log("called");
|
|
|
|
|
int max = (int)Mathf.Max(dimension.x, dimension.y);
|
|
|
|
|
RenderTexture rendtx = new RenderTexture(max, max, 24, RenderTextureFormat.ARGB32);
|
|
|
|
|
frontCam.targetTexture = rendtx;
|
|
|
|
|
if (frontRender != null)
|
|
|
|
|
frontRender.material.mainTexture = rendtx;
|
|
|
|
|
foreach (RectTransform rect in renderFaces)
|
|
|
|
|
{
|
|
|
|
|
rect.sizeDelta = dimension;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IsInit = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Vector3[] MeshRotationToSides;
|
|
|
|
|
public Vector3[] PivotRotationToSides;
|
|
|
|
|
public Vector3 neuralPos_mesh, neuralPos_pivot;
|
|
|
|
|
|
|
|
|
|
public void RotateToSides(int i)
|
|
|
|
|
{
|
|
|
|
|
//modelMeshes.rotation = Quaternion.identity;
|
|
|
|
|
//pivot.local = Quaternion.identity;
|
|
|
|
|
modelMeshes.localEulerAngles = MeshRotationToSides[i];
|
|
|
|
|
pivot.localEulerAngles = PivotRotationToSides[i];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void RotateToFront()
|
|
|
|
|
{
|
|
|
|
|
modelMeshes.localEulerAngles = neuralPos_mesh;
|
|
|
|
|
pivot.localEulerAngles = neuralPos_pivot;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void RotateToBack()
|
|
|
|
|
{
|
|
|
|
|
modelMeshes.rotation = Quaternion.Euler(0, 180, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public RectTransform contentArea(int i)
|
|
|
|
|
{
|
|
|
|
|
return renderFaces[i];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//public RectTransform contentArea;
|
|
|
|
|
|
|
|
|
|
public Transform modelMeshes;
|
|
|
|
|
|
|
|
|
|
public Transform pivot;
|
|
|
|
|
|
|
|
|
|
public void ClearEverything()
|
|
|
|
|
{
|
|
|
|
|
//foreach (Transform child in contentArea)
|
|
|
|
|
// Destroy(child.gameObject);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Sprite[][] printingArea;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Image capIcon;
|
|
|
|
|
public TMP_InputField capInputField;
|
|
|
|
|
public GameObject cloneTarget;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Renderer mainModel;
|
|
|
|
|
|
|
|
|
|
public void ChangeTexture(Texture tex)
|
|
|
|
|
{
|
|
|
|
|
mainModel.material.mainTexture = tex;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ChangeMatColor(Color color)
|
|
|
|
|
{
|
|
|
|
|
mainModel.material.SetColor("_Color", color);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Image roofImage;
|
|
|
|
|
|
|
|
|
|
public void ChangeRoofImage(Sprite sprite)
|
|
|
|
|
{
|
|
|
|
|
roofImage.gameObject.SetActive(true);
|
|
|
|
|
roofImage.sprite = sprite;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public GameObject yuruObject;
|
|
|
|
|
public Image yuruImage;
|
|
|
|
|
public Image yuruFullImage;
|
|
|
|
|
|
|
|
|
|
public void YuruSet(Sprite sprite, bool IsFull = false)
|
|
|
|
|
{
|
|
|
|
|
if (IsFull)
|
|
|
|
|
{
|
|
|
|
|
yuruFullImage.gameObject.SetActive(true);
|
|
|
|
|
yuruObject.SetActive(false);
|
|
|
|
|
yuruFullImage.sprite = sprite;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
yuruFullImage.gameObject.SetActive(false);
|
|
|
|
|
yuruObject.SetActive(true);
|
|
|
|
|
yuruImage.sprite = sprite;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void YuruSetPixel(Vector2 size)
|
|
|
|
|
{
|
|
|
|
|
yuruImage.GetComponent<RectTransform>().sizeDelta = size;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void YuruSetSize(Vector3 scale)
|
|
|
|
|
{
|
|
|
|
|
yuruImage.transform.localScale = scale;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Image[] trademarks;
|
|
|
|
|
public GameObject[] yuruIcons;
|
|
|
|
|
|
|
|
|
|
public void YuruSetTrade(Sprite sprite)
|
|
|
|
|
{
|
|
|
|
|
foreach (Image img in trademarks)
|
|
|
|
|
{
|
|
|
|
|
img.sprite = sprite;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SetOnOff(bool IsOn)
|
|
|
|
|
{
|
|
|
|
|
foreach (GameObject obj in yuruIcons)
|
|
|
|
|
{
|
|
|
|
|
obj.SetActive(IsOn);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Image staticImage;
|
|
|
|
|
}
|