2025-02-21 11:49:10 +08:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
using TMPro;
|
|
|
|
|
|
using DG.Tweening;
|
|
|
|
|
|
|
|
|
|
|
|
namespace QFramework.Example
|
|
|
|
|
|
{
|
|
|
|
|
|
public class UIDrawData : UIPanelData
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public partial class UIDraw : UIPanel
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
protected override void OnInit(IUIData uiData = null)
|
|
|
|
|
|
{
|
|
|
|
|
|
mData = uiData as UIDrawData ?? new UIDrawData();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// <20>رհ<D8B1>ť<EFBFBD><C5A5><EFBFBD><EFBFBD>
|
|
|
|
|
|
CloseBtn.onClick.AddListener(() =>
|
|
|
|
|
|
{
|
|
|
|
|
|
StringEventSystem.Global.Send($"On{UIDraw.Name}Close");
|
|
|
|
|
|
Hide();
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PenSizeSlider.onValueChanged.AddListener(value =>
|
|
|
|
|
|
{
|
|
|
|
|
|
RefreshPenSize();
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
AlphaSlider.onValueChanged.AddListener(value =>
|
|
|
|
|
|
{
|
|
|
|
|
|
RefreshAlphaSet();
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
HideBtn.onValueChanged.AddListener(isOn =>
|
|
|
|
|
|
{
|
|
|
|
|
|
if (isOn)
|
|
|
|
|
|
{
|
|
|
|
|
|
Content.GetComponent<DOTweenAnimation>().DORestart();
|
|
|
|
|
|
HideBtn.transform.Find("Label").GetComponent<TextMeshProUGUI>().text = "<22><>ʾ";
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
Content.GetComponent<DOTweenAnimation>().DOPlayBackwards();
|
|
|
|
|
|
HideBtn.transform.Find("Label").GetComponent<TextMeshProUGUI>().text = "<22><><EFBFBD><EFBFBD>";
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var toggle in Colors.GetComponentsInChildren<Toggle>())
|
|
|
|
|
|
{
|
|
|
|
|
|
toggle.onValueChanged.AddListener(isOn =>
|
|
|
|
|
|
{
|
|
|
|
|
|
if (isOn)
|
|
|
|
|
|
{
|
|
|
|
|
|
ChangeColor(toggle.transform.Find("Color").GetComponent<Image>().color);
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BackBtn.onClick.AddListener(() =>
|
|
|
|
|
|
{
|
2025-02-21 17:26:17 +08:00
|
|
|
|
ScreenShotPainter.instance.Undo();
|
2025-02-21 11:49:10 +08:00
|
|
|
|
});
|
|
|
|
|
|
ClearBtn.onClick.AddListener(() =>
|
|
|
|
|
|
{
|
2025-02-21 17:26:17 +08:00
|
|
|
|
ScreenShotPainter.instance.Clear();
|
2025-02-21 11:49:10 +08:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
Pen.onValueChanged.AddListener(isOn =>
|
|
|
|
|
|
{
|
2025-02-21 17:26:17 +08:00
|
|
|
|
if (isOn)
|
|
|
|
|
|
{
|
|
|
|
|
|
ScreenShotPainter.instance.SetStatus(ScreenShotPainter.Status.Pen);
|
2025-02-24 11:11:14 +08:00
|
|
|
|
RefreshPenSize();
|
2025-02-21 17:26:17 +08:00
|
|
|
|
}
|
2025-02-21 11:49:10 +08:00
|
|
|
|
});
|
|
|
|
|
|
Eraser.onValueChanged.AddListener(isOn =>
|
|
|
|
|
|
{
|
2025-02-21 17:26:17 +08:00
|
|
|
|
if (isOn)
|
|
|
|
|
|
{
|
|
|
|
|
|
ScreenShotPainter.instance.SetStatus(ScreenShotPainter.Status.Eraser);
|
2025-02-24 11:11:14 +08:00
|
|
|
|
RefreshPenSize();
|
2025-02-21 17:26:17 +08:00
|
|
|
|
}
|
2025-02-21 11:49:10 +08:00
|
|
|
|
});
|
2025-02-21 17:26:17 +08:00
|
|
|
|
Line.onValueChanged.AddListener(isOn =>
|
|
|
|
|
|
{
|
|
|
|
|
|
if (isOn)
|
|
|
|
|
|
{
|
|
|
|
|
|
ScreenShotPainter.instance.SetStatus(ScreenShotPainter.Status.Line);
|
|
|
|
|
|
}
|
2025-02-21 11:49:10 +08:00
|
|
|
|
|
2025-02-21 17:26:17 +08:00
|
|
|
|
});
|
2025-02-21 11:49:10 +08:00
|
|
|
|
|
2025-02-24 11:11:14 +08:00
|
|
|
|
Rect.onValueChanged.AddListener(isOn =>
|
|
|
|
|
|
{
|
|
|
|
|
|
if (isOn)
|
|
|
|
|
|
{
|
|
|
|
|
|
ScreenShotPainter.instance.SetStatus(ScreenShotPainter.Status.Rect);
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
Circle.onValueChanged.AddListener(isOn =>
|
|
|
|
|
|
{
|
|
|
|
|
|
if (isOn)
|
|
|
|
|
|
{
|
|
|
|
|
|
ScreenShotPainter.instance.SetStatus(ScreenShotPainter.Status.Circle);
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
2025-02-21 11:49:10 +08:00
|
|
|
|
|
2025-05-06 17:22:00 +08:00
|
|
|
|
|
|
|
|
|
|
Arrow.onValueChanged.AddListener(isOn =>
|
|
|
|
|
|
{
|
|
|
|
|
|
if (isOn)
|
|
|
|
|
|
{
|
|
|
|
|
|
ScreenShotPainter.instance.SetStatus(ScreenShotPainter.Status.Arrow);
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2025-03-14 11:24:44 +08:00
|
|
|
|
ColorAreaBtn.onClick.AddListener(() =>
|
|
|
|
|
|
{
|
|
|
|
|
|
ColorArea.gameObject.SetActive(true);
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
colorPicker.GetComponent<ColorPicker>().OnSelected = color =>
|
|
|
|
|
|
{
|
|
|
|
|
|
ChangeColor(color);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
mask.onClick.AddListener(() =>
|
|
|
|
|
|
{
|
|
|
|
|
|
ColorArea.gameObject.SetActive(false);
|
|
|
|
|
|
});
|
2025-03-18 10:34:06 +08:00
|
|
|
|
|
2025-02-21 11:49:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
public void ChangeColor(Color color)
|
|
|
|
|
|
{
|
|
|
|
|
|
Icon.color = new Color(color.r, color.g, color.b, Icon.color.a);
|
2025-02-21 17:26:17 +08:00
|
|
|
|
ScreenShotPainter.instance.SetPaintColor(Icon.color);
|
2025-02-21 11:49:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void RefreshPenSize()
|
|
|
|
|
|
{
|
2025-02-24 11:11:14 +08:00
|
|
|
|
|
2025-02-21 17:26:17 +08:00
|
|
|
|
var normalValue = PenSizeSlider.value / PenSizeSlider.maxValue;
|
2025-02-24 11:11:14 +08:00
|
|
|
|
if (Eraser.isOn)
|
|
|
|
|
|
{
|
2025-02-21 17:26:17 +08:00
|
|
|
|
|
2025-02-24 11:11:14 +08:00
|
|
|
|
//<2F><>С
|
|
|
|
|
|
float size = PaintingParams.EraserSizeMaxValue + (1 - normalValue) * PaintingParams.EraserSizeFactor;
|
|
|
|
|
|
float sizeY = ((float)Screen.height / (float)Screen.width) * size;
|
|
|
|
|
|
ScreenShotPainter.instance.SetEraserSize(size, sizeY);
|
2025-02-21 17:26:17 +08:00
|
|
|
|
|
2025-05-09 14:23:17 +08:00
|
|
|
|
float width = 1920 / size;
|
|
|
|
|
|
float height = 1920 / size;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>y<EFBFBD><79><EFBFBD><EFBFBD>
|
2025-02-24 11:11:14 +08:00
|
|
|
|
Icon.transform.localScale = new Vector3(width / Icon.rectTransform.rect.width, height / Icon.rectTransform.rect.height, 1);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2025-02-21 17:26:17 +08:00
|
|
|
|
|
2025-02-24 11:11:14 +08:00
|
|
|
|
float size = PaintingParams.BrushSizeMaxValue + (1 - normalValue) * PaintingParams.BrushSizeFactor;
|
|
|
|
|
|
float sizeY = ((float)Screen.height / (float)Screen.width) * size;
|
|
|
|
|
|
ScreenShotPainter.instance.SetPaintingSize(size, sizeY);
|
2025-02-21 17:26:17 +08:00
|
|
|
|
|
2025-05-09 14:23:17 +08:00
|
|
|
|
float width = 1920 / size;
|
|
|
|
|
|
float height = 1920 / size;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>y<EFBFBD><79><EFBFBD><EFBFBD>
|
2025-02-24 11:11:14 +08:00
|
|
|
|
Icon.transform.localScale = new Vector3(width / Icon.rectTransform.rect.width, height / Icon.rectTransform.rect.height, 1);
|
2025-02-21 17:26:17 +08:00
|
|
|
|
|
2025-02-24 11:11:14 +08:00
|
|
|
|
}
|
2025-02-21 17:26:17 +08:00
|
|
|
|
|
|
|
|
|
|
Penvalue.text = PenSizeSlider.value.ToString();
|
2025-02-24 11:11:14 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-02-21 11:49:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void RefreshAlphaSet()
|
|
|
|
|
|
{
|
|
|
|
|
|
var color = Icon.color;
|
|
|
|
|
|
color.a = AlphaSlider.value / 100f;
|
|
|
|
|
|
Icon.color = color;
|
2025-02-21 17:50:33 +08:00
|
|
|
|
ScreenShotPainter.instance.SetPaintColor(Icon.color);
|
2025-03-13 14:47:53 +08:00
|
|
|
|
AlphaValue.text = AlphaSlider.value + "%";
|
2025-02-21 11:49:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-03-18 15:22:05 +08:00
|
|
|
|
|
2025-02-21 11:49:10 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void HandleSaveClearColorInput()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (Input.GetKeyDown(KeyCode.S))
|
|
|
|
|
|
{
|
|
|
|
|
|
SaveDrawing();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƽ<EFBFBD><C6BD><EFBFBD><EFBFBD>ķ<EFBFBD><C4B7><EFBFBD>
|
|
|
|
|
|
private void SaveDrawing()
|
|
|
|
|
|
{
|
|
|
|
|
|
string filePath = Application.dataPath + "/Drawings/" + System.DateTime.Now.ToString("yyyyMMddHHmmss") + ".png";
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>
|
|
|
|
|
|
Directory.CreateDirectory(Path.GetDirectoryName(filePath));
|
|
|
|
|
|
ScreenCapture.CaptureScreenshot(filePath);
|
|
|
|
|
|
Debug.Log("Drawing saved to: " + filePath);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected override void OnOpen(IUIData uiData = null)
|
|
|
|
|
|
{
|
2025-03-18 10:34:06 +08:00
|
|
|
|
TypeEventSystem.Global.Register<BeginScreenShot>(OnBeginScreenShot);
|
|
|
|
|
|
TypeEventSystem.Global.Register<EndScreenShot>(OnEndScreenShot);
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-02-21 11:49:10 +08:00
|
|
|
|
Show3DCamera.instance.lockMove = true;
|
|
|
|
|
|
DrawController.instance.gameObject.SetActive(true);
|
2025-03-13 14:47:53 +08:00
|
|
|
|
ScreenShotPainter.instance.Init(RawImg, captureBGImg, CirCleImg, RectImg);
|
2025-02-21 17:26:17 +08:00
|
|
|
|
ScreenShotPainter.instance.SwitchOn(true);
|
|
|
|
|
|
ScreenShotPainter.instance.SetPaintColor(Icon.color);
|
|
|
|
|
|
RefreshAlphaSet();
|
|
|
|
|
|
RefreshPenSize();
|
2025-02-21 11:49:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-03-18 10:34:06 +08:00
|
|
|
|
private void OnEndScreenShot(EndScreenShot shot)
|
|
|
|
|
|
{
|
|
|
|
|
|
Content.gameObject.SetActive(true);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void OnBeginScreenShot(BeginScreenShot shot)
|
|
|
|
|
|
{
|
|
|
|
|
|
Content.gameObject.SetActive(false);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-02-21 11:49:10 +08:00
|
|
|
|
protected override void OnShow()
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected override void OnHide()
|
|
|
|
|
|
{
|
|
|
|
|
|
Show3DCamera.instance.lockMove = false;
|
|
|
|
|
|
DrawController.instance.gameObject.SetActive(false);
|
2025-03-18 10:34:06 +08:00
|
|
|
|
|
|
|
|
|
|
TypeEventSystem.Global.UnRegister<BeginScreenShot>(OnBeginScreenShot);
|
|
|
|
|
|
TypeEventSystem.Global.UnRegister<EndScreenShot>(OnEndScreenShot);
|
2025-02-21 11:49:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected override void OnClose()
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|