- LocalizationManager: 新增翻译表(SetFormatted/SetDuration/LocalizeOperateMsg) - LoginPanel: InputField placeholder本地化、字体颜色保持 - HistoryPanel: 用时数据本地化、placeholder本地化 - RecordDetailPanel: 操作详情消息本地化(LanguageChanged重建) - AppraiseWindowBase: 评价等级本地化、操作消息重建 - EditorAppraiser: 所有评估消息改用InjectOperateMsgLocalized - StudentOperateRecorder: 新增InjectOperateMsgLocalized方法 - LocalizationLanguageTestBar: 单例模式、ScreenSpaceOverlay筛选 - 字体切换时保留颜色和verticalOverflow
157 lines
5.0 KiB
C#
157 lines
5.0 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.Events;
|
|
|
|
/// <summary>
|
|
/// 起重机控制类
|
|
/// </summary>
|
|
public class MyCraneControl : MonoBehaviour
|
|
{
|
|
public Transform craneObject = null;
|
|
public Transform craneInStop = null;
|
|
public Transform craneOutStop = null;
|
|
private float craneVelocity = 0;
|
|
public float craneAccel = 3;
|
|
public float maxCraneVelocity = 7;
|
|
public float craneDampening = 0.985f;
|
|
public float cranePosition = 0.5f;
|
|
|
|
public Transform trollyObject = null;
|
|
public Transform trollyInStop = null;
|
|
public Transform trollyOutStop = null;
|
|
private float trollyVelocity = 0;
|
|
public float trollyAccel = 3;
|
|
public float maxTrollyVelocity = 7;
|
|
public float trollyDampening = 0.985f;
|
|
public float trollyPosition = 0.5f;
|
|
public QuickRope2 quickRope;
|
|
|
|
public int CurrentRopeChangeValue { get; private set; }
|
|
public event UnityAction<bool> ControllerCraneChanged;
|
|
|
|
bool ctrlCrane;
|
|
bool CtrlCrane
|
|
{
|
|
set
|
|
{
|
|
if (ctrlCrane != value)
|
|
{
|
|
ctrlCrane = value;
|
|
ControllerCraneChanged?.Invoke(ctrlCrane);
|
|
}
|
|
}
|
|
get
|
|
{
|
|
return ctrlCrane;
|
|
}
|
|
}//当前是否正在控制塔吊
|
|
|
|
bool active;//当前是否能控制塔吊
|
|
private void Start()
|
|
{
|
|
active = true;
|
|
}
|
|
|
|
void FixedUpdate()
|
|
{
|
|
if (!active) return;
|
|
bool hasInputValue = false;
|
|
//Crane
|
|
if (!Input.GetKey(KeyCode.A) && Input.GetKey(KeyCode.D))
|
|
{
|
|
craneVelocity += craneAccel * 0.1f * Time.fixedDeltaTime;
|
|
hasInputValue = true;
|
|
}
|
|
else if (Input.GetKey(KeyCode.A) && !Input.GetKey(KeyCode.D))
|
|
{
|
|
craneVelocity -= craneAccel * 0.1f * Time.fixedDeltaTime;
|
|
hasInputValue = true;
|
|
}
|
|
else if (!Input.GetKey(KeyCode.A) && !Input.GetKey(KeyCode.D))
|
|
{
|
|
if (craneVelocity > 0.2f)
|
|
craneVelocity *= craneDampening;
|
|
else
|
|
craneVelocity = 0;
|
|
}
|
|
|
|
if (craneVelocity != 0)
|
|
{
|
|
hasInputValue = true;
|
|
craneVelocity = Mathf.Clamp(craneVelocity, -maxCraneVelocity * 0.1f, maxCraneVelocity * 0.1f);
|
|
cranePosition += craneVelocity * Time.deltaTime;
|
|
cranePosition = Mathf.Clamp(cranePosition, 0f, 1f);
|
|
if (cranePosition == 0 || cranePosition == 1)
|
|
craneVelocity = 0;
|
|
craneObject.transform.position = craneInStop.position + ((craneOutStop.position - craneInStop.position) * cranePosition);
|
|
}
|
|
|
|
// Trolly
|
|
if (!Input.GetKey(KeyCode.S) && Input.GetKey(KeyCode.W))
|
|
{
|
|
trollyVelocity += trollyAccel * 0.1f * Time.fixedDeltaTime;
|
|
}
|
|
else if (Input.GetKey(KeyCode.S) && !Input.GetKey(KeyCode.W))
|
|
{
|
|
trollyVelocity -= trollyAccel * 0.1f * Time.fixedDeltaTime;
|
|
}
|
|
else if (!Input.GetKey(KeyCode.S) && !Input.GetKey(KeyCode.W))
|
|
{
|
|
if (trollyVelocity > 0.2f)
|
|
trollyVelocity *= trollyDampening;
|
|
else
|
|
trollyVelocity = 0;
|
|
}
|
|
if (trollyVelocity != 0)
|
|
{
|
|
hasInputValue = true;
|
|
trollyVelocity = Mathf.Clamp(trollyVelocity, -maxTrollyVelocity * 0.1f, maxTrollyVelocity * 0.1f);
|
|
trollyPosition += trollyVelocity * Time.deltaTime;
|
|
trollyPosition = Mathf.Clamp(trollyPosition, 0f, 1f);
|
|
if (trollyPosition == 0 || trollyPosition == 1)
|
|
trollyVelocity = 0;
|
|
trollyObject.transform.position = trollyInStop.position + ((trollyOutStop.position - trollyInStop.position) * trollyPosition);
|
|
}
|
|
|
|
CurrentRopeChangeValue = 0;
|
|
if (Input.GetKey(KeyCode.UpArrow))
|
|
{
|
|
CurrentRopeChangeValue = -1;
|
|
quickRope.ChangeRopeKey(-1);
|
|
}
|
|
if (Input.GetKey(KeyCode.DownArrow))
|
|
{
|
|
CurrentRopeChangeValue = 1;
|
|
quickRope.ChangeRopeKey(1);
|
|
}
|
|
quickRope.ChangeRopeKey(CurrentRopeChangeValue);
|
|
if (CurrentRopeChangeValue != 0)
|
|
{
|
|
hasInputValue = true;
|
|
}
|
|
CtrlCrane = hasInputValue;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 是否接受硬件控制
|
|
/// </summary>
|
|
/// <param name="active"></param>
|
|
public void SetActive(bool active)
|
|
{
|
|
this.active = active;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 同步时调用
|
|
/// </summary>
|
|
public void SyncCrane(float cPos,float tPos, int ropeChangeValue)
|
|
{
|
|
cranePosition = cPos;
|
|
craneObject.transform.position = craneInStop.position + ((craneOutStop.position - craneInStop.position) * cranePosition);
|
|
trollyPosition = tPos;
|
|
trollyObject.transform.position = trollyInStop.position + ((trollyOutStop.position - trollyInStop.position) * trollyPosition);
|
|
quickRope.ChangeRopeKey(ropeChangeValue);
|
|
}
|
|
}
|