60 lines
1.9 KiB
C#
60 lines
1.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using Cielonos.Core.Interaction;
|
|
using Sirenix.OdinInspector;
|
|
using UnityEngine;
|
|
using UnityEngine.SceneManagement;
|
|
|
|
namespace Cielonos.MainGame.Interactions
|
|
{
|
|
public partial class SceneTeleportationSite : InteractableObjectBase
|
|
{
|
|
[ValueDropdown("GetAllSceneNames")]
|
|
public string targetSceneName;
|
|
|
|
private AsyncOperation _asyncSceneLoad;
|
|
|
|
private void Start()
|
|
{
|
|
_asyncSceneLoad = SceneManager.LoadSceneAsync(targetSceneName);
|
|
_asyncSceneLoad.allowSceneActivation = false;
|
|
}
|
|
|
|
protected override void InitializeChoices()
|
|
{
|
|
choices.Add(new InteractionChoice("Teleport", Teleport));
|
|
}
|
|
|
|
private void Teleport()
|
|
{
|
|
if (targetSceneName != "")
|
|
{
|
|
// 场景跳转前,打包玩家当前所有的背包装备与槽位配置状态,存入中介单例传输
|
|
if (MainGameManager.Player != null)
|
|
{
|
|
PlayerInventorySaveData currentSaveData = MainGameManager.Player.inventorySc.GetSaveData();
|
|
InfoTransistor.SetInfo("PlayerSaveData", currentSaveData);
|
|
}
|
|
|
|
Debug.Log($"[SceneTeleportationSite] Teleporting to scene: {targetSceneName}");
|
|
_asyncSceneLoad.allowSceneActivation = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
public partial class SceneTeleportationSite
|
|
{
|
|
private List<string> GetAllSceneNames()
|
|
{
|
|
List<string> sceneNames = new List<string>();
|
|
int sceneCount = SceneManager.sceneCountInBuildSettings;
|
|
for (int i = 0; i < sceneCount; i++)
|
|
{
|
|
string path = SceneUtility.GetScenePathByBuildIndex(i);
|
|
string name = System.IO.Path.GetFileNameWithoutExtension(path);
|
|
sceneNames.Add(name);
|
|
}
|
|
return sceneNames;
|
|
}
|
|
}
|
|
} |