1
This commit is contained in:
@@ -9,6 +9,9 @@ public class LinerMgr : MonoSingleton<LinerMgr>
|
||||
public float height = 0.5f;
|
||||
public float arrowLength = 0.5f;
|
||||
public float speed = 1f;
|
||||
public float groundHeight = 0.25f; // 地面导航时的高度
|
||||
public float startDistance = 2f; // 箭头起始距离(相机前方)
|
||||
public float backStartDistance = 5f; // 目标在后方时,箭头起始距离(更远)
|
||||
|
||||
public GameObject arrowPrefab;
|
||||
private Vector3 target;
|
||||
@@ -50,9 +53,58 @@ public class LinerMgr : MonoSingleton<LinerMgr>
|
||||
|
||||
void UpdateArrow()
|
||||
{
|
||||
float distance = Vector3.Distance(transform.position, target);
|
||||
float radius = height / 2f + distance * distance / (8f * height);
|
||||
float diff = radius - height;
|
||||
Vector3 actualTarget = target;
|
||||
|
||||
// 统一使用地面导航模式
|
||||
Camera mainCamera = Camera.main;
|
||||
if (mainCamera == null)
|
||||
{
|
||||
mainCamera = FindObjectOfType<Camera>();
|
||||
}
|
||||
|
||||
if (mainCamera != null && m_target != null)
|
||||
{
|
||||
actualTarget = m_target.position;
|
||||
|
||||
// 计算目标相对于相机的方向
|
||||
Vector3 cameraPos = mainCamera.transform.position;
|
||||
Vector3 cameraForward = mainCamera.transform.forward;
|
||||
Vector3 toTarget = actualTarget - cameraPos;
|
||||
float distanceToTarget = toTarget.magnitude;
|
||||
Vector3 toTargetDir = toTarget.normalized;
|
||||
|
||||
// 判断目标是否在相机后方(点积小于0表示在后方)
|
||||
float dotProduct = Vector3.Dot(cameraForward, toTargetDir);
|
||||
bool isBehind = dotProduct < 0f;
|
||||
|
||||
// 计算箭头起始位置 - 始终在相机前方,这样玩家才能看到
|
||||
Vector3 startPos;
|
||||
if (isBehind)
|
||||
{
|
||||
// 目标在后方:箭头起始点在相机前方,但箭头会向后指
|
||||
// 使用更远的距离,让箭头更明显
|
||||
startPos = cameraPos + cameraForward * backStartDistance;
|
||||
}
|
||||
else
|
||||
{
|
||||
// 目标在前方或侧面:从相机前方开始,稍微偏向目标方向
|
||||
Vector3 startDir = Vector3.Slerp(cameraForward, toTargetDir, 0.3f).normalized;
|
||||
startPos = cameraPos + startDir * startDistance;
|
||||
}
|
||||
|
||||
// 设置高度为接近地面的高度(目标高度 + 地面高度偏移)
|
||||
startPos.y = actualTarget.y + groundHeight;
|
||||
transform.position = startPos;
|
||||
}
|
||||
else if (m_target != null)
|
||||
{
|
||||
// 没有相机,使用目标位置
|
||||
actualTarget = m_target.position;
|
||||
}
|
||||
|
||||
float distance = Vector3.Distance(transform.position, actualTarget);
|
||||
float radius = groundHeight / 2f + distance * distance / (8f * groundHeight);
|
||||
float diff = radius - groundHeight;
|
||||
float angle = 2f * Mathf.Acos(diff / radius);
|
||||
float length = angle * radius;
|
||||
float segmentAngle = arrowLength / radius * Mathf.Rad2Deg;
|
||||
@@ -75,9 +127,13 @@ public class LinerMgr : MonoSingleton<LinerMgr>
|
||||
arrowList[i].localRotation = Quaternion.FromToRotation(Vector3.up, pos - center);
|
||||
|
||||
}
|
||||
transform.LookAt(m_target);
|
||||
|
||||
if (m_target != null)
|
||||
{
|
||||
transform.LookAt(actualTarget);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ArrowInit(int listCount)
|
||||
{
|
||||
while (arrowList.Count < listCount)
|
||||
|
||||
@@ -20,8 +20,11 @@ public class MySingnalReceiver : MonoBehaviour,INotificationReceiver
|
||||
// SceneMgr.Instance.LoadScene(10009);
|
||||
//}
|
||||
//else
|
||||
//{ SceneMgr.Instance.LoadScene(singnal.sigParm1); }
|
||||
SceneMgr.Instance.nowSceneId = singnal.sigParm1;
|
||||
//{
|
||||
|
||||
//}
|
||||
//{ SceneMgr.Instance.LoadScene(singnal.sigParm1); }
|
||||
SceneMgr.Instance.nowSceneId = singnal.sigParm1;
|
||||
SceneMgr.Instance.LoadScene(singnal.sigParm1);
|
||||
}
|
||||
else if (singnal.sigName == "CheckPosition") //<2F><><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using BigSpace.XRCore.Base;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Video;
|
||||
|
||||
|
||||
namespace BigSpace.XRCore.GameMode
|
||||
@@ -15,17 +16,111 @@ namespace BigSpace.XRCore.GameMode
|
||||
public bool IsOffline => _isOffline;
|
||||
public int NextSceneId = 10000;
|
||||
|
||||
[SerializeField] private VideoPlayer videoPlayer;
|
||||
private bool initialized;
|
||||
private bool videoHidden;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
//Application.targetFrameRate = 30;
|
||||
SceneMgr.Instance.nowSceneId = NextSceneId;
|
||||
InitGameMode();
|
||||
StartCoroutine(PlayVideoThenInitGameMode());
|
||||
|
||||
//PicoApi.InitEnterpriseService();
|
||||
}
|
||||
|
||||
private IEnumerator PlayVideoThenInitGameMode()
|
||||
{
|
||||
if (videoPlayer == null && !TryGetComponent(out videoPlayer))
|
||||
{
|
||||
Debug.Log("[GameModeMgr] No VideoPlayer, init directly.");
|
||||
InitGameMode();
|
||||
yield break;
|
||||
}
|
||||
|
||||
videoPlayer.loopPointReached += OnVideoFinished;
|
||||
videoPlayer.errorReceived += OnVideoError;
|
||||
Debug.Log("[GameModeMgr] Video events registered, preparing.");
|
||||
|
||||
if (!videoPlayer.isPrepared)
|
||||
{
|
||||
videoPlayer.Prepare();
|
||||
while (!videoPlayer.isPrepared)
|
||||
{
|
||||
yield return null;
|
||||
}
|
||||
}
|
||||
|
||||
Debug.Log("[GameModeMgr] Video prepared, play.");
|
||||
videoPlayer.Play();
|
||||
|
||||
float waitToStart = 2f;
|
||||
float elapsed = 0f;
|
||||
while (!videoPlayer.isPlaying && elapsed < waitToStart)
|
||||
{
|
||||
elapsed += Time.deltaTime;
|
||||
yield return null;
|
||||
}
|
||||
|
||||
float maxDuration = videoPlayer.clip != null ? (float)videoPlayer.clip.length + 1f : 5f;
|
||||
elapsed = 0f;
|
||||
while (videoPlayer.isPlaying && elapsed < maxDuration)
|
||||
{
|
||||
elapsed += Time.deltaTime;
|
||||
yield return null;
|
||||
}
|
||||
|
||||
Debug.Log("[GameModeMgr] Video finished by coroutine.");
|
||||
InitGameMode();
|
||||
}
|
||||
|
||||
private void OnVideoFinished(VideoPlayer _)
|
||||
{
|
||||
Debug.Log("[GameModeMgr] Video finished event.");
|
||||
InitGameMode();
|
||||
}
|
||||
|
||||
private void OnVideoError(VideoPlayer _, string __)
|
||||
{
|
||||
Debug.LogWarning("[GameModeMgr] Video error, init directly.");
|
||||
InitGameMode();
|
||||
}
|
||||
|
||||
private void HideVideoPlayer()
|
||||
{
|
||||
if (videoHidden || videoPlayer == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
videoHidden = true;
|
||||
try
|
||||
{
|
||||
if (videoPlayer.isPlaying)
|
||||
{
|
||||
videoPlayer.Stop();
|
||||
}
|
||||
videoPlayer.gameObject.SetActive(false);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
private void InitGameMode()
|
||||
{
|
||||
if (initialized)
|
||||
{
|
||||
return;
|
||||
}
|
||||
initialized = true;
|
||||
HideVideoPlayer();
|
||||
if (videoPlayer != null)
|
||||
{
|
||||
videoPlayer.loopPointReached -= OnVideoFinished;
|
||||
videoPlayer.errorReceived -= OnVideoError;
|
||||
}
|
||||
|
||||
_gameMode = new OfflineMode();
|
||||
_gameMode.Initialize();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user