思想:
1.获取手指在圆盘的位置,换算成角度。把圆盘分为两个区。左按钮和右按钮。
2.在SteamVR Input,打开网页在圆盘添加触摸板,并添加相应的动作(Action)
3.通过圆盘触摸和圆盘点击实现事件的执行、变色
public UnityEvent Menter = new UnityEvent();
[Header("左边按钮")]
public UnityEvent LeftOnClick = new UnityEvent();
[Header("右边按钮")]
public UnityEvent RightOnClick = new UnityEvent();
public UnityEvent Mexit = new UnityEvent();
public Image LeftImage;
public Image RightImage;
//颜色设置
private Color LeftImageStartColor;
private Color RightImageStartColor;
private Color ClickImageColor = Color.gray;
private bool Limit = true;
private void Start()
{
LeftImageStartColor = LeftImage.color;
RightImageStartColor = RightImage.color;
Debug.Log(RightImageStartColor);
}
private void Update()
{
TrackPadTwoPartition();
}
private void TrackPadTwoPartition()
{
Vector3 currentPos = SteamVR_Actions._default.TrackPadPos.lastAxis;
float Angle = Mathf.Acos(Vector2.Dot(currentPos, Vector2.up)) * Mathf.Rad2Deg;
Angle = currentPos.x < 0 ? -Angle : Angle;
if (SteamVR_Actions._default.TrackPadTouch.GetState(SteamVR_Input_Sources.LeftHand) && Limit)
{
if (Angle > 0)
{
TouchColor(RightImage, Color.yellow);
TouchColor(LeftImage, LeftImageStartColor);
}
else if (Angle < -1)
{
TouchColor(LeftImage, Color.green);
TouchColor(RightImage, RightImageStartColor);
}
}
if (!SteamVR_Actions._default.TrackPadTouch.GetState(SteamVR_Input_Sources.LeftHand))
{
NoClick();
}
if (SteamVR_Actions._default.TrackPadClick.GetStateDown(SteamVR_Input_Sources.LeftHand))
{
if (Angle > 0)
{
RightOnClick.Invoke();
}
else if (Angle < -1)
{
LeftOnClick.Invoke();
}
Limit = false;
}
if (SteamVR_Actions._default.TrackPadClick.GetStateUp(SteamVR_Input_Sources.LeftHand))
{
NoClick();
Limit = true;
}
}
public void NoClick()
{
ChangeColor(LeftImage, LeftImageStartColor);
ChangeColor(RightImage, RightImageStartColor);
}
public void LeftClick()
{
Debug.Log("左边点击");
ChangeColor(LeftImage, ClickImageColor);
}
public void RighttClick()
{
Debug.Log("右边点击");
ChangeColor(RightImage, ClickImageColor);
}
public void ChangeColor(Image image, Color color)
{
image.color = color;
}
public void TouchColor(Image image, Color color)
{
image.color = color;
}