216 lines
5.3 KiB
C#
216 lines
5.3 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;
|
|
|
|
public class RightHand : MonoBehaviour
|
|
{
|
|
public TrackedPoseDriver tracked;
|
|
|
|
private HandState _cachePlayerState;
|
|
|
|
// 射线
|
|
public LayerMask layerMask;
|
|
public Transform ray;
|
|
|
|
[Tooltip("手模型")] public GameObject hand;
|
|
|
|
public GameObject[] gems;
|
|
|
|
public GameObject gemKeyHand;
|
|
public GameObject gemKey;
|
|
public Transform gemKeyUp;
|
|
|
|
public GameObject skillet;
|
|
public GameObject skilletEx;
|
|
|
|
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;
|
|
foreach (var item in gems)
|
|
{
|
|
item.SetActive(false);
|
|
}
|
|
gemKeyHand.SetActive(false);
|
|
skillet.SetActive(false);
|
|
skilletEx.SetActive(false);
|
|
}
|
|
|
|
public void Update()
|
|
{
|
|
if (Input.GetKeyDown(KeyCode.Space))
|
|
{
|
|
if (hit != null )
|
|
{
|
|
GameManager.Ins.taskManager.GetGem(hit);
|
|
}
|
|
}
|
|
|
|
#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))
|
|
{
|
|
hit = handlingHit.collider.gameObject;
|
|
if (handlingHit.collider.gameObject.tag == "Puzzle")
|
|
{
|
|
puzzleId = handlingHit.collider.GetComponent<PuzzleItem>().id;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
puzzleId = -1;
|
|
hit = null;
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
public void ClickRrightTrigger()
|
|
{
|
|
if(hit==null)
|
|
return;
|
|
var curTaskId=GameManager.Ins.taskManager.curTaskId;
|
|
if (curTaskId == 0)
|
|
{
|
|
GameManager.Ins.taskManager.GetGem(hit);
|
|
}
|
|
|
|
if ( puzzleId!=-1)
|
|
{
|
|
GameManager.Ins.taskManager.GetPuzzle(puzzleId);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 合成宝石钥匙
|
|
/// </summary>
|
|
public void CreateGemKey()
|
|
{
|
|
StartCoroutine(StartGemEnd());
|
|
}
|
|
|
|
IEnumerator StartGemEnd()
|
|
{
|
|
GameManager.Ins.PlaySound2DRPC("1.13");
|
|
foreach (var item in gems)
|
|
{
|
|
item.SetActive(true);
|
|
}
|
|
yield return new WaitForSeconds(3f);
|
|
Vector3 targetLocalPos = gems[1].transform.localPosition;
|
|
gems[0].transform.DOLocalMove(targetLocalPos, 2f);
|
|
gems[2].transform.DOLocalMove(targetLocalPos, 2f).OnComplete(()=>
|
|
{
|
|
GameManager.Ins.PlaySound2DRPC("1.37");
|
|
GameManager.Ins.PlaySound2DRPC("1.14");
|
|
gemKeyHand.SetActive(true);
|
|
hand.SetActive(false);
|
|
foreach (var item in gems)
|
|
{
|
|
item.SetActive(false);
|
|
}
|
|
});
|
|
}
|
|
|
|
public void MoveGemKey(Transform target,Action cb)
|
|
{
|
|
gemKey.transform.parent = null;
|
|
gemKey.transform.DOMove(target.position, 2f).OnComplete(() =>
|
|
{
|
|
cb();
|
|
});
|
|
gemKey.transform.DORotate(new Vector3(0, -90, 90), 2f);
|
|
}
|
|
|
|
public void ChangeHand()
|
|
{
|
|
hand.SetActive(true);
|
|
_isOpenLine = true;
|
|
gemKeyHand.SetActive(false);
|
|
skillet.SetActive(false);
|
|
}
|
|
|
|
public void ChangeSkillet()
|
|
{
|
|
GameManager.Ins.PlaySound2DRPC("1.19");
|
|
_isOpenLine = false;
|
|
hand.SetActive(false);
|
|
skillet.SetActive(true);
|
|
}
|
|
|
|
public void ShowSkilletEx()
|
|
{
|
|
GameManager.Ins.PlaySound2DRPC("1.22");
|
|
skilletEx.SetActive(true);
|
|
MonoSingleton<CoroutineTaskManager>.Instance.WaitSecondTodo(() =>
|
|
{
|
|
skilletEx.SetActive(false);
|
|
},4);
|
|
}
|
|
}
|