app.hypergames.hypersdk 1.1.11 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/Editor/Scripts/Setup/HyperSDKInstaller.cs +1 -1
- package/Editor/Scripts/Utils/{SceneReferenceDrawer.cs → HyperSceneReferenceDrawer.cs} +14 -6
- package/Editor/Scripts/Utils/HyperSceneReferenceDrawer.cs.meta +2 -0
- package/Editor/Scripts/Windows/HyperCoreSettingsWindow.cs +2 -5
- package/Editor/Scripts/Windows/HyperGameContentWindow.cs +1 -4
- package/Editor/Scripts/Windows/HyperSettingsWindow.cs +31 -10
- package/HyperLoader.unity +1 -1
- package/Runtime/Internal/ScriptableObjects/HyperGameContentConfig.cs +3 -3
- package/Runtime/Internal/Utils/JsonCompressor.cs +0 -1
- package/Runtime/Resources/HyperGameContentConfig.asset +6 -0
- package/Runtime/Shared/Utils/HyperSceneReference.cs +111 -0
- package/Runtime/Shared/Utils/HyperSceneReference.cs.meta +2 -0
- package/package.json +5 -12
- package/Editor/Scripts/Utils/SceneReferenceDrawer.cs.meta +0 -2
- package/Runtime/Internal/Utils/SceneReferenceExtensions.cs +0 -32
- package/Runtime/Internal/Utils/SceneReferenceExtensions.cs.meta +0 -2
- package/Runtime/Shared/Utils/SceneReference.cs +0 -95
- package/Runtime/Shared/Utils/SceneReference.cs.meta +0 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
## [1.2.1](https://github.com/mvmhyper/hyper-sdk/compare/v1.2.0...v1.2.1) (2025-11-26)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* stabilize scene references, installer overwrite, and resources path helper ([c27499e](https://github.com/mvmhyper/hyper-sdk/commit/c27499e525712d1fcf2f42e30813013e9610e254))
|
|
7
|
+
|
|
8
|
+
# [1.2.0](https://github.com/mvmhyper/hyper-sdk/compare/v1.1.11...v1.2.0) (2025-11-26)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Features
|
|
12
|
+
|
|
13
|
+
* move HyperLoader scene to root and refactor SDK utilities naming ([4407493](https://github.com/mvmhyper/hyper-sdk/commit/4407493b8ad8edb86a1c21f9ba9701f350755197))
|
|
14
|
+
|
|
1
15
|
## [1.1.11](https://github.com/mvmhyper/hyper-sdk/compare/v1.1.10...v1.1.11) (2025-11-26)
|
|
2
16
|
|
|
3
17
|
|
|
@@ -13,7 +13,7 @@ namespace Hyper.Editor
|
|
|
13
13
|
{
|
|
14
14
|
private const string InstallerPrefsKey = "HyperSDKInstaller.LastInstalledVersion";
|
|
15
15
|
private const string HyperLoaderSceneRelativePath = "HyperLoader.unity";
|
|
16
|
-
private const string HyperLoaderSceneDestination = "Assets/HyperSDK/
|
|
16
|
+
private const string HyperLoaderSceneDestination = "Assets/HyperSDK/HyperLoader.unity";
|
|
17
17
|
private const string WebGLTemplateRelativePath = "WebGLTemplates/HyperLoader";
|
|
18
18
|
private const string WebGLTemplateDestination = "Assets/WebGLTemplates/HyperLoader";
|
|
19
19
|
private const string HyperGameContentConfigRelativePath = "Runtime/Resources/HyperGameContentConfig.asset";
|
|
@@ -6,19 +6,22 @@ using Hyper.Shared;
|
|
|
6
6
|
namespace Hyper.Editor
|
|
7
7
|
{
|
|
8
8
|
/// <summary>
|
|
9
|
-
/// Custom property drawer for
|
|
9
|
+
/// Custom property drawer for HyperSceneReference that allows drag-and-drop scene assignment.
|
|
10
10
|
/// </summary>
|
|
11
|
-
[CustomPropertyDrawer(typeof(
|
|
12
|
-
public class
|
|
11
|
+
[CustomPropertyDrawer(typeof(HyperSceneReference))]
|
|
12
|
+
public class HyperSceneReferenceDrawer : PropertyDrawer
|
|
13
13
|
{
|
|
14
14
|
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
|
15
15
|
{
|
|
16
16
|
EditorGUI.BeginProperty(position, label, property);
|
|
17
17
|
|
|
18
18
|
SerializedProperty guidProperty = property.FindPropertyRelative("sceneGUID");
|
|
19
|
-
|
|
19
|
+
SerializedProperty pathProperty = property.FindPropertyRelative("scenePath");
|
|
20
|
+
SerializedProperty nameProperty = property.FindPropertyRelative("sceneName");
|
|
21
|
+
|
|
22
|
+
if (guidProperty == null || pathProperty == null || nameProperty == null)
|
|
20
23
|
{
|
|
21
|
-
EditorGUI.LabelField(position, label.text, "
|
|
24
|
+
EditorGUI.LabelField(position, label.text, "HyperSceneReference: Invalid property structure");
|
|
22
25
|
EditorGUI.EndProperty();
|
|
23
26
|
return;
|
|
24
27
|
}
|
|
@@ -44,18 +47,23 @@ namespace Hyper.Editor
|
|
|
44
47
|
false
|
|
45
48
|
) as SceneAsset;
|
|
46
49
|
|
|
47
|
-
// Update
|
|
50
|
+
// Update serialized values if scene changed
|
|
48
51
|
if (newScene != currentScene)
|
|
49
52
|
{
|
|
50
53
|
if (newScene != null)
|
|
51
54
|
{
|
|
52
55
|
string newPath = AssetDatabase.GetAssetPath(newScene);
|
|
53
56
|
string newGUID = AssetDatabase.AssetPathToGUID(newPath);
|
|
57
|
+
string newName = System.IO.Path.GetFileNameWithoutExtension(newPath);
|
|
54
58
|
guidProperty.stringValue = newGUID;
|
|
59
|
+
pathProperty.stringValue = newPath;
|
|
60
|
+
nameProperty.stringValue = newName;
|
|
55
61
|
}
|
|
56
62
|
else
|
|
57
63
|
{
|
|
58
64
|
guidProperty.stringValue = string.Empty;
|
|
65
|
+
pathProperty.stringValue = string.Empty;
|
|
66
|
+
nameProperty.stringValue = string.Empty;
|
|
59
67
|
}
|
|
60
68
|
}
|
|
61
69
|
|
|
@@ -78,14 +78,11 @@ namespace Hyper.Editor
|
|
|
78
78
|
private void CreateSettingsAsset()
|
|
79
79
|
{
|
|
80
80
|
// Ensure Resources folder exists
|
|
81
|
-
|
|
82
|
-
{
|
|
83
|
-
AssetDatabase.CreateFolder("Assets", "Resources");
|
|
84
|
-
}
|
|
81
|
+
HyperSettingsWindow.EnsureResourcesFolderExists();
|
|
85
82
|
|
|
86
83
|
// Create settings asset
|
|
87
84
|
var newSettings = CreateInstance<HyperSDKSettings>();
|
|
88
|
-
string assetPath = $"{HyperConstants.
|
|
85
|
+
string assetPath = $"{HyperConstants.SETTINGS_ASSET_PATH}";
|
|
89
86
|
|
|
90
87
|
AssetDatabase.CreateAsset(newSettings, assetPath);
|
|
91
88
|
AssetDatabase.SaveAssets();
|
|
@@ -76,10 +76,7 @@ namespace Hyper.Editor
|
|
|
76
76
|
private void CreateConfigAsset()
|
|
77
77
|
{
|
|
78
78
|
// Ensure Resources folder exists
|
|
79
|
-
|
|
80
|
-
{
|
|
81
|
-
AssetDatabase.CreateFolder("Assets", "Resources");
|
|
82
|
-
}
|
|
79
|
+
HyperSettingsWindow.EnsureResourcesFolderExists();
|
|
83
80
|
|
|
84
81
|
// Create config asset
|
|
85
82
|
var newConfig = CreateInstance<HyperGameContentConfig>();
|
|
@@ -109,13 +109,10 @@ namespace Hyper.Editor
|
|
|
109
109
|
|
|
110
110
|
private void CreateSettingsAsset()
|
|
111
111
|
{
|
|
112
|
-
|
|
113
|
-
{
|
|
114
|
-
AssetDatabase.CreateFolder("Assets", "Resources");
|
|
115
|
-
}
|
|
112
|
+
EnsureResourcesFolderExists();
|
|
116
113
|
|
|
117
114
|
var newSettings = CreateInstance<HyperSDKSettings>();
|
|
118
|
-
string assetPath = $"{HyperConstants.
|
|
115
|
+
string assetPath = $"{HyperConstants.SETTINGS_ASSET_PATH}";
|
|
119
116
|
|
|
120
117
|
AssetDatabase.CreateAsset(newSettings, assetPath);
|
|
121
118
|
AssetDatabase.SaveAssets();
|
|
@@ -129,13 +126,10 @@ namespace Hyper.Editor
|
|
|
129
126
|
|
|
130
127
|
private void CreateConfigAsset()
|
|
131
128
|
{
|
|
132
|
-
|
|
133
|
-
{
|
|
134
|
-
AssetDatabase.CreateFolder("Assets", "Resources");
|
|
135
|
-
}
|
|
129
|
+
EnsureResourcesFolderExists();
|
|
136
130
|
|
|
137
131
|
var newConfig = CreateInstance<HyperGameContentConfig>();
|
|
138
|
-
string assetPath = $"{HyperConstants.
|
|
132
|
+
string assetPath = $"{HyperConstants.GAME_CONTENT_ASSET_PATH}";
|
|
139
133
|
|
|
140
134
|
AssetDatabase.CreateAsset(newConfig, assetPath);
|
|
141
135
|
AssetDatabase.SaveAssets();
|
|
@@ -287,6 +281,33 @@ namespace Hyper.Editor
|
|
|
287
281
|
}
|
|
288
282
|
|
|
289
283
|
#endregion
|
|
284
|
+
internal static void EnsureResourcesFolderExists()
|
|
285
|
+
{
|
|
286
|
+
if (AssetDatabase.IsValidFolder(HyperConstants.RESOURCES_FOLDER_PATH))
|
|
287
|
+
{
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
string[] segments = HyperConstants.RESOURCES_FOLDER_PATH.Split('/');
|
|
292
|
+
if (segments.Length == 0)
|
|
293
|
+
{
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
string currentPath = segments[0]; // "Assets"
|
|
298
|
+
for (int i = 1; i < segments.Length; i++)
|
|
299
|
+
{
|
|
300
|
+
string folderName = segments[i];
|
|
301
|
+
string nextPath = $"{currentPath}/{folderName}";
|
|
302
|
+
|
|
303
|
+
if (!AssetDatabase.IsValidFolder(nextPath))
|
|
304
|
+
{
|
|
305
|
+
AssetDatabase.CreateFolder(currentPath, folderName);
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
currentPath = nextPath;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
290
311
|
}
|
|
291
312
|
}
|
|
292
313
|
#endif
|
package/HyperLoader.unity
CHANGED
|
@@ -885,7 +885,7 @@ GameObject:
|
|
|
885
885
|
m_Component:
|
|
886
886
|
- component: {fileID: 1064166296}
|
|
887
887
|
m_Layer: 0
|
|
888
|
-
m_Name:
|
|
888
|
+
m_Name: __HyperSDK_BuildMarker_638997386571830226
|
|
889
889
|
m_TagString: Untagged
|
|
890
890
|
m_Icon: {fileID: 0}
|
|
891
891
|
m_NavMeshLayer: 0
|
|
@@ -13,7 +13,7 @@ namespace Hyper.Internal
|
|
|
13
13
|
[Header("Battle Mode")]
|
|
14
14
|
[Tooltip("BATTLE mode → Gameplay Scene: go straight into the match (no menu) after the loading screen.")]
|
|
15
15
|
[Space(2)]
|
|
16
|
-
public
|
|
16
|
+
public HyperSceneReference GameScene;
|
|
17
17
|
|
|
18
18
|
#endregion
|
|
19
19
|
|
|
@@ -22,7 +22,7 @@ namespace Hyper.Internal
|
|
|
22
22
|
[Header("Practice Mode")]
|
|
23
23
|
[Tooltip("PRACTICE mode → Menu Scene: open a menu after the loading screen so players can choose stage/options.")]
|
|
24
24
|
[Space(2)]
|
|
25
|
-
public
|
|
25
|
+
public HyperSceneReference PracticeScene;
|
|
26
26
|
|
|
27
27
|
public PracticeSceneType PracticeSceneType = PracticeSceneType.Menu;
|
|
28
28
|
|
|
@@ -39,7 +39,7 @@ namespace Hyper.Internal
|
|
|
39
39
|
[Header("Scene Transitions")]
|
|
40
40
|
[Tooltip("Optional: Scene used for transitions or loading between other scenes.")]
|
|
41
41
|
[Space(2)]
|
|
42
|
-
public
|
|
42
|
+
public HyperSceneReference TransitionScene;
|
|
43
43
|
|
|
44
44
|
/// <summary>
|
|
45
45
|
/// Returns true if transition scene exists.
|
|
@@ -14,9 +14,15 @@ MonoBehaviour:
|
|
|
14
14
|
m_EditorClassIdentifier:
|
|
15
15
|
GameScene:
|
|
16
16
|
sceneGUID:
|
|
17
|
+
scenePath:
|
|
18
|
+
sceneName:
|
|
17
19
|
PracticeScene:
|
|
18
20
|
sceneGUID:
|
|
21
|
+
scenePath:
|
|
22
|
+
sceneName:
|
|
19
23
|
PracticeSceneType: 0
|
|
20
24
|
TransitionScene:
|
|
21
25
|
sceneGUID:
|
|
26
|
+
scenePath:
|
|
27
|
+
sceneName:
|
|
22
28
|
gamePosterSprite: {fileID: 0}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
using System;
|
|
2
|
+
using UnityEngine;
|
|
3
|
+
|
|
4
|
+
namespace Hyper.Shared
|
|
5
|
+
{
|
|
6
|
+
/// <summary>
|
|
7
|
+
/// Serializable scene reference that stores scene GUID and provides scene name access.
|
|
8
|
+
/// Allows drag-and-drop scene assignment in the inspector without external dependencies.
|
|
9
|
+
/// </summary>
|
|
10
|
+
[Serializable]
|
|
11
|
+
public class HyperSceneReference : ISerializationCallbackReceiver
|
|
12
|
+
{
|
|
13
|
+
[SerializeField]
|
|
14
|
+
private string sceneGUID;
|
|
15
|
+
|
|
16
|
+
[SerializeField]
|
|
17
|
+
private string scenePath;
|
|
18
|
+
|
|
19
|
+
[SerializeField]
|
|
20
|
+
private string sceneName;
|
|
21
|
+
|
|
22
|
+
/// <summary>
|
|
23
|
+
/// Gets the scene name stored at serialization time.
|
|
24
|
+
/// </summary>
|
|
25
|
+
public string SceneName
|
|
26
|
+
{
|
|
27
|
+
get
|
|
28
|
+
{
|
|
29
|
+
#if UNITY_EDITOR
|
|
30
|
+
// In editor, keep sceneName in sync with GUID/path for clarity
|
|
31
|
+
if (!string.IsNullOrEmpty(sceneGUID))
|
|
32
|
+
{
|
|
33
|
+
string assetPath = UnityEditor.AssetDatabase.GUIDToAssetPath(sceneGUID);
|
|
34
|
+
if (!string.IsNullOrEmpty(assetPath))
|
|
35
|
+
{
|
|
36
|
+
string fileName = System.IO.Path.GetFileNameWithoutExtension(assetPath);
|
|
37
|
+
if (!string.IsNullOrEmpty(fileName))
|
|
38
|
+
{
|
|
39
|
+
sceneName = fileName;
|
|
40
|
+
scenePath = assetPath;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
#endif
|
|
45
|
+
return sceneName;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/// <summary>
|
|
50
|
+
/// Gets the scene path stored at serialization time.
|
|
51
|
+
/// </summary>
|
|
52
|
+
public string ScenePath => scenePath;
|
|
53
|
+
|
|
54
|
+
/// <summary>
|
|
55
|
+
/// Gets the scene GUID.
|
|
56
|
+
/// </summary>
|
|
57
|
+
public string GUID => sceneGUID;
|
|
58
|
+
|
|
59
|
+
/// <summary>
|
|
60
|
+
/// Returns true if the scene reference has valid serialized data.
|
|
61
|
+
/// </summary>
|
|
62
|
+
public bool IsValid
|
|
63
|
+
{
|
|
64
|
+
get
|
|
65
|
+
{
|
|
66
|
+
return !string.IsNullOrEmpty(sceneGUID) &&
|
|
67
|
+
!string.IsNullOrEmpty(sceneName);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/// <summary>
|
|
72
|
+
/// Implicit conversion to string for backward compatibility.
|
|
73
|
+
/// Returns the stored scene name.
|
|
74
|
+
/// </summary>
|
|
75
|
+
public static implicit operator string(HyperSceneReference sceneRef)
|
|
76
|
+
{
|
|
77
|
+
return sceneRef?.SceneName;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/// <summary>
|
|
81
|
+
/// Returns the scene name, or empty string if invalid.
|
|
82
|
+
/// </summary>
|
|
83
|
+
public override string ToString()
|
|
84
|
+
{
|
|
85
|
+
return SceneName ?? string.Empty;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
#if UNITY_EDITOR
|
|
89
|
+
public void OnBeforeSerialize()
|
|
90
|
+
{
|
|
91
|
+
if (!string.IsNullOrEmpty(sceneGUID))
|
|
92
|
+
{
|
|
93
|
+
string assetPath = UnityEditor.AssetDatabase.GUIDToAssetPath(sceneGUID);
|
|
94
|
+
if (!string.IsNullOrEmpty(assetPath))
|
|
95
|
+
{
|
|
96
|
+
scenePath = assetPath;
|
|
97
|
+
sceneName = System.IO.Path.GetFileNameWithoutExtension(assetPath);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
public void OnAfterDeserialize()
|
|
103
|
+
{
|
|
104
|
+
}
|
|
105
|
+
#else
|
|
106
|
+
public void OnBeforeSerialize() { }
|
|
107
|
+
public void OnAfterDeserialize() { }
|
|
108
|
+
#endif
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "app.hypergames.hypersdk",
|
|
3
|
-
"version": "1.1
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"displayName": "HyperSDK",
|
|
5
|
-
"description": "Official Unity SDK for
|
|
5
|
+
"description": "Official Unity SDK for Hyper: multiplayer battles, leaderboards, deterministic RNG, session management, tutorials, and WebGL optimizations for production-ready games.",
|
|
6
6
|
"unity": "6000.0",
|
|
7
7
|
"unityRelease": "0b5",
|
|
8
8
|
"keywords": [
|
|
@@ -25,21 +25,14 @@
|
|
|
25
25
|
"email": "info@mvm.gg",
|
|
26
26
|
"url": "https://mvm.gg/"
|
|
27
27
|
},
|
|
28
|
-
"licensesUrl": "https://
|
|
29
|
-
"changelogUrl": "https://
|
|
30
|
-
"documentationUrl": "https://
|
|
28
|
+
"licensesUrl": "https://mvm.gg/",
|
|
29
|
+
"changelogUrl": "https://mvm.gg/",
|
|
30
|
+
"documentationUrl": "https://mvm.gg/",
|
|
31
31
|
"repository": {
|
|
32
32
|
"type": "git",
|
|
33
33
|
"url": "https://github.com/mvmhyper/hyper-sdk.git",
|
|
34
34
|
"revision": "v0.1.0"
|
|
35
35
|
},
|
|
36
|
-
"samples": [
|
|
37
|
-
{
|
|
38
|
-
"displayName": "Math Rush Sample Game",
|
|
39
|
-
"description": "Complete example game demonstrating HyperSDK integration including score submission, deterministic RNG, game modes, and UI integration. Perfect starting point for understanding how to use HyperSDK in your own games.",
|
|
40
|
-
"path": "Samples~/MathRushSample"
|
|
41
|
-
}
|
|
42
|
-
],
|
|
43
36
|
"dependencies": {
|
|
44
37
|
"com.unity.nuget.newtonsoft-json": "3.2.1"
|
|
45
38
|
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
// using Eflatun.SceneReference;
|
|
2
|
-
|
|
3
|
-
// namespace Hyper.Internal
|
|
4
|
-
// {
|
|
5
|
-
// /// <summary>
|
|
6
|
-
// /// Extension methods for Eflatun.SceneReference to simplify scene name retrieval.
|
|
7
|
-
// /// </summary>
|
|
8
|
-
// internal static class SceneReferenceExtensions
|
|
9
|
-
// {
|
|
10
|
-
// /// <summary>
|
|
11
|
-
// /// Gets the scene name if the scene reference is valid and in a regular state.
|
|
12
|
-
// /// </summary>
|
|
13
|
-
// /// <param name="sceneRef">The scene reference to validate</param>
|
|
14
|
-
// /// <returns>The scene name if valid, null otherwise</returns>
|
|
15
|
-
// public static string GetValidSceneName(this SceneReference sceneRef)
|
|
16
|
-
// {
|
|
17
|
-
// return (sceneRef != null && sceneRef.State == SceneReferenceState.Regular)
|
|
18
|
-
// ? sceneRef.Name
|
|
19
|
-
// : null;
|
|
20
|
-
// }
|
|
21
|
-
|
|
22
|
-
// /// <summary>
|
|
23
|
-
// /// Checks if a scene reference is valid and usable.
|
|
24
|
-
// /// </summary>
|
|
25
|
-
// /// <param name="sceneRef">The scene reference to check</param>
|
|
26
|
-
// /// <returns>True if the scene reference is valid and in regular state</returns>
|
|
27
|
-
// public static bool IsValid(this SceneReference sceneRef)
|
|
28
|
-
// {
|
|
29
|
-
// return sceneRef != null && sceneRef.State == SceneReferenceState.Regular;
|
|
30
|
-
// }
|
|
31
|
-
// }
|
|
32
|
-
// }
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
using System;
|
|
2
|
-
using UnityEngine;
|
|
3
|
-
|
|
4
|
-
namespace Hyper.Shared
|
|
5
|
-
{
|
|
6
|
-
/// <summary>
|
|
7
|
-
/// Serializable scene reference that stores scene GUID and provides scene name access.
|
|
8
|
-
/// Allows drag-and-drop scene assignment in the inspector without external dependencies.
|
|
9
|
-
/// </summary>
|
|
10
|
-
[Serializable]
|
|
11
|
-
public class SceneReference
|
|
12
|
-
{
|
|
13
|
-
[SerializeField]
|
|
14
|
-
private string sceneGUID;
|
|
15
|
-
|
|
16
|
-
/// <summary>
|
|
17
|
-
/// Gets the scene name from the GUID, or null if invalid.
|
|
18
|
-
/// </summary>
|
|
19
|
-
public string SceneName
|
|
20
|
-
{
|
|
21
|
-
get
|
|
22
|
-
{
|
|
23
|
-
if (string.IsNullOrEmpty(sceneGUID))
|
|
24
|
-
{
|
|
25
|
-
return null;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
#if UNITY_EDITOR
|
|
29
|
-
string assetPath = UnityEditor.AssetDatabase.GUIDToAssetPath(sceneGUID);
|
|
30
|
-
if (string.IsNullOrEmpty(assetPath))
|
|
31
|
-
{
|
|
32
|
-
return null;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// Extract scene name from path (e.g., "Assets/Scenes/MyScene.unity" -> "MyScene")
|
|
36
|
-
string sceneName = System.IO.Path.GetFileNameWithoutExtension(assetPath);
|
|
37
|
-
return sceneName;
|
|
38
|
-
#else
|
|
39
|
-
// In builds, we can't resolve GUIDs, so return null
|
|
40
|
-
return null;
|
|
41
|
-
#endif
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/// <summary>
|
|
46
|
-
/// Gets the scene GUID.
|
|
47
|
-
/// </summary>
|
|
48
|
-
public string GUID => sceneGUID;
|
|
49
|
-
|
|
50
|
-
/// <summary>
|
|
51
|
-
/// Returns true if the scene reference is valid (has a GUID and resolves to a scene).
|
|
52
|
-
/// </summary>
|
|
53
|
-
public bool IsValid
|
|
54
|
-
{
|
|
55
|
-
get
|
|
56
|
-
{
|
|
57
|
-
if (string.IsNullOrEmpty(sceneGUID))
|
|
58
|
-
{
|
|
59
|
-
return false;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
#if UNITY_EDITOR
|
|
63
|
-
string assetPath = UnityEditor.AssetDatabase.GUIDToAssetPath(sceneGUID);
|
|
64
|
-
if (string.IsNullOrEmpty(assetPath))
|
|
65
|
-
{
|
|
66
|
-
return false;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
// Check if it's actually a scene file
|
|
70
|
-
return assetPath.EndsWith(".unity", System.StringComparison.OrdinalIgnoreCase);
|
|
71
|
-
#else
|
|
72
|
-
// In builds, assume valid if GUID exists (can't verify without AssetDatabase)
|
|
73
|
-
return true;
|
|
74
|
-
#endif
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/// <summary>
|
|
79
|
-
/// Implicit conversion to string for backward compatibility.
|
|
80
|
-
/// </summary>
|
|
81
|
-
public static implicit operator string(SceneReference sceneRef)
|
|
82
|
-
{
|
|
83
|
-
return sceneRef?.SceneName;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/// <summary>
|
|
87
|
-
/// Returns the scene name, or empty string if invalid.
|
|
88
|
-
/// </summary>
|
|
89
|
-
public override string ToString()
|
|
90
|
-
{
|
|
91
|
-
return SceneName ?? string.Empty;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|