using System.Collections; using System.Collections.Generic; using UnityEngine; public class PlayerTrigger : MonoBehaviour { private Vector3 m_LastPos; //public GameObject MovePanel; private bool m_IsDown; private string m_Dir; [Range(0.1f, 10f)] public float Speed = 0.4f; public List MovePoints { get; set; } private int m_MoveIndex; private void Start() { m_LastPos = Vector3.zero; //MovePanel.SetActive(false); m_IsDown = false; m_MoveIndex = 0; MovePoints = new List(); } private void LateUpdate() { /* if (API_GSXR_Slam.GSXR_Get_Head() != null) { transform.position = new Vector3(API_GSXR_Slam.GSXR_Get_Head().position.x, transform.position.y, API_GSXR_Slam.GSXR_Get_Head().position.z); transform.eulerAngles = new Vector3(0, API_GSXR_Slam.GSXR_Get_Head().eulerAngles.y, 0); if (GameManager.Instance.IsRuning) { //MovePanel.SetActive(true); //MovePanel.transform.localEulerAngles = new Vector3(0, transform.localEulerAngles.y, 0); //MovePanel.transform.localPosition = transform.localPosition + transform.forward * 0.8f + new Vector3(0, -1f, 0); if (Vector3.Distance(m_LastPos, transform.position) < 0.1f) { return; } m_LastPos = transform.position; float x = transform.localPosition.x / GameManager.Instance.MapSize.x * GameManager.Instance.WebMapSize.x; float y = transform.localPosition.z / GameManager.Instance.MapSize.y * GameManager.Instance.WebMapSize.y; var pos = new Vector3(x, -y, 0); HttpSocket.Instance.SendIpToPointPos(pos, (message) => { //Debug.Log(message); }); } } */ if (OpenXRCamera.Instance.head != null) { transform.position = new Vector3(OpenXRCamera.Instance.head.position.x, OpenXRCamera.Instance.head.position.y, OpenXRCamera.Instance.head.position.z); transform.eulerAngles = new Vector3(0, OpenXRCamera.Instance.head.eulerAngles.y, 0); if (GameManager.Instance.IsRuning) { //MovePanel.SetActive(true); //MovePanel.transform.localEulerAngles = new Vector3(0, transform.localEulerAngles.y, 0); //MovePanel.transform.localPosition = transform.localPosition + transform.forward * 0.8f + new Vector3(0, -1f, 0); if (Vector3.Distance(m_LastPos, transform.position) < 0.1f) { return; } m_LastPos = transform.position; float x = transform.localPosition.x / GameManager.Instance.MapSize.x * GameManager.Instance.WebMapSize.x; float y = transform.localPosition.z / GameManager.Instance.MapSize.y * GameManager.Instance.WebMapSize.y; var pos = new Vector3(x, -y, 0); HttpSocket.Instance.SendIpToPointPos(pos, (message) => { //Debug.Log(message); }); } } } private void OnTriggerEnter(Collider other) { if (other.gameObject.tag == "TriggerBox") { GameManager.Instance.OnColliderTriggerEnter(other); Debug.Log("OnTriggerEnter " + other.name); } } private void OnTriggerExit(Collider other) { if (other.gameObject.tag == "TriggerBox") { GameManager.Instance.OnColliderTriggerExit(other); Debug.Log("OnTriggerExit " + other.name); } } #region Player Move public void PlayerMove(string dir) { m_IsDown = true; m_Dir = dir; StartCoroutine(CalMove()); } public void StopMove() { m_IsDown = false; //StopCoroutine(CalMove()); StopAllCoroutines(); m_Dir = null; } IEnumerator CalMove() { while (m_IsDown) { //yield return new WaitForSeconds(0.05f); yield return new WaitForFixedUpdate(); Vector3 pos = Vector3.zero; switch (m_Dir) { case "Front": //API_GSXR_Slam.GSXR_Get_Head().Translate(Vector3.forward * Time.deltaTime * Speed); pos = transform.forward * Time.deltaTime * Speed; break; case "After": //API_GSXR_Slam.GSXR_Get_Head().Translate(Vector3.back * Time.deltaTime * Speed); pos = -transform.forward * Time.deltaTime * Speed; break; case "Left": //API_GSXR_Slam.GSXR_Get_Head().Translate(Vector3.left * Time.deltaTime * Speed); pos = -transform.right * Time.deltaTime * Speed; break; case "Right": //API_GSXR_Slam.GSXR_Get_Head().Translate(Vector3.right * Time.deltaTime * Speed); pos = transform.right * Time.deltaTime * Speed; break; default: break; } var position = transform.localPosition + pos; position = transform.parent.TransformPoint(position); Debug.Log(position); #if UNITY_EDITOR API_GSXR_Slam.GSXR_Get_Head().position = position; #elif UNITY_ANDROID API_GSXR_Slam.GSXR_Get_Head().position = position; #endif Debug.Log("m_Dir:" + m_Dir.ToString() + "=====" + API_GSXR_Slam.GSXR_Get_Head().localPosition.ToString()); } } public void MoveNextPoint() { if (MovePoints.Count > 0) { m_MoveIndex++; m_MoveIndex = m_MoveIndex < MovePoints.Count ? m_MoveIndex : 0; var position = transform.parent.TransformPoint(new Vector3(MovePoints[m_MoveIndex].x, transform.localPosition.y, MovePoints[m_MoveIndex].z)); #if UNITY_EDITOR API_GSXR_Slam.GSXR_Get_Head().position = position; #elif UNITY_ANDROID API_GSXR_Slam.GSXR_Get_Head().position = position; #endif } Debug.Log("m_MoveIndex:" + m_MoveIndex.ToString() + "=====" + API_GSXR_Slam.GSXR_Get_Head().localPosition.ToString()); Debug.Log(transform.position); } #endregion }