unityzgy/Assets/ThirdPackages/QuickRopes 2/CraneInterGO.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

119 lines
3.1 KiB
C#

using DG.Tweening;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
/// <summary>
/// 起重机交互物体
/// </summary>
public class CraneInterGO : MonoBehaviour
{
[Tooltip("起吊锚点")]
public Transform craneAnchored;
public bool isSlinged;
Vector3 rightPos;
Vector3 rightAngle;
[Tooltip("允许位置误差")]
public Vector3 allowPosError;
//吊起事件
public event UnityAction OnSlingEvent;
//放下事件
public event UnityAction UnSlingEvent;
//放置在固定位置时
public event UnityAction SetOnFixedPos;
//放置在自由位置时
public event UnityAction SetOnFreePos;
// Start is called before the first frame update
void Start()
{
rightPos = this.transform.localPosition;
rightAngle = this.transform.localEulerAngles;
}
/// <summary>
/// 吊起时
/// </summary>
/// <param name="loadHookRig"></param>
public void OnSling()
{
if (!isSlinged) return;
isSlinged = false;
OnSlingEvent?.Invoke();
}
/// <summary>
/// 放下时
/// </summary>
/// <param name="loadHookRig"></param>
public void UnSling()
{
UnSlingEvent?.Invoke();
bool onAllowableFixed = false;//判断是否启用了复位逻辑 且满足安装位置需要
onAllowableFixed = CheckPos();
if (onAllowableFixed)//满足安装条件
{
StartHoming();//播放归位动画
}
else//未处于安装位置 暂时不做处理
{
this.gameObject.GetComponent<Rigidbody>().isKinematic = false;//安置在其他位置时 启用刚体影响
SetOnFreePos?.Invoke();
}
}
/// <summary>
/// 获取锚点位置
/// </summary>
/// <returns></returns>
public Vector3 GetCraneAnchorPos()
{
if (craneAnchored != null)
return craneAnchored.position;
else
return this.transform.position;
}
/// <summary>
/// 检查位置是否符合要求
/// </summary>
/// <returns> true 符合要求</returns>
bool CheckPos()
{
if (Mathf.Abs(this.transform.localPosition.x - rightPos.x) > allowPosError.x)
return false;
if (Mathf.Abs(this.transform.localPosition.y - rightPos.y) > allowPosError.y)
return false;
if (Mathf.Abs(this.transform.localPosition.z - rightPos.z) > allowPosError.z)
return false;
return true;
}
//开始动画复位到准确的安装位置
private void StartHoming()
{
Debug.Log("开始复位");
this.gameObject.GetComponent<Rigidbody>().isKinematic = true;//避免重力或其他物体影响其归位
this.transform.DOLocalMove(rightPos, 1f).OnComplete(HomgingOver);
this.transform.DOLocalRotateQuaternion(Quaternion.Euler(rightAngle), 1f);
}
//复位完成
protected virtual void HomgingOver()
{
this.gameObject.GetComponent<Rigidbody>().isKinematic = false;//复位结束后启用刚体影响
SetOnFixedPos?.Invoke();
}
}