From 75d8d032754da594a2d938343a79a3852783b738 Mon Sep 17 00:00:00 2001 From: Ding Yuntian <1491671119@qq.com> Date: Wed, 5 Mar 2025 15:02:30 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9B=BE=E9=9B=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Editor/EditorKit.cs | 13 ++++ Assets/Editor/Inspector/SpriteGroupEditor.cs | 8 +-- Assets/Resources/SpriteGroup/佩佩最新.prefab | 4 +- Assets/Scenes/ClinicScene.unity | 65 ++++++++++++++++++- .../Framework/OtherKit/SpriteGroupKit.cs | 33 ++++------ .../StreamingAssets/Config/sprite_group.json | 2 +- 6 files changed, 98 insertions(+), 27 deletions(-) diff --git a/Assets/Editor/EditorKit.cs b/Assets/Editor/EditorKit.cs index f3b68b00f..42084bf57 100644 --- a/Assets/Editor/EditorKit.cs +++ b/Assets/Editor/EditorKit.cs @@ -54,5 +54,18 @@ namespace AibisDream.SystemEditor return SortingLayer.layers[idx].id; } + + public static void RecordObjectAndChildren(GameObject parent, string actionName) + { + Transform[] transforms = parent.GetComponentsInChildren(true); + Object[] objectsToUndo = new Object[transforms.Length]; + + for (int i = 0; i < transforms.Length; i++) + { + objectsToUndo[i] = transforms[i].gameObject; + } + + Undo.RegisterCompleteObjectUndo(objectsToUndo, actionName); + } } } \ No newline at end of file diff --git a/Assets/Editor/Inspector/SpriteGroupEditor.cs b/Assets/Editor/Inspector/SpriteGroupEditor.cs index 9de9b1a9f..497079280 100644 --- a/Assets/Editor/Inspector/SpriteGroupEditor.cs +++ b/Assets/Editor/Inspector/SpriteGroupEditor.cs @@ -91,7 +91,7 @@ namespace AibisDream.SystemEditor EditorGUILayout.BeginHorizontal(); - var stateArray = example.config.StateDict.Keys.ToArray(); + var stateArray = example.config.stateDict.Keys.ToArray(); var newIndex = EditorGUILayout.Popup(_stateIdx, stateArray); _curState = EditorGUILayout.TextField(_curState); @@ -131,9 +131,9 @@ namespace AibisDream.SystemEditor private void OnLoadStateClick(SpriteGroupKit example) { - if (!string.IsNullOrEmpty(_curState) && example.config.StateDict.ContainsKey(_curState)) + if (!string.IsNullOrEmpty(_curState) && example.config.stateDict.ContainsKey(_curState)) { - Undo.RecordObject(example, "加载状态"); + EditorKit.RecordObjectAndChildren(example.gameObject, "加载状态"); example.SwitchState(_curState); EditorUtility.SetDirty(example); } @@ -154,7 +154,7 @@ namespace AibisDream.SystemEditor EditorGUILayout.EndHorizontal(); if (GUILayout.Button("重排序")) { - Undo.RecordObject(example, "重排序"); + EditorKit.RecordObjectAndChildren(example.gameObject, "重新排序"); example.Reorder(); EditorUtility.SetDirty(example); } diff --git a/Assets/Resources/SpriteGroup/佩佩最新.prefab b/Assets/Resources/SpriteGroup/佩佩最新.prefab index b625fe3e6..782a79181 100644 --- a/Assets/Resources/SpriteGroup/佩佩最新.prefab +++ b/Assets/Resources/SpriteGroup/佩佩最新.prefab @@ -1174,7 +1174,7 @@ GameObject: m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 - m_IsActive: 1 + m_IsActive: 0 --- !u!4 &8908242346666898786 Transform: m_ObjectHideFlags: 0 @@ -2335,7 +2335,7 @@ GameObject: m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 - m_IsActive: 1 + m_IsActive: 0 --- !u!4 &7133885259711726990 Transform: m_ObjectHideFlags: 0 diff --git a/Assets/Scenes/ClinicScene.unity b/Assets/Scenes/ClinicScene.unity index f059c87da..308f4b528 100644 --- a/Assets/Scenes/ClinicScene.unity +++ b/Assets/Scenes/ClinicScene.unity @@ -303,7 +303,8 @@ Transform: m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 - m_Children: [] + m_Children: + - {fileID: 1159736113065115078} m_Father: {fileID: 1982974704} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!114 &94987966 @@ -1274,6 +1275,68 @@ Transform: - {fileID: 1511682091} m_Father: {fileID: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!1001 &1159736113065115077 +PrefabInstance: + m_ObjectHideFlags: 0 + serializedVersion: 2 + m_Modification: + serializedVersion: 3 + m_TransformParent: {fileID: 94987965} + m_Modifications: + - target: {fileID: 484818901331367303, guid: 2c6a43c0915e4a049840d1aa8ba592dd, type: 3} + propertyPath: m_Name + value: "\u4F69\u4F69\u6700\u65B0(Clone)" + objectReference: {fileID: 0} + - target: {fileID: 3367790813836740543, guid: 2c6a43c0915e4a049840d1aa8ba592dd, type: 3} + propertyPath: m_LocalPosition.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 3367790813836740543, guid: 2c6a43c0915e4a049840d1aa8ba592dd, type: 3} + propertyPath: m_LocalPosition.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 3367790813836740543, guid: 2c6a43c0915e4a049840d1aa8ba592dd, type: 3} + propertyPath: m_LocalPosition.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 3367790813836740543, guid: 2c6a43c0915e4a049840d1aa8ba592dd, type: 3} + propertyPath: m_LocalRotation.w + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 3367790813836740543, guid: 2c6a43c0915e4a049840d1aa8ba592dd, type: 3} + propertyPath: m_LocalRotation.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 3367790813836740543, guid: 2c6a43c0915e4a049840d1aa8ba592dd, type: 3} + propertyPath: m_LocalRotation.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 3367790813836740543, guid: 2c6a43c0915e4a049840d1aa8ba592dd, type: 3} + propertyPath: m_LocalRotation.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 3367790813836740543, guid: 2c6a43c0915e4a049840d1aa8ba592dd, type: 3} + propertyPath: m_LocalEulerAnglesHint.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 3367790813836740543, guid: 2c6a43c0915e4a049840d1aa8ba592dd, type: 3} + propertyPath: m_LocalEulerAnglesHint.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 3367790813836740543, guid: 2c6a43c0915e4a049840d1aa8ba592dd, type: 3} + propertyPath: m_LocalEulerAnglesHint.z + value: 0 + objectReference: {fileID: 0} + m_RemovedComponents: [] + m_RemovedGameObjects: [] + m_AddedGameObjects: [] + m_AddedComponents: [] + m_SourcePrefab: {fileID: 100100000, guid: 2c6a43c0915e4a049840d1aa8ba592dd, type: 3} +--- !u!4 &1159736113065115078 stripped +Transform: + m_CorrespondingSourceObject: {fileID: 3367790813836740543, guid: 2c6a43c0915e4a049840d1aa8ba592dd, type: 3} + m_PrefabInstance: {fileID: 1159736113065115077} + m_PrefabAsset: {fileID: 0} --- !u!1660057539 &9223372036854775807 SceneRoots: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/Framework/OtherKit/SpriteGroupKit.cs b/Assets/Scripts/Framework/OtherKit/SpriteGroupKit.cs index a9da9fb92..8df1f9129 100644 --- a/Assets/Scripts/Framework/OtherKit/SpriteGroupKit.cs +++ b/Assets/Scripts/Framework/OtherKit/SpriteGroupKit.cs @@ -15,9 +15,9 @@ namespace AibisDream.Framework public class SpriteGroupKit : MonoBehaviour { #region 索引 - - private Dictionary _rendererDict; - [HideInInspector] public SpriteGroupConfig config; + + public Dictionary rendererDict = new(); + [HideInInspector] public SpriteGroupConfig config = new(); [HideInInspector] public GameObject spriteGroup; #endregion @@ -68,11 +68,11 @@ namespace AibisDream.Framework private void InstantiateGroup() { var root = Instantiate(spriteGroup, transform); - var rendererArray = root.GetComponentsInChildren(); - _rendererDict = new Dictionary(); + var rendererArray = root.GetComponentsInChildren(true); + rendererDict = new Dictionary(); foreach (var rendererItem in rendererArray) { - _rendererDict[rendererItem.gameObject.name] = rendererItem; + rendererDict[rendererItem.gameObject.name] = rendererItem; } } @@ -95,12 +95,12 @@ namespace AibisDream.Framework public void SaveState(string curState) { - var activeArray = _rendererDict + var activeArray = rendererDict .Where(pair => pair.Value.gameObject.activeSelf) .Select(item => item.Key) .ToArray(); - config.StateDict[curState] = activeArray; + config.stateDict[curState] = activeArray; } public void SaveSpriteGroup() @@ -148,10 +148,10 @@ namespace AibisDream.Framework public void SwitchState(string stateName) { // 检查是否存在 - if (!config.StateDict.TryGetValue(stateName, out var activeArray)) return; + if (!config.stateDict.TryGetValue(stateName, out var activeArray)) return; // 按状态激活 - foreach (var item in _rendererDict.Values) + foreach (var item in rendererDict.Values) { item.gameObject.SetActive(activeArray.Contains(item.gameObject.name)); } @@ -169,14 +169,14 @@ namespace AibisDream.Framework return; } - if (_rendererDict is not { Count: > 0 }) + if (rendererDict is not { Count: > 0 }) { Debug.LogWarning("还没有加载图集"); return; } // 排序 - var renderers = _rendererDict.Values; + var renderers = rendererDict.Values; var sortedRenderers = renderers.OrderBy(item => item, new LayerComparer()).ToArray(); for (var i = 0; i < sortedRenderers.Length; i++) { @@ -189,7 +189,7 @@ namespace AibisDream.Framework } [Serializable] - public struct SpriteGroupConfig + public class SpriteGroupConfig { [JsonIgnore] public string PrefabPath => $"Assets/Resources/SpriteGroup/{key}.prefab"; @@ -200,12 +200,7 @@ namespace AibisDream.Framework public int layerId; public int maxLayer; public int minLayer; - private Dictionary _stateDict; - - public Dictionary StateDict - { - get { return _stateDict ??= new Dictionary(); } - } + public Dictionary stateDict = new(); public bool Validate() { diff --git a/Assets/StreamingAssets/Config/sprite_group.json b/Assets/StreamingAssets/Config/sprite_group.json index 57a1e0a77..135450216 100644 --- a/Assets/StreamingAssets/Config/sprite_group.json +++ b/Assets/StreamingAssets/Config/sprite_group.json @@ -1 +1 @@ -{"佩佩最新":{"key":"佩佩最新","layerId":941243827,"maxLayer":200,"minLayer":100,"StateDict":{"侧低头":["测低头侧眼","侧低头张嘴 ","侧低头背手"]}}} \ No newline at end of file +{"佩佩最新":{"key":"佩佩最新","layerId":941243827,"maxLayer":200,"minLayer":100,"stateDict":{"默认":["佩佩默认姿势"],"低头":["侧低头背手"]}}} \ No newline at end of file