From b2c9cb3a7e47bbf517f187073c8a54894657fc12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BD=95=E5=86=A0=E5=B3=B0?= Date: Thu, 17 Apr 2025 14:16:56 +0800 Subject: [PATCH] update space shooter --- .../GameRes/UIPanel/UIBattle.prefab | 15 ++++ .../GameRes/UIPanel/UIHome.prefab | 14 ++++ .../GameRes/UIPanel/UILoading.prefab | 14 ++++ .../GameRes/UISprite/atlas_icon.meta | 8 ++ .../UISprite/{ => atlas_icon}/bullet.png | Bin .../UISprite/{ => atlas_icon}/bullet.png.meta | 0 .../UISprite/{ => atlas_icon}/pause.png | Bin .../UISprite/{ => atlas_icon}/pause.png.meta | 0 .../UISprite/{ => atlas_icon}/rocket.png | Bin .../UISprite/{ => atlas_icon}/rocket.png.meta | 0 .../UISpriteAtlas/atlas_icon.spriteatlas | 2 +- .../GameScript/Editor/PanelMonitor.meta | 8 ++ .../Editor/PanelMonitor/UIPanelModifier.cs | 70 ++++++++++++++++++ .../PanelMonitor/UIPanelModifier.cs.meta | 11 +++ .../Editor/PanelMonitor/UIPanelMonitor.cs | 29 ++++++++ .../PanelMonitor/UIPanelMonitor.cs.meta | 11 +++ .../Editor/PanelMonitor/UIPanelSettings.cs | 49 ++++++++++++ .../PanelMonitor/UIPanelSettings.cs.meta | 11 +++ .../Runtime/Behaviour/PanelManifest.cs | 12 +++ .../Runtime/Behaviour/PanelManifest.cs.meta | 11 +++ 20 files changed, 264 insertions(+), 1 deletion(-) create mode 100644 Assets/YooAsset/Samples~/Space Shooter/GameRes/UISprite/atlas_icon.meta rename Assets/YooAsset/Samples~/Space Shooter/GameRes/UISprite/{ => atlas_icon}/bullet.png (100%) rename Assets/YooAsset/Samples~/Space Shooter/GameRes/UISprite/{ => atlas_icon}/bullet.png.meta (100%) rename Assets/YooAsset/Samples~/Space Shooter/GameRes/UISprite/{ => atlas_icon}/pause.png (100%) rename Assets/YooAsset/Samples~/Space Shooter/GameRes/UISprite/{ => atlas_icon}/pause.png.meta (100%) rename Assets/YooAsset/Samples~/Space Shooter/GameRes/UISprite/{ => atlas_icon}/rocket.png (100%) rename Assets/YooAsset/Samples~/Space Shooter/GameRes/UISprite/{ => atlas_icon}/rocket.png.meta (100%) create mode 100644 Assets/YooAsset/Samples~/Space Shooter/GameScript/Editor/PanelMonitor.meta create mode 100644 Assets/YooAsset/Samples~/Space Shooter/GameScript/Editor/PanelMonitor/UIPanelModifier.cs create mode 100644 Assets/YooAsset/Samples~/Space Shooter/GameScript/Editor/PanelMonitor/UIPanelModifier.cs.meta create mode 100644 Assets/YooAsset/Samples~/Space Shooter/GameScript/Editor/PanelMonitor/UIPanelMonitor.cs create mode 100644 Assets/YooAsset/Samples~/Space Shooter/GameScript/Editor/PanelMonitor/UIPanelMonitor.cs.meta create mode 100644 Assets/YooAsset/Samples~/Space Shooter/GameScript/Editor/PanelMonitor/UIPanelSettings.cs create mode 100644 Assets/YooAsset/Samples~/Space Shooter/GameScript/Editor/PanelMonitor/UIPanelSettings.cs.meta create mode 100644 Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/Behaviour/PanelManifest.cs create mode 100644 Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/Behaviour/PanelManifest.cs.meta diff --git a/Assets/YooAsset/Samples~/Space Shooter/GameRes/UIPanel/UIBattle.prefab b/Assets/YooAsset/Samples~/Space Shooter/GameRes/UIPanel/UIBattle.prefab index ee02a682..686c9394 100644 --- a/Assets/YooAsset/Samples~/Space Shooter/GameRes/UIPanel/UIBattle.prefab +++ b/Assets/YooAsset/Samples~/Space Shooter/GameRes/UIPanel/UIBattle.prefab @@ -377,6 +377,7 @@ GameObject: - component: {fileID: 4142826567245113225} - component: {fileID: 446002385128238495} - component: {fileID: 3593489457066976788} + - component: {fileID: 6254029933122384597} m_Layer: 5 m_Name: UIBattle m_TagString: Untagged @@ -457,6 +458,20 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 9776c197a7f86e94c9484946495616bb, type: 3} m_Name: m_EditorClassIdentifier: +--- !u!114 &6254029933122384597 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4142826567245113227} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: e2537124b11b52a458e01629f6b18f55, type: 3} + m_Name: + m_EditorClassIdentifier: + ReferencesAtlas: + - {fileID: 4343727234628468602, guid: 2a1b1891e0f61ff498a73d9ff86c26d7, type: 2} --- !u!1 &5051316305113654670 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/YooAsset/Samples~/Space Shooter/GameRes/UIPanel/UIHome.prefab b/Assets/YooAsset/Samples~/Space Shooter/GameRes/UIPanel/UIHome.prefab index 6bde1866..67fe2a2e 100644 --- a/Assets/YooAsset/Samples~/Space Shooter/GameRes/UIPanel/UIHome.prefab +++ b/Assets/YooAsset/Samples~/Space Shooter/GameRes/UIPanel/UIHome.prefab @@ -286,6 +286,7 @@ GameObject: - component: {fileID: 4142826567245113225} - component: {fileID: 446002385128238495} - component: {fileID: 761597478329303380} + - component: {fileID: 314988873648655327} m_Layer: 5 m_Name: UIHome m_TagString: Untagged @@ -370,6 +371,19 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 4792d7c57be85c845bc50d7215160853, type: 3} m_Name: m_EditorClassIdentifier: +--- !u!114 &314988873648655327 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4142826567245113227} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: e2537124b11b52a458e01629f6b18f55, type: 3} + m_Name: + m_EditorClassIdentifier: + ReferencesAtlas: [] --- !u!1 &4243341538011618776 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/YooAsset/Samples~/Space Shooter/GameRes/UIPanel/UILoading.prefab b/Assets/YooAsset/Samples~/Space Shooter/GameRes/UIPanel/UILoading.prefab index 2fe1c444..f4f71055 100644 --- a/Assets/YooAsset/Samples~/Space Shooter/GameRes/UIPanel/UILoading.prefab +++ b/Assets/YooAsset/Samples~/Space Shooter/GameRes/UIPanel/UILoading.prefab @@ -166,6 +166,7 @@ GameObject: - component: {fileID: 4142826567245113225} - component: {fileID: 446002385128238495} - component: {fileID: 6653013303473587574} + - component: {fileID: 5570311910315361439} m_Layer: 5 m_Name: UILoading m_TagString: Untagged @@ -246,3 +247,16 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: f2bfcc4f450a0b94bb7748fb4788630e, type: 3} m_Name: m_EditorClassIdentifier: +--- !u!114 &5570311910315361439 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4142826567245113227} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: e2537124b11b52a458e01629f6b18f55, type: 3} + m_Name: + m_EditorClassIdentifier: + ReferencesAtlas: [] diff --git a/Assets/YooAsset/Samples~/Space Shooter/GameRes/UISprite/atlas_icon.meta b/Assets/YooAsset/Samples~/Space Shooter/GameRes/UISprite/atlas_icon.meta new file mode 100644 index 00000000..da82ab9c --- /dev/null +++ b/Assets/YooAsset/Samples~/Space Shooter/GameRes/UISprite/atlas_icon.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 5fac54b722786ad4ead1a636d5057b7e +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/YooAsset/Samples~/Space Shooter/GameRes/UISprite/bullet.png b/Assets/YooAsset/Samples~/Space Shooter/GameRes/UISprite/atlas_icon/bullet.png similarity index 100% rename from Assets/YooAsset/Samples~/Space Shooter/GameRes/UISprite/bullet.png rename to Assets/YooAsset/Samples~/Space Shooter/GameRes/UISprite/atlas_icon/bullet.png diff --git a/Assets/YooAsset/Samples~/Space Shooter/GameRes/UISprite/bullet.png.meta b/Assets/YooAsset/Samples~/Space Shooter/GameRes/UISprite/atlas_icon/bullet.png.meta similarity index 100% rename from Assets/YooAsset/Samples~/Space Shooter/GameRes/UISprite/bullet.png.meta rename to Assets/YooAsset/Samples~/Space Shooter/GameRes/UISprite/atlas_icon/bullet.png.meta diff --git a/Assets/YooAsset/Samples~/Space Shooter/GameRes/UISprite/pause.png b/Assets/YooAsset/Samples~/Space Shooter/GameRes/UISprite/atlas_icon/pause.png similarity index 100% rename from Assets/YooAsset/Samples~/Space Shooter/GameRes/UISprite/pause.png rename to Assets/YooAsset/Samples~/Space Shooter/GameRes/UISprite/atlas_icon/pause.png diff --git a/Assets/YooAsset/Samples~/Space Shooter/GameRes/UISprite/pause.png.meta b/Assets/YooAsset/Samples~/Space Shooter/GameRes/UISprite/atlas_icon/pause.png.meta similarity index 100% rename from Assets/YooAsset/Samples~/Space Shooter/GameRes/UISprite/pause.png.meta rename to Assets/YooAsset/Samples~/Space Shooter/GameRes/UISprite/atlas_icon/pause.png.meta diff --git a/Assets/YooAsset/Samples~/Space Shooter/GameRes/UISprite/rocket.png b/Assets/YooAsset/Samples~/Space Shooter/GameRes/UISprite/atlas_icon/rocket.png similarity index 100% rename from Assets/YooAsset/Samples~/Space Shooter/GameRes/UISprite/rocket.png rename to Assets/YooAsset/Samples~/Space Shooter/GameRes/UISprite/atlas_icon/rocket.png diff --git a/Assets/YooAsset/Samples~/Space Shooter/GameRes/UISprite/rocket.png.meta b/Assets/YooAsset/Samples~/Space Shooter/GameRes/UISprite/atlas_icon/rocket.png.meta similarity index 100% rename from Assets/YooAsset/Samples~/Space Shooter/GameRes/UISprite/rocket.png.meta rename to Assets/YooAsset/Samples~/Space Shooter/GameRes/UISprite/atlas_icon/rocket.png.meta diff --git a/Assets/YooAsset/Samples~/Space Shooter/GameRes/UISpriteAtlas/atlas_icon.spriteatlas b/Assets/YooAsset/Samples~/Space Shooter/GameRes/UISpriteAtlas/atlas_icon.spriteatlas index 6f25346c..3afcdaef 100644 --- a/Assets/YooAsset/Samples~/Space Shooter/GameRes/UISpriteAtlas/atlas_icon.spriteatlas +++ b/Assets/YooAsset/Samples~/Space Shooter/GameRes/UISpriteAtlas/atlas_icon.spriteatlas @@ -32,7 +32,7 @@ SpriteAtlas: secondaryTextureSettings: {} variantMultiplier: 1 packables: - - {fileID: 102900000, guid: 935d7f20c085cc141a3daf9cacfabfae, type: 3} + - {fileID: 102900000, guid: 5fac54b722786ad4ead1a636d5057b7e, type: 3} bindAsDefault: 1 isAtlasV2: 0 cachedData: {fileID: 0} diff --git a/Assets/YooAsset/Samples~/Space Shooter/GameScript/Editor/PanelMonitor.meta b/Assets/YooAsset/Samples~/Space Shooter/GameScript/Editor/PanelMonitor.meta new file mode 100644 index 00000000..fab23070 --- /dev/null +++ b/Assets/YooAsset/Samples~/Space Shooter/GameScript/Editor/PanelMonitor.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 93fb052359d809247bd6669f2b989ddd +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/YooAsset/Samples~/Space Shooter/GameScript/Editor/PanelMonitor/UIPanelModifier.cs b/Assets/YooAsset/Samples~/Space Shooter/GameScript/Editor/PanelMonitor/UIPanelModifier.cs new file mode 100644 index 00000000..8235140c --- /dev/null +++ b/Assets/YooAsset/Samples~/Space Shooter/GameScript/Editor/PanelMonitor/UIPanelModifier.cs @@ -0,0 +1,70 @@ +using System.IO; +using UnityEngine; +using UnityEngine.UI; +using UnityEngine.U2D; + +public static class UIPanelModifier +{ + /// + /// 刷新面板清单 + /// + public static void Refresh(PanelManifest manifest) + { + CacheReferenceAtals(manifest); + } + + /// + /// 更新组件 + /// + private static void CacheReferenceAtals(PanelManifest manifest) + { + manifest.ReferencesAtlas.Clear(); + + string spriteDirectory = UIPanelSettings.GetSpriteDirecotry(); + string altasDirectory = UIPanelSettings.GetAtlasDirecotry(); + + // 获取依赖的图集名称 + Transform root = manifest.transform; + Image[] allImage = root.GetComponentsInChildren(true); + for (int i = 0; i < allImage.Length; i++) + { + Image image = allImage[i]; + if (image.sprite == null) + continue; + + // 文件路径 + string spriteAssetPath = UnityEditor.AssetDatabase.GetAssetPath(image.sprite); + + // 跳过系统内置资源 + if (spriteAssetPath.Contains("_builtin_")) + continue; + + // 跳过非图集精灵 + if (spriteAssetPath.StartsWith(spriteDirectory) == false) + continue; + + string atlasAssetPath = GetAtlasPath(altasDirectory, spriteAssetPath); + SpriteAtlas spriteAtlas = UnityEditor.AssetDatabase.LoadAssetAtPath(atlasAssetPath); + if (spriteAtlas == null) + { + throw new System.Exception($"Not found SpriteAtlas : {atlasAssetPath}"); + } + else + { + if (manifest.ReferencesAtlas.Contains(spriteAtlas) == false) + manifest.ReferencesAtlas.Add(spriteAtlas); + } + } + } + + /// + /// 获取精灵所属图集 + /// + private static string GetAtlasPath(string atlasDirectory, string assetPath) + { + string directory = Path.GetDirectoryName(assetPath); + DirectoryInfo directoryInfo = new DirectoryInfo(directory); + string atlasName = directoryInfo.Name; + return $"{atlasDirectory}/{atlasName}.spriteatlas"; + } +} \ No newline at end of file diff --git a/Assets/YooAsset/Samples~/Space Shooter/GameScript/Editor/PanelMonitor/UIPanelModifier.cs.meta b/Assets/YooAsset/Samples~/Space Shooter/GameScript/Editor/PanelMonitor/UIPanelModifier.cs.meta new file mode 100644 index 00000000..e7db53ab --- /dev/null +++ b/Assets/YooAsset/Samples~/Space Shooter/GameScript/Editor/PanelMonitor/UIPanelModifier.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 6076577ae87253845a16ec633f38704c +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/YooAsset/Samples~/Space Shooter/GameScript/Editor/PanelMonitor/UIPanelMonitor.cs b/Assets/YooAsset/Samples~/Space Shooter/GameScript/Editor/PanelMonitor/UIPanelMonitor.cs new file mode 100644 index 00000000..e933e266 --- /dev/null +++ b/Assets/YooAsset/Samples~/Space Shooter/GameScript/Editor/PanelMonitor/UIPanelMonitor.cs @@ -0,0 +1,29 @@ +using UnityEngine; +using UnityEditor; +using UnityEditor.SceneManagement; + +public class UIPanelMonitor : UnityEditor.Editor +{ + [InitializeOnLoadMethod] + static void StartInitializeOnLoadMethod() + { + PrefabStage.prefabSaving += OnPrefabSaving; + } + + static void OnPrefabSaving(GameObject go) + { + PrefabStage stage = PrefabStageUtility.GetCurrentPrefabStage(); + if (stage != null) + { + string panelDirectory = UIPanelSettings.GetPanelDirecotry(); + if (stage.assetPath.StartsWith(panelDirectory)) + { + PanelManifest manifest = go.GetComponent(); + if (manifest == null) + manifest = go.AddComponent(); + + UIPanelModifier.Refresh(manifest); + } + } + } +} \ No newline at end of file diff --git a/Assets/YooAsset/Samples~/Space Shooter/GameScript/Editor/PanelMonitor/UIPanelMonitor.cs.meta b/Assets/YooAsset/Samples~/Space Shooter/GameScript/Editor/PanelMonitor/UIPanelMonitor.cs.meta new file mode 100644 index 00000000..716a4d98 --- /dev/null +++ b/Assets/YooAsset/Samples~/Space Shooter/GameScript/Editor/PanelMonitor/UIPanelMonitor.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 6bed3b2eaa555ec4e9aaa22a888b504c +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/YooAsset/Samples~/Space Shooter/GameScript/Editor/PanelMonitor/UIPanelSettings.cs b/Assets/YooAsset/Samples~/Space Shooter/GameScript/Editor/PanelMonitor/UIPanelSettings.cs new file mode 100644 index 00000000..e7783625 --- /dev/null +++ b/Assets/YooAsset/Samples~/Space Shooter/GameScript/Editor/PanelMonitor/UIPanelSettings.cs @@ -0,0 +1,49 @@ +using UnityEngine; +using UnityEditor; + +public static class UIPanelSettings +{ + /// + /// 面板文件夹GUID + /// + private const string UIPanelDirectoryGUID = "12d33f33f3a55224c9c747d7bffa1c68"; + + /// + /// 精灵文件夹GUID + /// + private const string UISpriteDirectoryGUID = "935d7f20c085cc141a3daf9cacfabfae"; + + /// + /// 图集文件夹GUID + /// + private const string UIAtlasDirectoryGUID = "c355c783476322b4cacac98c5e1b46d8"; + + + public static string GetPanelDirecotry() + { + string result = AssetDatabase.GUIDToAssetPath(UIPanelDirectoryGUID); + if (string.IsNullOrEmpty(result)) + { + throw new System.Exception($"Can not found panel direcotry : {UIPanelDirectoryGUID}"); + } + return result; + } + public static string GetSpriteDirecotry() + { + string result = AssetDatabase.GUIDToAssetPath(UISpriteDirectoryGUID); + if (string.IsNullOrEmpty(result)) + { + throw new System.Exception($"Can not found sprite direcotry : {UISpriteDirectoryGUID}"); + } + return result; + } + public static string GetAtlasDirecotry() + { + string result = AssetDatabase.GUIDToAssetPath(UIAtlasDirectoryGUID); + if (string.IsNullOrEmpty(result)) + { + throw new System.Exception($"Can not found atlas direcotry : {UIAtlasDirectoryGUID}"); + } + return result; + } +} \ No newline at end of file diff --git a/Assets/YooAsset/Samples~/Space Shooter/GameScript/Editor/PanelMonitor/UIPanelSettings.cs.meta b/Assets/YooAsset/Samples~/Space Shooter/GameScript/Editor/PanelMonitor/UIPanelSettings.cs.meta new file mode 100644 index 00000000..aaa94072 --- /dev/null +++ b/Assets/YooAsset/Samples~/Space Shooter/GameScript/Editor/PanelMonitor/UIPanelSettings.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 603a8486cd52506408bf1eb6a80588b6 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/Behaviour/PanelManifest.cs b/Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/Behaviour/PanelManifest.cs new file mode 100644 index 00000000..517cb07e --- /dev/null +++ b/Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/Behaviour/PanelManifest.cs @@ -0,0 +1,12 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.U2D; + +public class PanelManifest : MonoBehaviour +{ + /// + /// 面板自动引用的图集 + /// + public List ReferencesAtlas = new List(); +} \ No newline at end of file diff --git a/Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/Behaviour/PanelManifest.cs.meta b/Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/Behaviour/PanelManifest.cs.meta new file mode 100644 index 00000000..4f86ead2 --- /dev/null +++ b/Assets/YooAsset/Samples~/Space Shooter/GameScript/Runtime/Behaviour/PanelManifest.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: e2537124b11b52a458e01629f6b18f55 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: