- LocalizationManager: 新增翻译表(SetFormatted/SetDuration/LocalizeOperateMsg) - LoginPanel: InputField placeholder本地化、字体颜色保持 - HistoryPanel: 用时数据本地化、placeholder本地化 - RecordDetailPanel: 操作详情消息本地化(LanguageChanged重建) - AppraiseWindowBase: 评价等级本地化、操作消息重建 - EditorAppraiser: 所有评估消息改用InjectOperateMsgLocalized - StudentOperateRecorder: 新增InjectOperateMsgLocalized方法 - LocalizationLanguageTestBar: 单例模式、ScreenSpaceOverlay筛选 - 字体切换时保留颜色和verticalOverflow
185 lines
5.7 KiB
C#
185 lines
5.7 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using VRTK;
|
|
|
|
//右手柄车辆控制器 用于选取车辆、控制车辆移动
|
|
public class CarVRInputCtrl : MonoBehaviour,IVRInput
|
|
{
|
|
//当前选中的车辆
|
|
CarCtrl currentCar;
|
|
|
|
//当前射线指向的物体
|
|
Transform CurrentPointerTarget;
|
|
|
|
//左手控制器
|
|
public VRTK_ControllerEvents leftControllerEvents;
|
|
|
|
bool interactable=false;//是否启用
|
|
|
|
float hor;
|
|
float ver;
|
|
float breakValue = 0;
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 开启或关闭VR车辆控制输入
|
|
/// </summary>
|
|
/// <param name="interactable"></param>
|
|
public void SetInteractable(bool interactable)
|
|
{
|
|
if (interactable == this.interactable) return;//未改变启用状态 不做处理
|
|
this.interactable = interactable;
|
|
if (interactable)//开启注册监听事件
|
|
{
|
|
RegisterHandleEvent();
|
|
}
|
|
else //注销事件 清空车辆和射线检测物体 恢复车辆选中状态
|
|
{
|
|
CancleHandleEvent();
|
|
if (currentCar)
|
|
{
|
|
currentCar.IsSelect = false;
|
|
currentCar.StopVRCtrl();
|
|
currentCar = null;
|
|
CurrentPointerTarget = null;
|
|
}
|
|
}
|
|
}
|
|
|
|
//注册手柄监听事件
|
|
void RegisterHandleEvent()
|
|
{
|
|
GetComponent<VRTK_ControllerEvents>().TouchpadAxisChanged += new ControllerInteractionEventHandler(DoTouchpadPressed);
|
|
GetComponent<VRTK_ControllerEvents>().TouchpadTouchEnd += new ControllerInteractionEventHandler(DoTouchpadReleased);
|
|
GetComponent<VRTK_ControllerEvents>().TriggerClicked += TriggerClicked;
|
|
|
|
//GetComponent<VRTK_Pointer>().DestinationMarkerHover += DestinationMarkerHover;
|
|
GetComponent<VRTK_Pointer>().PointerStateInvalid += PointerInValid;
|
|
GetComponent<VRTK_Pointer>().PointerStateValid += PointerValid;
|
|
//GetComponent<VRTK_ControllerEvents>().ButtonTwoPressed += OpenCar;//右手上部按钮会触发系统鼠标点击事件 与触控盘太近 易误触发
|
|
leftControllerEvents.TriggerClicked += OpenCar;//改为由左手Trigger点击实现
|
|
|
|
|
|
}
|
|
|
|
//注销手柄监听事件
|
|
void CancleHandleEvent()
|
|
{
|
|
GetComponent<VRTK_ControllerEvents>().TouchpadAxisChanged -= new ControllerInteractionEventHandler(DoTouchpadPressed);
|
|
GetComponent<VRTK_ControllerEvents>().TouchpadTouchEnd -= new ControllerInteractionEventHandler(DoTouchpadReleased);
|
|
GetComponent<VRTK_ControllerEvents>().TriggerClicked -= TriggerClicked;
|
|
//GetComponent<VRTK_Pointer>().DestinationMarkerHover -= DestinationMarkerHover;
|
|
GetComponent<VRTK_Pointer>().PointerStateInvalid -= PointerInValid;
|
|
GetComponent<VRTK_Pointer>().PointerStateValid -= PointerValid;
|
|
GetComponent<VRTK_ControllerEvents>().ButtonTwoPressed -= OpenCar;
|
|
}
|
|
|
|
// 改变当前选中车辆展开状态
|
|
private void OpenCar(object sender, ControllerInteractionEventArgs e)
|
|
{
|
|
if (currentCar)
|
|
currentCar.ChangeOpening(true);
|
|
}
|
|
|
|
//按下扳机
|
|
private void TriggerClicked(object sender, ControllerInteractionEventArgs e)
|
|
{
|
|
if (!GetComponent<VRTK_Pointer>().IsPointerActive())//扣下扳机时 无射线射线物体信息
|
|
{
|
|
CurrentPointerTarget = null;//清空射线消失前选中的物体
|
|
}
|
|
|
|
if (currentCar)//存在当前选中车辆
|
|
{
|
|
if (currentCar.transform == CurrentPointerTarget)//再次选择已经选中的车不做任何处理
|
|
{
|
|
return;
|
|
}
|
|
else//选中了其他物体 或未选中任何物体
|
|
{
|
|
CancelCurrentCarSelelct();//取消当前车辆选中状态
|
|
}
|
|
}
|
|
|
|
if (CurrentPointerTarget)//射线碰到了 一个物体
|
|
{
|
|
currentCar= CurrentPointerTarget.GetComponentInParent<CarCtrl>();
|
|
if (currentCar)//选中了一辆车
|
|
{
|
|
currentCar.IsSelect = true;
|
|
currentCar.StartVRCtrl();
|
|
}
|
|
}
|
|
}
|
|
|
|
//取消车辆选中状态
|
|
private void CancelCurrentCarSelelct()
|
|
{
|
|
currentCar.IsSelect = false;
|
|
currentCar.StopVRCtrl();
|
|
currentCar = null;
|
|
}
|
|
|
|
//射线碰到物体 变红色
|
|
private void PointerInValid(object sender, DestinationMarkerEventArgs e)
|
|
{
|
|
CurrentPointerTarget = null;
|
|
}
|
|
|
|
//射线碰撞到物体 变绿色
|
|
private void PointerValid(object sender, DestinationMarkerEventArgs e)
|
|
{
|
|
CurrentPointerTarget = e.target;
|
|
}
|
|
|
|
//touch结束触碰
|
|
private void DoTouchpadReleased(object sender, ControllerInteractionEventArgs e)
|
|
{
|
|
hor = 0;
|
|
ver = 0;
|
|
breakValue = 1;
|
|
//if (currentCar != null)
|
|
// currentCar.CarMove(0, 0, 1);//停车
|
|
}
|
|
|
|
//touch触碰
|
|
private void DoTouchpadPressed(object sender, ControllerInteractionEventArgs e)
|
|
{
|
|
hor = e.touchpadAxis.x;
|
|
ver = e.touchpadAxis.y;
|
|
breakValue = 0;
|
|
//if (currentCar != null)
|
|
// currentCar.CarMove(e.touchpadAxis.x, e.touchpadAxis.y, 0);//移动
|
|
}
|
|
|
|
//private void OnEnable()
|
|
//{
|
|
// EventCenter.Instance.EventTrigger<IVRInput>("AddVRInput", this);
|
|
//}
|
|
|
|
//private void OnDisable()
|
|
//{
|
|
// EventCenter.Instance.EventTrigger<IVRInput>("RemoveVRInput", this);
|
|
//}
|
|
|
|
void FixedUpdate()
|
|
{
|
|
if (currentCar)
|
|
{
|
|
currentCar.CarMove(hor, ver, breakValue);
|
|
}
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
CancleHandleEvent();
|
|
}
|
|
|
|
}
|