aboutsummaryrefslogtreecommitdiff
path: root/Assets/Scripts
diff options
context:
space:
mode:
Diffstat (limited to 'Assets/Scripts')
-rw-r--r--Assets/Scripts/FragmentManager.cs10
-rw-r--r--Assets/Scripts/FragmentRequire.cs3
-rw-r--r--Assets/Scripts/PlayerPosition.cs4
3 files changed, 15 insertions, 2 deletions
diff --git a/Assets/Scripts/FragmentManager.cs b/Assets/Scripts/FragmentManager.cs
index 3bac110..74e5a58 100644
--- a/Assets/Scripts/FragmentManager.cs
+++ b/Assets/Scripts/FragmentManager.cs
@@ -6,6 +6,14 @@ public class FragmentManager : MonoBehaviour
{
private static readonly HashSet<string> LoadedSceneNames = new();
+ // 关键:在每次进入 Play Mode(且不重启域)时,重置静态集合
+ [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
+ private static void ResetStaticState()
+ {
+ LoadedSceneNames.Clear();
+ // 如果有其他静态字段,也在这里一并重置
+ }
+
/// <summary>
/// 刷新场景需要列表(基于场景名称)
/// </summary>
@@ -91,6 +99,7 @@ public class FragmentManager : MonoBehaviour
{
foreach (var sceneName in sceneNames)
{
+ Debug.Log("Unloading: " + sceneName);
var asyncOp = SceneManager.UnloadSceneAsync(sceneName);
if (asyncOp != null)
{
@@ -115,6 +124,7 @@ public class FragmentManager : MonoBehaviour
{
foreach (var sceneName in sceneNames)
{
+ Debug.Log("Loading: " + sceneName);
var asyncOp = SceneManager.LoadSceneAsync(sceneName, LoadSceneMode.Additive);
if (asyncOp != null)
{
diff --git a/Assets/Scripts/FragmentRequire.cs b/Assets/Scripts/FragmentRequire.cs
index 71ce602..cfe4120 100644
--- a/Assets/Scripts/FragmentRequire.cs
+++ b/Assets/Scripts/FragmentRequire.cs
@@ -20,6 +20,7 @@ public class FragmentRequire : MonoBehaviour
private void OnTriggerEnter(Collider other)
{
+ Debug.Log("Sync!");
var sceneName = new List<string>();
foreach (SceneAsset sceneAsset in requiredScenes)
sceneName.Add(sceneAsset.name);
@@ -39,7 +40,7 @@ public class FragmentRequire : MonoBehaviour
var ts = Vector3.one;
var size = new Vector3(cs.x * ts.x, cs.y * ts.y, cs.z * ts.z);
- Gizmos.color = new Color(1f, 0.18f, 0.29f, 0.5f);
+ Gizmos.color = new Color(1f, 0.18f, 0.29f, 0.25f);
Gizmos.matrix = transform.localToWorldMatrix;
Gizmos.DrawCube(_boxCollider.center, size);
}
diff --git a/Assets/Scripts/PlayerPosition.cs b/Assets/Scripts/PlayerPosition.cs
index 9b839f8..baf4e66 100644
--- a/Assets/Scripts/PlayerPosition.cs
+++ b/Assets/Scripts/PlayerPosition.cs
@@ -23,7 +23,9 @@ public class PlayerPosition : MonoBehaviour
while (true)
{
yield return new WaitUntil(() => _playerLocomotion == null);
- _playerLocomotion = GetComponent<PlayerLocomotion>();
+ var list = Resources.FindObjectsOfTypeAll<PlayerLocomotion>();
+ if (list.Length > 0)
+ _playerLocomotion = list[0];
yield return new WaitForSeconds(5f);
}
}