diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-03-01 09:36:29 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-03-01 09:36:29 +0800 |
| commit | c2b26c0491886b99f422e830cd9ec1637a4ddc2e (patch) | |
| tree | ec5a2b8aaf2e4568bd7ad59aa812864915bc6bdc /Assets/Scripts/Core | |
firstmaster
Diffstat (limited to 'Assets/Scripts/Core')
| -rw-r--r-- | Assets/Scripts/Core/LoadGroup.cs | 12 | ||||
| -rw-r--r-- | Assets/Scripts/Core/LoadGroup.cs.meta | 2 | ||||
| -rw-r--r-- | Assets/Scripts/Core/Loader.cs | 73 | ||||
| -rw-r--r-- | Assets/Scripts/Core/Loader.cs.meta | 2 | ||||
| -rw-r--r-- | Assets/Scripts/Core/WCGame.Core.asmdef | 14 | ||||
| -rw-r--r-- | Assets/Scripts/Core/WCGame.Core.asmdef.meta | 7 |
6 files changed, 110 insertions, 0 deletions
diff --git a/Assets/Scripts/Core/LoadGroup.cs b/Assets/Scripts/Core/LoadGroup.cs new file mode 100644 index 0000000..7381c5d --- /dev/null +++ b/Assets/Scripts/Core/LoadGroup.cs @@ -0,0 +1,12 @@ + +using System.Collections.Generic; +using UnityEngine; + +namespace Core +{ + [CreateAssetMenu(fileName = "LoadGroup", menuName = "WCGame/LoadGroup")] + public class LoadGroup : ScriptableObject + { + public List<GameObject> GameObjects; + } +} diff --git a/Assets/Scripts/Core/LoadGroup.cs.meta b/Assets/Scripts/Core/LoadGroup.cs.meta new file mode 100644 index 0000000..2e81310 --- /dev/null +++ b/Assets/Scripts/Core/LoadGroup.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: c6a85e5be7398304e8084f1e1b140abf
\ No newline at end of file diff --git a/Assets/Scripts/Core/Loader.cs b/Assets/Scripts/Core/Loader.cs new file mode 100644 index 0000000..23cf216 --- /dev/null +++ b/Assets/Scripts/Core/Loader.cs @@ -0,0 +1,73 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.Events; + +namespace Core +{ + public class Loader : MonoBehaviour + { + public static Loader Current; + + public List<LoadGroup> loadGroups; + public UnityEvent onLoaded; + + private bool _started; + + +#if UNITY_EDITOR + [HideInInspector] public int objectCount; + [HideInInspector] public int loadedObjectCount; + + private void OnGUI() + { + GUILayout.Label($"Loaded: {loadedObjectCount / objectCount * 100}% ({loadedObjectCount}/{objectCount})"); + } +#endif + + private void Update() + { + if (!_started) + _started = true; + } + + private void Awake() + { +#if UNITY_EDITOR + foreach (var loadGroup in loadGroups) + objectCount += loadGroup.GameObjects.Count; +#endif + if (Current == null) + Current = this; + + StartCoroutine(Load()); + } + + private IEnumerator Load() + { + yield return new WaitUntil(() => _started); + foreach (var loadGroup in loadGroups) + { + if (loadGroups == null) + continue; + foreach (var loadGroupGameObject in loadGroup.GameObjects) + { + Instantiate(loadGroupGameObject); +#if UNITY_EDITOR + loadedObjectCount++; +#endif + yield return null; + } + } + onLoaded.Invoke(); + Destroy(gameObject); + } + + private void OnDestroy() + { + if (Current == this) + Current = null; + } + } +} diff --git a/Assets/Scripts/Core/Loader.cs.meta b/Assets/Scripts/Core/Loader.cs.meta new file mode 100644 index 0000000..8cd6a76 --- /dev/null +++ b/Assets/Scripts/Core/Loader.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 57b520943bbc8914d80e8523d908b4c2
\ No newline at end of file diff --git a/Assets/Scripts/Core/WCGame.Core.asmdef b/Assets/Scripts/Core/WCGame.Core.asmdef new file mode 100644 index 0000000..6218367 --- /dev/null +++ b/Assets/Scripts/Core/WCGame.Core.asmdef @@ -0,0 +1,14 @@ +{ + "name": "WCGame.Core", + "rootNamespace": "", + "references": [], + "includePlatforms": [], + "excludePlatforms": [], + "allowUnsafeCode": false, + "overrideReferences": false, + "precompiledReferences": [], + "autoReferenced": true, + "defineConstraints": [], + "versionDefines": [], + "noEngineReferences": false +}
\ No newline at end of file diff --git a/Assets/Scripts/Core/WCGame.Core.asmdef.meta b/Assets/Scripts/Core/WCGame.Core.asmdef.meta new file mode 100644 index 0000000..234ed6b --- /dev/null +++ b/Assets/Scripts/Core/WCGame.Core.asmdef.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: cdb8b834ac5fd5b4f9c5c43cc62e0cfb +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: |
