From 0cc1ec386671081bda87344c7a6b289c4abb071b Mon Sep 17 00:00:00 2001 From: MuHua-123 <136542559+MuHua-123@users.noreply.github.com> Date: Mon, 24 Mar 2025 17:36:33 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0aa=E5=8A=A0=E8=BD=BD=E5=8C=85?= =?UTF-8?q?=E5=92=8C=E9=87=8D=E5=81=9A=E6=A0=87=E7=AD=BE=E7=B3=BB=E7=BB=9F?= =?UTF-8?q?=E5=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../LabelFollow/Script/StandardLabel.cs | 28 ++++---- Packages/AALoading/Runtime.meta | 8 +++ Packages/AALoading/Runtime/AACatalog.cs | 64 +++++++++++++++++ Packages/AALoading/Runtime/AACatalog.cs.meta | 11 +++ .../AALoading/Runtime/AACatalogToScene.cs | 57 +++++++++++++++ .../Runtime/AACatalogToScene.cs.meta | 11 +++ Packages/AALoading/Runtime/AALabel.cs | 65 +++++++++++++++++ Packages/AALoading/Runtime/AALabel.cs.meta | 11 +++ Packages/AALoading/Runtime/AAScene.cs | 68 ++++++++++++++++++ Packages/AALoading/Runtime/AAScene.cs.meta | 11 +++ .../AALoading/Runtime/MuHua.AALoading.asmdef | 17 +++++ .../Runtime/MuHua.AALoading.asmdef.meta | 7 ++ Packages/AALoading/package.json | 14 ++++ Packages/AALoading/package.json.meta | 7 ++ Packages/{LabelFollow => FollowTag}/README.md | 0 .../{LabelFollow => FollowTag}/README.md.meta | 0 .../{LabelFollow => FollowTag}/Runtime.meta | 0 .../FollowTag/Runtime/FollowController.cs | 37 ++++++++++ .../Runtime/FollowController.cs.meta} | 0 Packages/FollowTag/Runtime/FollowTag.cs | 19 +++++ .../Runtime/FollowTag.cs.meta} | 0 .../Runtime/MuHua.FollowTag.asmdef} | 2 +- .../Runtime/MuHua.FollowTag.asmdef.meta} | 0 .../Samples~/Sample.unitypackage | Bin .../Samples~/Sample.unitypackage.meta | 0 .../{LabelFollow => FollowTag}/package.json | 4 +- .../package.json.meta | 0 .../LabelFollow/Runtime/LabelController.cs | 34 --------- Packages/LabelFollow/Runtime/LabelFollower.cs | 21 ------ Packages/packages-lock.json | 33 ++++++++- 30 files changed, 453 insertions(+), 76 deletions(-) create mode 100644 Packages/AALoading/Runtime.meta create mode 100644 Packages/AALoading/Runtime/AACatalog.cs create mode 100644 Packages/AALoading/Runtime/AACatalog.cs.meta create mode 100644 Packages/AALoading/Runtime/AACatalogToScene.cs create mode 100644 Packages/AALoading/Runtime/AACatalogToScene.cs.meta create mode 100644 Packages/AALoading/Runtime/AALabel.cs create mode 100644 Packages/AALoading/Runtime/AALabel.cs.meta create mode 100644 Packages/AALoading/Runtime/AAScene.cs create mode 100644 Packages/AALoading/Runtime/AAScene.cs.meta create mode 100644 Packages/AALoading/Runtime/MuHua.AALoading.asmdef create mode 100644 Packages/AALoading/Runtime/MuHua.AALoading.asmdef.meta create mode 100644 Packages/AALoading/package.json create mode 100644 Packages/AALoading/package.json.meta rename Packages/{LabelFollow => FollowTag}/README.md (100%) rename Packages/{LabelFollow => FollowTag}/README.md.meta (100%) rename Packages/{LabelFollow => FollowTag}/Runtime.meta (100%) create mode 100644 Packages/FollowTag/Runtime/FollowController.cs rename Packages/{LabelFollow/Runtime/LabelController.cs.meta => FollowTag/Runtime/FollowController.cs.meta} (100%) create mode 100644 Packages/FollowTag/Runtime/FollowTag.cs rename Packages/{LabelFollow/Runtime/LabelFollower.cs.meta => FollowTag/Runtime/FollowTag.cs.meta} (100%) rename Packages/{LabelFollow/Runtime/MuHua.LabelFollow.asmdef => FollowTag/Runtime/MuHua.FollowTag.asmdef} (90%) rename Packages/{LabelFollow/Runtime/MuHua.LabelFollow.asmdef.meta => FollowTag/Runtime/MuHua.FollowTag.asmdef.meta} (100%) rename Packages/{LabelFollow => FollowTag}/Samples~/Sample.unitypackage (100%) rename Packages/{LabelFollow => FollowTag}/Samples~/Sample.unitypackage.meta (100%) rename Packages/{LabelFollow => FollowTag}/package.json (82%) rename Packages/{LabelFollow => FollowTag}/package.json.meta (100%) delete mode 100644 Packages/LabelFollow/Runtime/LabelController.cs delete mode 100644 Packages/LabelFollow/Runtime/LabelFollower.cs diff --git a/Assets/ModuleMuHua/LabelFollow/Script/StandardLabel.cs b/Assets/ModuleMuHua/LabelFollow/Script/StandardLabel.cs index 781c490..496cdc2 100644 --- a/Assets/ModuleMuHua/LabelFollow/Script/StandardLabel.cs +++ b/Assets/ModuleMuHua/LabelFollow/Script/StandardLabel.cs @@ -3,22 +3,18 @@ using System.Collections.Generic; using UnityEngine; using MuHua; -namespace MuHua.Sample -{ - public class StandardLabel : MonoBehaviour - { - public GameObject labelPrefab; - public Vector3 offset = new Vector3(0, 1, 0); - private GameObject labelObject; +namespace MuHua.Sample { + public class StandardLabel : MonoBehaviour { + public GameObject labelPrefab; + public Vector3 offset = new Vector3(0, 1, 0); + private GameObject labelObject; - void Start() - { - labelObject = LabelController.CreateLabel(transform, labelPrefab, offset); - } - void OnDestroy() - { - if (labelObject != null) { Destroy(labelObject); } - } - } + void Start() { + // labelObject = FollowerController.CreateLabel(transform, labelPrefab, offset); + } + void OnDestroy() { + if (labelObject != null) { Destroy(labelObject); } + } + } } diff --git a/Packages/AALoading/Runtime.meta b/Packages/AALoading/Runtime.meta new file mode 100644 index 0000000..ba8a86b --- /dev/null +++ b/Packages/AALoading/Runtime.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 3699f8709aed43a46bb5220a7124e92b +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/AALoading/Runtime/AACatalog.cs b/Packages/AALoading/Runtime/AACatalog.cs new file mode 100644 index 0000000..c3439a4 --- /dev/null +++ b/Packages/AALoading/Runtime/AACatalog.cs @@ -0,0 +1,64 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Threading.Tasks; +using UnityEngine; +using UnityEngine.AddressableAssets; +using UnityEngine.AddressableAssets.ResourceLocators; +using UnityEngine.ResourceManagement.AsyncOperations; + +namespace MuHua { + /// + /// 加载可寻址资源目录 + /// + public class AACatalog { + public readonly string filePath; + public Action OnProgress; + public Action OnError; + public Action OnComplete; + + /// 加载可寻址资源目录 + public AACatalog(string filePath, Action OnComplete = null) { + this.filePath = filePath; + this.OnComplete = OnComplete; + } + /// 获取异步句柄 + public AsyncOperationHandle Handle() { + return Addressables.LoadContentCatalogAsync(filePath, true); + } + /// 加载目录 + public async void Load() => await ALoad(); + /// 加载目录 + public async Task ALoad() { + AsyncOperationHandle handle = Handle(); + if (handle.Status == AsyncOperationStatus.Failed) { + OnError?.Invoke($"无法加载资源目录!({filePath})"); return; + } + while (!handle.IsDone) { + float downloadProgress = handle.GetDownloadStatus().Percent; + float loadProgress = handle.PercentComplete; + float totalProgress = (downloadProgress + loadProgress) / 2.0f; + // Debug.Log($"下载进度: {downloadProgress * 100}% , 加载进度: {loadProgress * 100}% , 总进度: {totalProgress * 100}%"); + OnProgress?.Invoke(totalProgress); + await Task.Delay(100); + } + OnComplete?.Invoke(); + } + /// 加载目录 + public IEnumerator ILoad() { + AsyncOperationHandle handle = Handle(); + if (handle.Status == AsyncOperationStatus.Failed) { + OnError?.Invoke($"无法加载资源目录!({filePath})"); + yield break; + } + while (!handle.IsDone) { + float downloadProgress = handle.GetDownloadStatus().Percent; + float loadProgress = handle.PercentComplete; + float totalProgress = (downloadProgress + loadProgress) / 2.0f; + OnProgress?.Invoke(totalProgress); + yield return new WaitForEndOfFrame(); + } + OnComplete?.Invoke(); + } + } +} \ No newline at end of file diff --git a/Packages/AALoading/Runtime/AACatalog.cs.meta b/Packages/AALoading/Runtime/AACatalog.cs.meta new file mode 100644 index 0000000..eba6bb4 --- /dev/null +++ b/Packages/AALoading/Runtime/AACatalog.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: cdf535680c5435444845cfa205c9619f +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/AALoading/Runtime/AACatalogToScene.cs b/Packages/AALoading/Runtime/AACatalogToScene.cs new file mode 100644 index 0000000..365fdbb --- /dev/null +++ b/Packages/AALoading/Runtime/AACatalogToScene.cs @@ -0,0 +1,57 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Threading.Tasks; +using UnityEngine; +using UnityEngine.AddressableAssets; +using UnityEngine.SceneManagement; + +namespace MuHua { + /// + /// 从目录加载场景 + /// + public class AACatalogToScene { + public enum Progress { Catalog, Label, Scene } + public readonly string filePath; + public readonly string sceneName; + public readonly LoadSceneMode loadSceneMode; + public readonly bool activateOnLoad; + public Action OnProgress; + public Action OnError; + public Action OnComplete; + + /// 加载可寻址资源目录 + public AACatalogToScene(string filePath, string sceneName, LoadSceneMode loadSceneMode = LoadSceneMode.Single, bool activateOnLoad = true) { + this.filePath = filePath; + this.sceneName = sceneName; + this.loadSceneMode = loadSceneMode; + this.activateOnLoad = activateOnLoad; + } + /// 从目录加载场景 + public async void Load() => await ALoad(); + /// 从目录加载场景 + public async Task ALoad() { + AACatalog catalog = new AACatalog(filePath); + catalog.OnProgress = (value) => { OnProgress?.Invoke(value, Progress.Catalog); }; + catalog.OnError = OnError; + await catalog.ALoad(); + AAScene aaScene = new AAScene(sceneName, loadSceneMode, activateOnLoad); + aaScene.OnProgress = (value) => { OnProgress?.Invoke(value, Progress.Scene); }; + aaScene.OnError = OnError; + aaScene.OnComplete = OnComplete; + await aaScene.ALoad(); + } + /// 从目录加载场景 + public IEnumerator ILoad() { + AACatalog catalog = new AACatalog(filePath); + catalog.OnProgress = (value) => { OnProgress?.Invoke(value, Progress.Catalog); }; + catalog.OnError = OnError; + yield return catalog.ILoad(); + AAScene aaScene = new AAScene(sceneName, loadSceneMode, activateOnLoad); + aaScene.OnProgress = (value) => { OnProgress?.Invoke(value, Progress.Scene); }; + aaScene.OnError = OnError; + aaScene.OnComplete = OnComplete; + yield return aaScene.ILoad(); + } + } +} \ No newline at end of file diff --git a/Packages/AALoading/Runtime/AACatalogToScene.cs.meta b/Packages/AALoading/Runtime/AACatalogToScene.cs.meta new file mode 100644 index 0000000..70a1379 --- /dev/null +++ b/Packages/AALoading/Runtime/AACatalogToScene.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c8003e83f422c6e4797a12c63bf25406 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/AALoading/Runtime/AALabel.cs b/Packages/AALoading/Runtime/AALabel.cs new file mode 100644 index 0000000..35e7744 --- /dev/null +++ b/Packages/AALoading/Runtime/AALabel.cs @@ -0,0 +1,65 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Threading.Tasks; +using UnityEngine; +using UnityEngine.AddressableAssets; +using UnityEngine.AddressableAssets.ResourceLocators; +using UnityEngine.ResourceManagement.AsyncOperations; + +namespace MuHua { + /// + /// 按标签加载可寻址资源 + /// + public class AALabel { + public readonly string label; + public Action OnProgress; + public Action OnError; + public Action OnComplete; + public T result; + + /// 按标签加载可寻址资源 + public AALabel(string label, Action OnComplete = null) { + this.label = label; + this.OnComplete = OnComplete; + } + /// 获取异步句柄 + public AsyncOperationHandle Handle() { + return Addressables.LoadAssetAsync(label); + } + /// 加载资源 + public async void Load() => await ALoad(); + /// 加载资源 + public async Task ALoad() { + AsyncOperationHandle handle = Handle(); + if (handle.Status == AsyncOperationStatus.Failed) { + OnError?.Invoke($"无法加载资源!(label={label} , type={typeof(T)})"); return; + } + while (!handle.IsDone) { + float downloadProgress = handle.GetDownloadStatus().Percent; + float loadProgress = handle.PercentComplete; + float totalProgress = (downloadProgress + loadProgress) / 2.0f; + // Debug.Log($"下载进度: {downloadProgress * 100}% , 加载进度: {loadProgress * 100}% , 总进度: {totalProgress * 100}%"); + OnProgress?.Invoke(totalProgress); + await Task.Delay(100); + } + OnComplete?.Invoke(handle.Result); + } + /// 加载资源 + public IEnumerator ILoad() { + AsyncOperationHandle handle = Handle(); + if (handle.Status == AsyncOperationStatus.Failed) { + OnError?.Invoke($"无法加载资源!(label={label} , type={typeof(T)})"); yield break; + } + while (!handle.IsDone) { + float downloadProgress = handle.GetDownloadStatus().Percent; + float loadProgress = handle.PercentComplete; + float totalProgress = (downloadProgress + loadProgress) / 2.0f; + OnProgress?.Invoke(totalProgress); + yield return new WaitForEndOfFrame(); + } + result = handle.Result; + OnComplete?.Invoke(handle.Result); + } + } +} \ No newline at end of file diff --git a/Packages/AALoading/Runtime/AALabel.cs.meta b/Packages/AALoading/Runtime/AALabel.cs.meta new file mode 100644 index 0000000..b5fa4c2 --- /dev/null +++ b/Packages/AALoading/Runtime/AALabel.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 05c642602f45beb4391c7dbbd6b78968 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/AALoading/Runtime/AAScene.cs b/Packages/AALoading/Runtime/AAScene.cs new file mode 100644 index 0000000..83cdb7d --- /dev/null +++ b/Packages/AALoading/Runtime/AAScene.cs @@ -0,0 +1,68 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Threading.Tasks; +using UnityEngine; +using UnityEngine.AddressableAssets; +using UnityEngine.AddressableAssets.ResourceLocators; +using UnityEngine.ResourceManagement.AsyncOperations; +using UnityEngine.ResourceManagement.ResourceProviders; +using UnityEngine.SceneManagement; + +namespace MuHua { + /// + /// 加载可寻址场景 + /// + public class AAScene { + public readonly string name; + public readonly LoadSceneMode loadSceneMode; + public readonly bool activateOnLoad; + public Action OnProgress; + public Action OnError; + public Action OnComplete; + + /// 加载可寻址场景 + public AAScene(string name, LoadSceneMode loadSceneMode = LoadSceneMode.Single, bool activateOnLoad = true) { + this.name = name; + this.loadSceneMode = loadSceneMode; + this.activateOnLoad = activateOnLoad; + } + /// 获取异步句柄 + public AsyncOperationHandle Handle() { + return Addressables.LoadSceneAsync(name, loadSceneMode, activateOnLoad); + } + /// 加载场景 + public async void Load() => await ALoad(); + /// 加载场景 + public async Task ALoad() { + AsyncOperationHandle handle = Handle(); + if (handle.Status == AsyncOperationStatus.Failed) { + OnError?.Invoke($"无法加载场景!({name})"); return; + } + while (!handle.IsDone) { + float downloadProgress = handle.GetDownloadStatus().Percent; + float loadProgress = handle.PercentComplete; + float totalProgress = (downloadProgress + loadProgress) / 2.0f; + // Debug.Log($"下载进度: {downloadProgress * 100}% , 加载进度: {loadProgress * 100}% , 总进度: {totalProgress * 100}%"); + OnProgress?.Invoke(totalProgress); + await Task.Delay(100); + } + OnComplete?.Invoke(); + } + /// 加载场景 + public IEnumerator ILoad() { + AsyncOperationHandle handle = Handle(); + if (handle.Status == AsyncOperationStatus.Failed) { + OnError?.Invoke($"无法加载场景!({name})"); yield break; + } + while (!handle.IsDone) { + float downloadProgress = handle.GetDownloadStatus().Percent; + float loadProgress = handle.PercentComplete; + float totalProgress = (downloadProgress + loadProgress) / 2.0f; + OnProgress?.Invoke(totalProgress); + yield return new WaitForEndOfFrame(); + } + OnComplete?.Invoke(); + } + } +} diff --git a/Packages/AALoading/Runtime/AAScene.cs.meta b/Packages/AALoading/Runtime/AAScene.cs.meta new file mode 100644 index 0000000..0295906 --- /dev/null +++ b/Packages/AALoading/Runtime/AAScene.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 68519b916d961c745aeba6680a8cafe3 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/AALoading/Runtime/MuHua.AALoading.asmdef b/Packages/AALoading/Runtime/MuHua.AALoading.asmdef new file mode 100644 index 0000000..2215dfb --- /dev/null +++ b/Packages/AALoading/Runtime/MuHua.AALoading.asmdef @@ -0,0 +1,17 @@ +{ + "name": "MuHua.AALoading", + "rootNamespace": "", + "references": [ + "GUID:9e24947de15b9834991c9d8411ea37cf", + "GUID:84651a3751eca9349aac36a66bba901b" + ], + "includePlatforms": [], + "excludePlatforms": [], + "allowUnsafeCode": false, + "overrideReferences": false, + "precompiledReferences": [], + "autoReferenced": true, + "defineConstraints": [], + "versionDefines": [], + "noEngineReferences": false +} \ No newline at end of file diff --git a/Packages/AALoading/Runtime/MuHua.AALoading.asmdef.meta b/Packages/AALoading/Runtime/MuHua.AALoading.asmdef.meta new file mode 100644 index 0000000..e7157b2 --- /dev/null +++ b/Packages/AALoading/Runtime/MuHua.AALoading.asmdef.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 26f33ddf2c81134458ea0d2283ffaaaa +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/AALoading/package.json b/Packages/AALoading/package.json new file mode 100644 index 0000000..dfa1a8e --- /dev/null +++ b/Packages/AALoading/package.json @@ -0,0 +1,14 @@ +{ + "name": "muhua-aaloading", + "version": "1.0.0", + "displayName": "MuHua AALoading", + "description": "\u534f\u7a0b\u548c\u5f02\u6b65\u5b9e\u73b0\u52a0\u8f7daa\u8d44\u6e90", + "author": { + "name": "MuHua", + "email": "muhua233@qq.com" + }, + "type": "tool", + "dependencies": { + "com.unity.addressables": "1.21.21" + } +} \ No newline at end of file diff --git a/Packages/AALoading/package.json.meta b/Packages/AALoading/package.json.meta new file mode 100644 index 0000000..7008986 --- /dev/null +++ b/Packages/AALoading/package.json.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 03fe4d2014c6ea3488b135e4f4898c14 +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/LabelFollow/README.md b/Packages/FollowTag/README.md similarity index 100% rename from Packages/LabelFollow/README.md rename to Packages/FollowTag/README.md diff --git a/Packages/LabelFollow/README.md.meta b/Packages/FollowTag/README.md.meta similarity index 100% rename from Packages/LabelFollow/README.md.meta rename to Packages/FollowTag/README.md.meta diff --git a/Packages/LabelFollow/Runtime.meta b/Packages/FollowTag/Runtime.meta similarity index 100% rename from Packages/LabelFollow/Runtime.meta rename to Packages/FollowTag/Runtime.meta diff --git a/Packages/FollowTag/Runtime/FollowController.cs b/Packages/FollowTag/Runtime/FollowController.cs new file mode 100644 index 0000000..88f0f36 --- /dev/null +++ b/Packages/FollowTag/Runtime/FollowController.cs @@ -0,0 +1,37 @@ +using UnityEngine; + +namespace MuHua { + /// + /// 跟随标签控制器 + /// + public abstract class FollowController : MonoBehaviour where T : FollowController { + /// 模块单例 + public static T I => instance; + /// 模块单例 + protected static T instance; + /// 初始化 + protected abstract void Awake(); + + /// 替换,并且设置切换场景不销毁 + protected virtual void Replace(bool isDontDestroy = true) { + if (instance != null) { Destroy(instance.gameObject); } + instance = (T)this; + if (isDontDestroy) { DontDestroyOnLoad(gameObject); } + } + /// 不替换,并且设置切换场景不销毁 + protected virtual void NoReplace(bool isDontDestroy = true) { + if (isDontDestroy) { DontDestroyOnLoad(gameObject); } + if (instance == null) { instance = (T)this; } + else { Destroy(gameObject); } + } + + /// 创建标签 + public static Transform CreateLabel(Transform target, Transform labelPrefab, Transform parent, Vector3 offset) { + Transform labelObject = Instantiate(labelPrefab, parent); + FollowTag followObjectLabel = labelObject.GetComponent(); + followObjectLabel.target = target; + followObjectLabel.offset = offset; + return labelObject; + } + } +} \ No newline at end of file diff --git a/Packages/LabelFollow/Runtime/LabelController.cs.meta b/Packages/FollowTag/Runtime/FollowController.cs.meta similarity index 100% rename from Packages/LabelFollow/Runtime/LabelController.cs.meta rename to Packages/FollowTag/Runtime/FollowController.cs.meta diff --git a/Packages/FollowTag/Runtime/FollowTag.cs b/Packages/FollowTag/Runtime/FollowTag.cs new file mode 100644 index 0000000..264dc68 --- /dev/null +++ b/Packages/FollowTag/Runtime/FollowTag.cs @@ -0,0 +1,19 @@ +using UnityEngine; + +namespace MuHua { + /// + /// 跟随标签 + /// + public class FollowTag : MonoBehaviour { + public Transform target; // 要跟随的目标物体 + public Vector3 offset; // 标签的偏移量 + + protected virtual void Update() { + if (target == null) { return; } + // 设置标签的位置 + transform.position = target.position + offset; + // 使标签面向相机 + transform.rotation = Camera.main.transform.rotation; + } + } +} \ No newline at end of file diff --git a/Packages/LabelFollow/Runtime/LabelFollower.cs.meta b/Packages/FollowTag/Runtime/FollowTag.cs.meta similarity index 100% rename from Packages/LabelFollow/Runtime/LabelFollower.cs.meta rename to Packages/FollowTag/Runtime/FollowTag.cs.meta diff --git a/Packages/LabelFollow/Runtime/MuHua.LabelFollow.asmdef b/Packages/FollowTag/Runtime/MuHua.FollowTag.asmdef similarity index 90% rename from Packages/LabelFollow/Runtime/MuHua.LabelFollow.asmdef rename to Packages/FollowTag/Runtime/MuHua.FollowTag.asmdef index 13b59cf..42a5e4b 100644 --- a/Packages/LabelFollow/Runtime/MuHua.LabelFollow.asmdef +++ b/Packages/FollowTag/Runtime/MuHua.FollowTag.asmdef @@ -1,5 +1,5 @@ { - "name": "MuHua.LabelFollow", + "name": "MuHua.FollowTag", "rootNamespace": "", "references": [], "includePlatforms": [], diff --git a/Packages/LabelFollow/Runtime/MuHua.LabelFollow.asmdef.meta b/Packages/FollowTag/Runtime/MuHua.FollowTag.asmdef.meta similarity index 100% rename from Packages/LabelFollow/Runtime/MuHua.LabelFollow.asmdef.meta rename to Packages/FollowTag/Runtime/MuHua.FollowTag.asmdef.meta diff --git a/Packages/LabelFollow/Samples~/Sample.unitypackage b/Packages/FollowTag/Samples~/Sample.unitypackage similarity index 100% rename from Packages/LabelFollow/Samples~/Sample.unitypackage rename to Packages/FollowTag/Samples~/Sample.unitypackage diff --git a/Packages/LabelFollow/Samples~/Sample.unitypackage.meta b/Packages/FollowTag/Samples~/Sample.unitypackage.meta similarity index 100% rename from Packages/LabelFollow/Samples~/Sample.unitypackage.meta rename to Packages/FollowTag/Samples~/Sample.unitypackage.meta diff --git a/Packages/LabelFollow/package.json b/Packages/FollowTag/package.json similarity index 82% rename from Packages/LabelFollow/package.json rename to Packages/FollowTag/package.json index 07f96de..ffebfa4 100644 --- a/Packages/LabelFollow/package.json +++ b/Packages/FollowTag/package.json @@ -1,7 +1,7 @@ { - "name": "muhua-label-follow", + "name": "muhua-follow-tag", "version": "1.0.0", - "displayName": "MuHua LabelFollow", + "displayName": "MuHua FollowTag", "description": "\u6d6e\u52a8\u6807\u7b7e\u7cfb\u7edf", "author": { "name": "MuHua", diff --git a/Packages/LabelFollow/package.json.meta b/Packages/FollowTag/package.json.meta similarity index 100% rename from Packages/LabelFollow/package.json.meta rename to Packages/FollowTag/package.json.meta diff --git a/Packages/LabelFollow/Runtime/LabelController.cs b/Packages/LabelFollow/Runtime/LabelController.cs deleted file mode 100644 index 146a0c8..0000000 --- a/Packages/LabelFollow/Runtime/LabelController.cs +++ /dev/null @@ -1,34 +0,0 @@ -using UnityEngine; - -namespace MuHua -{ - public class LabelController : MonoBehaviour - { - public static LabelController Instance { get; private set; } - - public Transform parent; // 标签父物体 - public GameObject labelPrefab; // 标签预制体 - - void Awake() - { - if (Instance == null) { Instance = this; } - else { Destroy(gameObject); } - } - - // 启用标签 - public static void Enable(bool enable) => Instance.parent.gameObject.SetActive(enable); - - // 创建标签 - public static GameObject CreateLabel(Transform target) => CreateLabel(target, Vector3.zero); - public static GameObject CreateLabel(Transform target, Vector3 offset) => CreateLabel(target, Instance.labelPrefab, offset); - public static GameObject CreateLabel(Transform target, GameObject labelPrefab, Vector3 offset) - { - GameObject labelObject = Instantiate(labelPrefab, Instance.parent); - LabelFollower followObjectLabel = labelObject.GetComponent(); - followObjectLabel.target = target; - followObjectLabel.offset = offset; - - return labelObject; - } - } -} \ No newline at end of file diff --git a/Packages/LabelFollow/Runtime/LabelFollower.cs b/Packages/LabelFollow/Runtime/LabelFollower.cs deleted file mode 100644 index 2d667ab..0000000 --- a/Packages/LabelFollow/Runtime/LabelFollower.cs +++ /dev/null @@ -1,21 +0,0 @@ -using UnityEngine; - -namespace MuHua -{ - public class LabelFollower : MonoBehaviour - { - public Transform target; // 要跟随的目标物体 - public Vector3 offset; // 标签的偏移量 - void Update() - { - if (target != null) - { - // 设置标签的位置 - transform.position = target.position + offset; - - // 使标签面向相机 - transform.rotation = Camera.main.transform.rotation; - } - } - } -} \ No newline at end of file diff --git a/Packages/packages-lock.json b/Packages/packages-lock.json index c9071c0..8fd60b2 100644 --- a/Packages/packages-lock.json +++ b/Packages/packages-lock.json @@ -6,6 +6,20 @@ "source": "embedded", "dependencies": {} }, + "com.unity.addressables": { + "version": "1.21.21", + "depth": 1, + "source": "registry", + "dependencies": { + "com.unity.scriptablebuildpipeline": "1.21.23", + "com.unity.modules.assetbundle": "1.0.0", + "com.unity.modules.imageconversion": "1.0.0", + "com.unity.modules.jsonserialize": "1.0.0", + "com.unity.modules.unitywebrequest": "1.0.0", + "com.unity.modules.unitywebrequestassetbundle": "1.0.0" + }, + "url": "https://packages.unity.cn" + }, "com.unity.burst": { "version": "1.8.15", "depth": 1, @@ -140,6 +154,13 @@ "com.unity.render-pipelines.core": "14.0.10" } }, + "com.unity.scriptablebuildpipeline": { + "version": "1.21.23", + "depth": 2, + "source": "registry", + "dependencies": {}, + "url": "https://packages.unity.cn" + }, "com.unity.searcher": { "version": "4.9.2", "depth": 2, @@ -250,6 +271,14 @@ }, "url": "https://packages.unity.cn" }, + "muhua-aaloading": { + "version": "file:AALoading", + "depth": 0, + "source": "embedded", + "dependencies": { + "com.unity.addressables": "1.21.21" + } + }, "muhua-character": { "version": "file:Character", "depth": 0, @@ -258,8 +287,8 @@ "com.unity.inputsystem": "1.7.0" } }, - "muhua-label-follow": { - "version": "file:LabelFollow", + "muhua-follow-tag": { + "version": "file:FollowTag", "depth": 0, "source": "embedded", "dependencies": {}