temp
This commit is contained in:
8
Assets/Gameplay/Scripts/GameFlowMgr.meta
Normal file
8
Assets/Gameplay/Scripts/GameFlowMgr.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8025a89a5d992e44fa273cab4f2a4973
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,6 @@
|
||||
public interface IInteractable
|
||||
{/// 玩家与交互对象进行交互时调用
|
||||
void OnInteract();
|
||||
void OnEnterInteractionRange(); // 玩家进入交互范围时调用,用于显示提示
|
||||
void OnExitInteractionRange(); // 玩家离开交互范围时调用,用于隐藏提示
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9a9052ca06b0e2349a35e76092b02770
|
||||
31
Assets/Gameplay/Scripts/GameFlowMgr/GameFlowMgr.cs
Normal file
31
Assets/Gameplay/Scripts/GameFlowMgr/GameFlowMgr.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using A2W;
|
||||
using UnityEngine;
|
||||
|
||||
public class GameFlowMgr : Singleton<GameFlowMgr>
|
||||
{
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
public LevelData levelData;
|
||||
void Start()
|
||||
{
|
||||
levelData = Resources.Load<LevelData>("LevelData/LevelData");
|
||||
Debug.Log(levelData.levels.Count);
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
public void StartGame()
|
||||
{
|
||||
if (levelData.currentLevelIndex < 0)
|
||||
{
|
||||
throw new System.Exception("请选择关卡");
|
||||
}
|
||||
SceneLoader.instance?.LoadScene(levelData.levels[levelData.currentLevelIndex].sceneName);
|
||||
}
|
||||
public void completeLevel(int index)
|
||||
{
|
||||
levelData.currentLevelIndex = ++index;
|
||||
}
|
||||
}
|
||||
2
Assets/Gameplay/Scripts/GameFlowMgr/GameFlowMgr.cs.meta
Normal file
2
Assets/Gameplay/Scripts/GameFlowMgr/GameFlowMgr.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 07802e1d785f6d047aa212c442f94459
|
||||
21
Assets/Gameplay/Scripts/GameFlowMgr/InteractableObject.cs
Normal file
21
Assets/Gameplay/Scripts/GameFlowMgr/InteractableObject.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class InteractableObject : MonoBehaviour, IInteractable
|
||||
{
|
||||
public GameObject tipUI;
|
||||
public void OnEnterInteractionRange()
|
||||
{
|
||||
Debug.Log("Enter");
|
||||
}
|
||||
|
||||
public void OnExitInteractionRange()
|
||||
{
|
||||
Debug.Log("Exit");
|
||||
}
|
||||
|
||||
public void OnInteract()
|
||||
{
|
||||
GameFlowMgr.instance?.StartGame();
|
||||
Debug.Log("Interact");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a78b1d612d1525a458c45e832b7fabc1
|
||||
17
Assets/Gameplay/Scripts/GameFlowMgr/LevelData.cs
Normal file
17
Assets/Gameplay/Scripts/GameFlowMgr/LevelData.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
/// <summary>
|
||||
/// 关卡数据
|
||||
/// </summary>
|
||||
[CreateAssetMenu(fileName = "LevelData", menuName = "Scriptable Objects/LevelData")]
|
||||
public class LevelData : ScriptableObject
|
||||
{
|
||||
public int currentLevelIndex = 0;
|
||||
public List<Level> levels = new List<Level>();
|
||||
}
|
||||
[System.Serializable]
|
||||
public class Level
|
||||
{
|
||||
public string name;
|
||||
public string sceneName;
|
||||
}
|
||||
2
Assets/Gameplay/Scripts/GameFlowMgr/LevelData.cs.meta
Normal file
2
Assets/Gameplay/Scripts/GameFlowMgr/LevelData.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2140a8bde814f34479aa85224c58c135
|
||||
@@ -0,0 +1,87 @@
|
||||
// PlayerInteractController.cs
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
using UnityEngine.InputSystem.Controls;
|
||||
|
||||
public class PlayerInteractController : MonoBehaviour
|
||||
{
|
||||
// public KeyControl interactionKey = Keyboard.current.fKey; // 交互按键,默认为F
|
||||
public float interactionRange = 2f; // 交互检测范围
|
||||
public Transform interactPoint; // 交互检测的起点(通常是玩家相机或身体中心)
|
||||
|
||||
private IInteractable currentInteractable; // 当前可交互的对象
|
||||
|
||||
void Start()
|
||||
{
|
||||
StartCoroutine(PeriodicDetection());
|
||||
}
|
||||
void Update()
|
||||
{
|
||||
// 每帧检测附近的交互物
|
||||
// DetectInteractables();
|
||||
|
||||
// 如果当前有可交互物体,且玩家按下了交互键
|
||||
if (currentInteractable != null && Keyboard.current.fKey.wasPressedThisFrame)
|
||||
{
|
||||
currentInteractable.OnInteract();
|
||||
}
|
||||
}
|
||||
private IEnumerator PeriodicDetection()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
DetectInteractables(); // 你的检测逻辑
|
||||
yield return new WaitForSeconds(0.1f); // 每0.1秒检测一次
|
||||
}
|
||||
}
|
||||
void DetectInteractables()
|
||||
{
|
||||
// 使用球形检测来查找范围内的所有碰撞体
|
||||
Collider[] hitColliders = Physics.OverlapSphere(interactPoint.position, interactionRange);
|
||||
IInteractable closestInteractable = null;
|
||||
float closestDistance = float.MaxValue;
|
||||
|
||||
// 遍历所有碰撞体,找到最近的 IInteractable 对象
|
||||
foreach (var hitCollider in hitColliders)
|
||||
{
|
||||
IInteractable interactable = hitCollider.GetComponent<IInteractable>();
|
||||
if (interactable != null)
|
||||
{
|
||||
float distance = Vector3.Distance(interactPoint.position, hitCollider.transform.position);
|
||||
if (distance < closestDistance)
|
||||
{
|
||||
closestDistance = distance;
|
||||
closestInteractable = interactable;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 如果当前交互对象发生了变化
|
||||
if (closestInteractable != currentInteractable)
|
||||
{
|
||||
// 通知旧物体退出范围
|
||||
if (currentInteractable != null)
|
||||
{
|
||||
currentInteractable.OnExitInteractionRange();
|
||||
}
|
||||
// 通知新物体进入范围
|
||||
if (closestInteractable != null)
|
||||
{
|
||||
closestInteractable.OnEnterInteractionRange();
|
||||
}
|
||||
// 更新当前交互对象
|
||||
currentInteractable = closestInteractable;
|
||||
}
|
||||
}
|
||||
|
||||
// 在Scene视图中绘制交互范围,便于调试
|
||||
private void OnDrawGizmosSelected()
|
||||
{
|
||||
if (interactPoint != null)
|
||||
{
|
||||
Gizmos.color = Color.yellow;
|
||||
Gizmos.DrawWireSphere(interactPoint.position, interactionRange);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 02223bd6679dafd4cb5a95407ff5932d
|
||||
@@ -3,7 +3,7 @@ using A2W;
|
||||
|
||||
public class LaunchManager : SceneSingleton<LaunchManager>
|
||||
{
|
||||
private async void Awake()
|
||||
private async void Start()
|
||||
{
|
||||
UIManager.instance.Init();
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using A2W;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
public class LaunchPanel : UIPanel
|
||||
{
|
||||
@@ -23,8 +24,8 @@ public class LaunchPanel : UIPanel
|
||||
await UniTask.Delay(200);
|
||||
press.alpha = 1;
|
||||
|
||||
//await UniTask.WaitUntil(()=>Input.anyKeyDown);
|
||||
await UniTask.Delay(2000);
|
||||
await UniTask.WaitUntil(()=>Keyboard.current.anyKey.wasPressedThisFrame);
|
||||
// await UniTask.Delay(2000);
|
||||
|
||||
StageSelector.EnterStage("Stage1");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user