unityzgy/Assets/Scripts/UIScripts/Teacher/DragIcon.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

66 lines
2.1 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
public class DragIcon : IconBase
{
protected Vector2 offsetPos; //临时记录点击点与UI的相对位置
protected bool isOnMap;//放置在固定位置
protected bool keepLocalScale;//是否保持自身缩放 true随父物体缩放 false父物体缩放时始终保持当前的大小
protected bool isAdded;//已经添加到记录中
protected List<RaycastResult> results = new List<RaycastResult>();//点击时触发的所有UI层级
// Start is called before the first frame update
protected virtual void Start()
{
if (!isOnMap)
{
transform.position = (Vector2)Input.mousePosition;
offsetPos = (Vector2)Input.mousePosition - (Vector2)transform.position;
}
float parentScale = this.transform.parent.localScale.x;
this.transform.localScale = new Vector3(1.0f / parentScale, 1.0f / parentScale, 1);
}
// Update is called once per frame
protected virtual void Update()
{
if (!isOnMap)
{
transform.position = (Vector2)Input.mousePosition - offsetPos;
}
if (!keepLocalScale)
{
float parentScale = this.transform.parent.localScale.x;
this.transform.localScale = new Vector3(1.0f / parentScale, 1.0f / parentScale, 1);
}
}
protected void GetMouseRaycastAll()
{
PointerEventData eventDataCurrentPosition = new PointerEventData(EventSystem.current);
eventDataCurrentPosition.position = Input.mousePosition;
EventSystem.current.RaycastAll(eventDataCurrentPosition, results);
}
//设置初始化位置 并固定在该位置 关闭拖拽逻辑
public void SetFixedAnchoredPos(Vector2 anchorPos)
{
this.GetComponent<RectTransform>().anchoredPosition = anchorPos;
isOnMap = true;
isAdded = true;
}
/// <summary>
/// 被对象池收回时初始化参数
/// </summary>
protected virtual void OnDisable()
{
isOnMap = false;
isAdded = false;
}
}