unityzgy/Assets/Scripts/UIScripts/ThisProjectPublic/DrawLineCtrl.cs
ayuan9957 bf12e02276 feat: 多语言本地化系统 - 支持中/英/法/俄实时切换
- LocalizationManager: 新增翻译表(SetFormatted/SetDuration/LocalizeOperateMsg)
- LoginPanel: InputField placeholder本地化、字体颜色保持
- HistoryPanel: 用时数据本地化、placeholder本地化
- RecordDetailPanel: 操作详情消息本地化(LanguageChanged重建)
- AppraiseWindowBase: 评价等级本地化、操作消息重建
- EditorAppraiser: 所有评估消息改用InjectOperateMsgLocalized
- StudentOperateRecorder: 新增InjectOperateMsgLocalized方法
- LocalizationLanguageTestBar: 单例模式、ScreenSpaceOverlay筛选
- 字体切换时保留颜色和verticalOverflow
2026-07-16 10:05:59 +08:00

96 lines
3.4 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
using XFramework.UIExtensions;
public class DrawLineCtrl : MaskableGraphic
{
//public List< Vector2> points;
//public List<bool> colors;
// public float segments;
//public float linewidth;
//非全屏时的修正值 全屏时可为0
public Vector3 anchorPos = new Vector3(0, 0, 0);
List<List<UIVertex>> vertexQuadList = new List<List<UIVertex>>();
List<UIVertex> vertexQuad;
public float lineWidth = 2;
Vector3 lastleftPoint;
Vector3 lastrightPoint;
Vector3 lastPos= Vector3.zero;
protected override void OnPopulateMesh(VertexHelper vh)
{
vh.Clear();
for (int i = 0; i < vertexQuadList.Count; i++)
{
vh.AddUIVertexQuad(vertexQuadList[i].ToArray());
}
}
void Update()
{
if (Input.GetMouseButtonDown(0))
{
// vertexQuadList.Clear();
if (lastPos == Vector3.zero)
{
lastPos = Input.mousePosition - anchorPos;
lastleftPoint = lastPos - new Vector3(Screen.width / 2, Screen.height / 2, 0) + Vector3.up * lineWidth;
lastrightPoint = lastPos - new Vector3(Screen.width / 2, Screen.height / 2, 0) - Vector3.up * lineWidth;
}
else
{
Vector3 newVec = Input.mousePosition - anchorPos - lastPos;
int colorIndex = Random.Range(0, 2);
if (colorIndex == 0)
{
color = Color.green;
}
else
color = Color.red;
if (newVec.magnitude < 0.1f)
{
return;
}
vertexQuad = new List<UIVertex>();
Vector3 vec = Vector3.Cross(newVec.normalized, Vector3.forward).normalized;
Vector3 newleftPoint = Input.mousePosition - anchorPos - new Vector3(Screen.width / 2, Screen.height / 2, 0) + vec * lineWidth;
Vector3 newrightPoint = Input.mousePosition - anchorPos - new Vector3(Screen.width / 2, Screen.height / 2, 0) - vec * lineWidth;
UIVertex uIVertex = new UIVertex();
uIVertex.position = lastleftPoint;
uIVertex.color = color;
vertexQuad.Add(uIVertex);
UIVertex uIVertex1 = new UIVertex();
uIVertex1.position = lastrightPoint;
uIVertex1.color = color;
vertexQuad.Add(uIVertex1);
UIVertex uIVertex3 = new UIVertex();
uIVertex3.position = newrightPoint;
uIVertex3.color = color;
vertexQuad.Add(uIVertex3);
UIVertex uIVertex2 = new UIVertex();
uIVertex2.position = newleftPoint;
uIVertex2.color = color;
vertexQuad.Add(uIVertex2);
lastleftPoint = newleftPoint;
lastrightPoint = newrightPoint;
vertexQuadList.Add(vertexQuad);
lastPos = Input.mousePosition - anchorPos;
SetVerticesDirty();
}
}
if (Input.GetMouseButtonDown(1))
{
lastPos = Vector3.zero;
vertexQuadList.Clear();
SetVerticesDirty();
}
}
}