59 lines
1.9 KiB
C#
59 lines
1.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using DG.Tweening;
|
|
using UnityEngine;
|
|
using UnityEngine.Serialization;
|
|
using ZGame;
|
|
using ZXL.Helper;
|
|
|
|
namespace Runtime
|
|
{
|
|
public class NotebookModelBar : MonoBehaviour
|
|
{
|
|
[SerializeField] List<Vector3> positions = new List<Vector3>();
|
|
[SerializeField] Transform model;
|
|
|
|
[SerializeField] float doTweenTime = 1f;
|
|
[SerializeField] DesignCoverModelItem designCoverModelItem;
|
|
[SerializeField] Camera previewCamera;
|
|
[SerializeField] Camera designCamera;
|
|
|
|
[ContextMenu("TestPlay")]
|
|
public void PlayIndex(int index)
|
|
{
|
|
if (index >= 0 && index < positions.Count)
|
|
model.DOLocalMove(positions[index], doTweenTime);
|
|
}
|
|
|
|
[ContextMenu("GenPreviewImage")]
|
|
public List<byte[]> GenPreviewImage()
|
|
{
|
|
var texture2D = TextureHelper.SaveCameraToTexture(previewCamera);
|
|
var previewBytes = texture2D.EncodeToPNG();
|
|
var texture2D1 = TextureHelper.SaveCameraToTexture(designCamera);
|
|
var designBytes = texture2D1.EncodeToPNG();
|
|
try
|
|
{
|
|
// save
|
|
#if (PLATFORM_STANDALONE_WIN || UNITY_STANDALONE_WIN) && !UNITY_EDITOR
|
|
string folder = $"{Application.persistentDataPath}/Notebook/{DateTime.Now.Ticks}";
|
|
if (!Directory.Exists(folder))
|
|
{
|
|
Directory.CreateDirectory(folder);
|
|
}
|
|
|
|
File.WriteAllBytes(Path.Combine(folder, "previewImage.png"), previewBytes);
|
|
File.WriteAllBytes(Path.Combine(folder, "designImage.png"), designBytes);
|
|
#endif
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
UnityEngine.Debug.Log(e);
|
|
}
|
|
|
|
// File.WriteAllBytes($"{Application.dataPath}/tupian.png", bytes);
|
|
return new List<byte[]> { previewBytes, designBytes };
|
|
}
|
|
}
|
|
} |