125 lines
2.8 KiB
C#
125 lines
2.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using DragonLi.Core;
|
|
using UnityEngine;
|
|
using UnityEngine.XR;
|
|
|
|
/// <summary>
|
|
/// 手类型
|
|
/// </summary>
|
|
public enum HandType
|
|
{
|
|
Left,
|
|
Right
|
|
}
|
|
|
|
/// <summary>
|
|
/// 手状态
|
|
/// </summary>
|
|
public enum HandState
|
|
{
|
|
/// <summary>
|
|
/// 空手
|
|
/// </summary>
|
|
Empty,
|
|
/// <summary>
|
|
/// 有武器
|
|
/// </summary>
|
|
HaveWeapon
|
|
}
|
|
|
|
public class Player : MonoBehaviour
|
|
{
|
|
public Transform LeftHand;
|
|
public Transform RightHand;
|
|
public Transform Aim;
|
|
|
|
public GameObject rightHandPre;
|
|
|
|
public Collider Collider;
|
|
public LayerMask AimLayer;
|
|
|
|
public HandState handState = HandState.Empty;
|
|
|
|
#if UNITY_EDITOR
|
|
[DisplayOnly]
|
|
#endif
|
|
public Vector3 AimVec = Vector3.zero;
|
|
|
|
public void Start()
|
|
{
|
|
|
|
GameLocal.Ins.self = this;
|
|
CreateHands();
|
|
}
|
|
|
|
public void Update()
|
|
{
|
|
Transform mainCamera = GameLocal.Ins.MRCamera.transform;
|
|
Transform aim = GameLocal.Ins.Aim.transform;
|
|
Transform leftControl = GameLocal.Ins.MRLeftControl;
|
|
Transform rightControl = GameLocal.Ins.MRRightControl;
|
|
|
|
// 同步相机
|
|
transform.position = mainCamera.position;
|
|
transform.rotation = mainCamera.rotation;
|
|
|
|
// 同步注视点
|
|
Aim.position = aim.position;
|
|
Aim.rotation = aim.rotation;
|
|
|
|
#if !UNITY_EDITOR && UNITY_ANDROID && PICO
|
|
// 同步手柄
|
|
LeftHand.transform.position = leftControl.position;
|
|
LeftHand.transform.rotation = leftControl.rotation;
|
|
|
|
RightHand.transform.position = rightControl.position;
|
|
RightHand.transform.rotation = rightControl.rotation;
|
|
#endif
|
|
|
|
|
|
if (Input.GetKeyDown(KeyCode.Q))
|
|
{
|
|
|
|
}
|
|
|
|
// 发射射线
|
|
if (Physics.Raycast(transform.position, transform.forward, out RaycastHit handlingHit, 20f, AimLayer))
|
|
{
|
|
AimVec = handlingHit.point;
|
|
}
|
|
else
|
|
{
|
|
AimVec = Aim.position;
|
|
}
|
|
}
|
|
|
|
public void CreateHands()
|
|
{
|
|
//LeftHand leftHand = Instantiate(LeftHandPre).GetComponent<LeftHand>();
|
|
RightHand rightHand = Instantiate(rightHandPre).GetComponent<RightHand>();
|
|
}
|
|
|
|
public void OnTriggerEnter(Collider other)
|
|
{
|
|
// 开始游戏
|
|
if (other.tag == "GameStartDoor")
|
|
{
|
|
Debug.Log("触碰开始");
|
|
other.gameObject.GetComponent<Collider>().enabled = false;
|
|
other.gameObject.SetActive(false);
|
|
Destroy(other.gameObject);
|
|
if (GameManager.Ins.taskManager.curTaskId != 4)
|
|
{
|
|
GameManager.Ins.GameStart();
|
|
}
|
|
else
|
|
{
|
|
GameManager.Ins.StartDance();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|