This commit is contained in:
Даниил Заикин
2026-06-17 20:44:53 +03:00
parent 9d153773c2
commit b133e7c656
1880 changed files with 244545 additions and 0 deletions
@@ -0,0 +1,39 @@
using UnityEngine;
using UnityEngine.SceneManagement;
public class BootstrapSceneLoader : MonoBehaviour
{
private const string RequestedScenePathKey = "SceneBootstrapLoader.RequestedScenePath";
[SerializeField] private string fallbackSceneName = "";
private async void Start()
{
string requestedScenePath = GetRequestedScenePath();
string sceneToLoad = !string.IsNullOrWhiteSpace(requestedScenePath)
? System.IO.Path.GetFileNameWithoutExtension(requestedScenePath)
: fallbackSceneName;
if (string.IsNullOrWhiteSpace(sceneToLoad))
{
Debug.LogWarning("BootstrapSceneLoader: No requested scene and no fallback scene set.");
return;
}
Scene activeScene = SceneManager.GetActiveScene();
if (activeScene.name == sceneToLoad)
return;
await SceneManager.LoadSceneAsync(sceneToLoad, LoadSceneMode.Single);
}
private string GetRequestedScenePath()
{
#if UNITY_EDITOR
return UnityEditor.EditorPrefs.GetString(RequestedScenePathKey, string.Empty);
#else
return string.Empty;
#endif
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: f1b12cb32bc61bd4790e02afa40e4ccb
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: bfddc0e472a69314abbea24e871e5207
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,85 @@
#if UNITY_EDITOR
using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine;
[InitializeOnLoad]
public static class SceneBootstrapLoader
{
private const string EnabledKey = "SceneBootstrapLoader.Enabled";
private const string BootstrapScenePathKey = "SceneBootstrapLoader.BootstrapScenePath";
private const string RequestedScenePathKey = "SceneBootstrapLoader.RequestedScenePath";
public static bool Enabled
{
get => EditorPrefs.GetBool(EnabledKey, false);
set => EditorPrefs.SetBool(EnabledKey, value);
}
public static string BootstrapScenePath
{
get => EditorPrefs.GetString(BootstrapScenePathKey, string.Empty);
set => EditorPrefs.SetString(BootstrapScenePathKey, value ?? string.Empty);
}
public static string RequestedScenePath
{
get => EditorPrefs.GetString(RequestedScenePathKey, string.Empty);
set => EditorPrefs.SetString(RequestedScenePathKey, value ?? string.Empty);
}
static SceneBootstrapLoader()
{
EditorApplication.playModeStateChanged += OnPlayModeStateChanged;
}
private static void OnPlayModeStateChanged(PlayModeStateChange state)
{
if (!Enabled)
{
EditorSceneManager.playModeStartScene = null;
return;
}
switch (state)
{
case PlayModeStateChange.ExitingEditMode:
PreparePlayModeStartScene();
break;
case PlayModeStateChange.EnteredEditMode:
CleanupAfterPlayMode();
break;
}
}
private static void PreparePlayModeStartScene()
{
string bootstrapPath = BootstrapScenePath;
if (string.IsNullOrWhiteSpace(bootstrapPath))
{
Debug.LogWarning("SceneBootstrapLoader: Bootstrap scene is not set.");
EditorSceneManager.playModeStartScene = null;
return;
}
var bootstrapScene = AssetDatabase.LoadAssetAtPath<SceneAsset>(bootstrapPath);
if (bootstrapScene == null)
{
Debug.LogWarning($"SceneBootstrapLoader: Bootstrap scene not found at path: {bootstrapPath}");
EditorSceneManager.playModeStartScene = null;
return;
}
string currentScenePath = UnityEngine.SceneManagement.SceneManager.GetActiveScene().path;
RequestedScenePath = currentScenePath;
EditorSceneManager.playModeStartScene = bootstrapScene;
}
private static void CleanupAfterPlayMode()
{
EditorSceneManager.playModeStartScene = null;
}
}
#endif
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 14654515991486d4790469be18a9123b
@@ -0,0 +1,47 @@
#if UNITY_EDITOR
using UnityEditor;
using UnityEngine;
public class SceneBootstrapLoaderWindow : EditorWindow
{
[MenuItem("Tools/Scenes/Bootstrap Loader")]
public static void ShowWindow()
{
var window = GetWindow<SceneBootstrapLoaderWindow>("Bootstrap Loader");
window.minSize = new Vector2(420, 110);
}
private void OnGUI()
{
GUILayout.Space(8);
SceneBootstrapLoader.Enabled = EditorGUILayout.Toggle(
new GUIContent("Enabled", "Always start Play Mode from bootstrap scene"),
SceneBootstrapLoader.Enabled
);
var currentAsset = string.IsNullOrWhiteSpace(SceneBootstrapLoader.BootstrapScenePath)
? null
: AssetDatabase.LoadAssetAtPath<SceneAsset>(SceneBootstrapLoader.BootstrapScenePath);
var newAsset = (SceneAsset)EditorGUILayout.ObjectField(
new GUIContent("Bootstrap Scene", "Scene used as playModeStartScene"),
currentAsset,
typeof(SceneAsset),
false
);
string newPath = newAsset != null ? AssetDatabase.GetAssetPath(newAsset) : string.Empty;
if (newPath != SceneBootstrapLoader.BootstrapScenePath)
SceneBootstrapLoader.BootstrapScenePath = newPath;
GUILayout.Space(8);
EditorGUILayout.HelpBox(
"When enabled, Play Mode always starts from the selected bootstrap scene. " +
"The path of the scene you launched from is saved and can be loaded by bootstrap at runtime.",
MessageType.Info
);
}
}
#endif
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 3525cdb25bffe9f44abd3dd1a7e44aec