150 lines
3.2 KiB
C#
150 lines
3.2 KiB
C#
using System.Globalization;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using Pico.Platform;
|
|
using UnityEngine;
|
|
using System;
|
|
using DG.Tweening;
|
|
using DragonLi.Core;
|
|
using UnityEngine.XR.Interaction.Toolkit;
|
|
using TrackedPoseDriver = UnityEngine.SpatialTracking.TrackedPoseDriver;
|
|
|
|
/// <summary>
|
|
/// 击打结果
|
|
/// </summary>
|
|
public enum HitResult
|
|
{
|
|
None, // 无效击打
|
|
Hit, // 击中雕像
|
|
TargetBreak, // 击碎目标雕像
|
|
WrongBreak // 击碎错误雕像
|
|
}
|
|
|
|
public class RightHand : MonoBehaviour
|
|
{
|
|
public TrackedPoseDriver tracked;
|
|
|
|
private HandState _cachePlayerState;
|
|
|
|
// 射线
|
|
public LayerMask layerMask;
|
|
public Transform ray;
|
|
|
|
[Tooltip("手模型")] public GameObject hand;
|
|
public GameObject hit;
|
|
|
|
private int _cacheTargetId = -1;
|
|
|
|
private Vector3 _curPos;
|
|
private bool _isStartTrigger;
|
|
|
|
public bool isTrigger;
|
|
|
|
public float triggerDis;
|
|
|
|
public bool _isOpenLine = false;
|
|
|
|
//拼图Id
|
|
public int puzzleId;
|
|
|
|
private Collider _collider = null;
|
|
|
|
public Collider selfCollider
|
|
{
|
|
get
|
|
{
|
|
if (_collider == null)
|
|
{
|
|
_collider = GetComponentInChildren<Collider>();
|
|
}
|
|
return _collider;
|
|
}
|
|
}
|
|
|
|
public void Start()
|
|
{
|
|
tracked.enabled = true;
|
|
selfCollider.enabled = true;
|
|
GameManager.Ins.playerRightHand=this;
|
|
MRInput.Ins.RegisterClickRrightTrigger(ClickRrightTrigger);
|
|
Init();
|
|
}
|
|
|
|
public void Init()
|
|
{
|
|
hand.SetActive(true);
|
|
_isOpenLine = true;
|
|
}
|
|
|
|
public void Update()
|
|
{
|
|
if (Input.GetKeyDown(KeyCode.Space))
|
|
{
|
|
|
|
}
|
|
|
|
#if UNITY_EDITOR
|
|
Transform camera = GameLocal.Ins.MRCamera.transform;
|
|
transform.position = camera.position + camera.forward * 0.5f + camera.right * 0.2f + camera.up * -0.1f;
|
|
transform.rotation = camera.rotation;
|
|
#endif
|
|
|
|
ray.gameObject.SetActive(_isOpenLine);
|
|
isTrigger = MRInput.Ins.pressRightTrigger;
|
|
if (isTrigger&& !_isStartTrigger)
|
|
{
|
|
_isStartTrigger = true;
|
|
_curPos = transform.position;
|
|
}
|
|
else
|
|
{
|
|
_isStartTrigger = false;
|
|
}
|
|
triggerDis=isTrigger?transform.position.y-_curPos.y:0;
|
|
// 射线检测
|
|
if (_isOpenLine)
|
|
{
|
|
if (Physics.Raycast(transform.position, transform.forward, out RaycastHit handlingHit, 100F, layerMask))
|
|
{
|
|
|
|
}
|
|
else
|
|
{
|
|
hit = null;
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
private void OnTriggerEnter(Collider other)
|
|
{
|
|
// 拾取硬币
|
|
if (other.CompareTag("Coin"))
|
|
{
|
|
Coin coin = other.GetComponent<Coin>();
|
|
if (coin != null)
|
|
{
|
|
coin.OnCollected();
|
|
}
|
|
}
|
|
}
|
|
|
|
private void OnCollisionEnter(Collision other)
|
|
{
|
|
|
|
}
|
|
|
|
public void ClickRrightTrigger()
|
|
{
|
|
if(hit==null)
|
|
return;
|
|
}
|
|
|
|
public void ChangeHand()
|
|
{
|
|
hand.SetActive(true);
|
|
_isOpenLine = true;
|
|
}
|
|
|
|
}
|