unityzgy/.svn/pristine/6c/6c75c3c330123dcbc96b990493a9cdd0599dce8e.svn-base
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

141 lines
4.2 KiB
Plaintext

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using VRTK;
/// <summary>
/// 自带重力 松开可自行落下的门
/// </summary>
[RequireComponent(typeof(VRTK_InteractableObject))]
public class SimpleDoor : MonoBehaviour,IStepNodeAction
{
VRTK_InteractableObject interactableObject;
UnityAction openDoorEvent;
UnityAction closeDoorEvent;
Rigidbody thisRigidbody;
HingeJoint thisHingeJoint;
JointLimits defultLimits;
//抓取时执行
public event UnityAction OnGrabbedEvent;
//放下重力影响完成后执行
public event UnityAction UnGrabbedWaitGravityEvent;
protected void Awake()
{
thisRigidbody = this.GetComponent<Rigidbody>();
thisHingeJoint = this.GetComponent<HingeJoint>();
defultLimits = thisHingeJoint.limits;
interactableObject = this.GetComponent<VRTK_InteractableObject>();
interactableObject.InteractableObjectUngrabbed += InteractableObjectUngrabbed;
interactableObject.InteractableObjectGrabbed += InteractableObjectGrabbed;
interactableObject.touchHighlightColor = Color.red;
interactableObject.touchHighlightColor.a=0.3f;
}
protected void InteractableObjectGrabbed(object sender, InteractableObjectEventArgs e)
{
OnGrabbedEvent?.Invoke();
}
//放开门时 等待3秒后再判断门是否打开或关上
protected virtual void InteractableObjectUngrabbed(object sender, InteractableObjectEventArgs e)
{
UnGrabbed();
}
protected virtual void UnGrabbed()
{
if (IsInvoking("WaitGravity"))
CancelInvoke("WaitGravity");
Invoke("WaitGravity", 2f);
}
void WaitGravity()
{
UnGrabbedWaitGravityEvent?.Invoke();
UnGrabbedCheckDoorPos();//结束抓取时主动检测位置
}
/// <summary>
/// 主动操作完 2秒后/同步触发时 检查当前门的位置 执行门开/关事件
/// </summary>
public void UnGrabbedCheckDoorPos()
{
if (Mathf.Abs(this.transform.eulerAngles.x) > 30) //松手2秒后 角度仍大于30度 可以确定门不会自动关上了
{
Debug.Log("门打开了");
if (openDoorEvent != null)//关注打开事件时 执行打开事件后
{
openDoorEvent.Invoke();
}
}
else//小于30度 开门角度不够 重力影响下自动闭合了
{
Debug.Log("关闭了");
if (closeDoorEvent != null)
{
closeDoorEvent.Invoke();
}
}
}
public void Active(ProcessEnum stepName, UnityAction nodeFinishedEvent)
{
SetGrabbable(true);
thisRigidbody.isKinematic = false;
if (stepName == ProcessEnum.teardown)//拆卸流程需要把门打开
{
openDoorEvent += nodeFinishedEvent;
}
else if (stepName == ProcessEnum.assemble)//组装流程需要把门关上
{
closeDoorEvent += nodeFinishedEvent;
}
}
public void UnActive(ProcessEnum stepName)
{
SetGrabbable(false);
GetComponent<Rigidbody>().isKinematic = true;
openDoorEvent = null;
closeDoorEvent = null;
}
//启用 /禁用门交互
public void SetGrabbable(bool grabbable)
{
interactableObject.isGrabbable = grabbable;
}
//改变铰链限制度数 保持当前度数
public void KeepNowAngle()
{
Debug.Log("锁住时当前角度为" + this.transform.localEulerAngles.x);
float currentAngleX;
if (this.transform.localEulerAngles.x > 180)
currentAngleX = this.transform.localEulerAngles.x - 360;
else
currentAngleX = 0;
JointLimits limits = thisHingeJoint.limits;
limits.max = defultLimits.max + currentAngleX - 0.5f;
limits.min = defultLimits.max + currentAngleX;
thisHingeJoint.limits = limits;
}
//重置铰链限制
public void ReturnDefultLimit()
{
//Debug.Log("解锁");
Debug.Log(this.transform.localEulerAngles.x);
thisHingeJoint.limits = defultLimits;
}
}