FM/Assets/Scripts/FUJIFILM/Other/TransparentCaptureSystem_Te...

92 lines
3.2 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using System.Collections;
using UnityEngine;
using System.IO;
namespace HK.FUJIFILM
{
public class TransparentCaptureSystem_Test : TransparentCaptureSystem<TransparentCaptureSystem_Test>
{
// 自定义参数:水印文本
public string watermarkText = "Custom Watermark";
// 自定义参数:水印颜色
public Color watermarkColor = Color.red;
// 重写Init自定义单例逻辑可选
protected override void Init()
{
base.Init(); // 调用基类初始化
Debug.Log("自定义截图系统初始化完成");
}
// 重写原始截图方法:修改截图尺寸或相机设置
protected override IEnumerator CaptureOriginalScreenshot()
{
// 示例截图前临时调整相机FOV
float originalFOV = targetCamera.fieldOfView;
targetCamera.fieldOfView = 60; // 缩小FOV
// 调用基类的截图逻辑(保留原有功能)
var coroutine = base.CaptureOriginalScreenshot();
while (coroutine.MoveNext())
yield return coroutine.Current;
// 恢复相机FOV
targetCamera.fieldOfView = originalFOV;
}
// 重写裁剪逻辑:添加水印
protected override void CropWithTransparency()
{
// 先调用基类裁剪逻辑
base.CropWithTransparency();
// 自定义:给裁剪后的图片添加水印
if (_croppedTexture != null)
{
// 简单水印绘制实际项目可使用Texture2D.SetPixel或更复杂逻辑
for (int y = 0; y < 20; y++) // 底部绘制20像素高的水印区域
{
for (int x = 0; x < _croppedTexture.width; x++)
{
// 每10像素绘制一个水印像素简单示例
if (x % 10 == 0)
{
_croppedTexture.SetPixel(x, y, watermarkColor);
}
}
}
_croppedTexture.Apply(); // 应用水印
}
}
// 重写保存逻辑:修改保存路径
protected override void SaveCroppedImage()
{
// 自定义保存路径:在原有路径后添加"Custom"子文件夹
string customFolder = Path.Combine(saveFolder, "Custom");
if (!Directory.Exists(customFolder))
Directory.CreateDirectory(customFolder);
// 临时修改保存路径
string originalSaveFolder = saveFolder;
saveFolder = customFolder;
// 调用基类保存逻辑(使用修改后的路径)
base.SaveCroppedImage();
// 恢复原始路径
saveFolder = originalSaveFolder;
}
// 利用钩子方法:保存后上传图片
protected override void OnAfterSave()
{
base.OnAfterSave();
// 示例:保存完成后自动上传
Debug.Log($"开始上传图片:{FullPath}");
// StartCoroutine(UploadToServer(FullPath)); // 实际项目中添加上传逻辑
}
}
}