diff --git a/Assets/_DDD/_Scripts/AssetPostprocessors/AssetPostProcessors.cs b/Assets/_DDD/_Scripts/AssetPostprocessors/AssetPostProcessors.cs index 8c1754e64..7b627294d 100644 --- a/Assets/_DDD/_Scripts/AssetPostprocessors/AssetPostProcessors.cs +++ b/Assets/_DDD/_Scripts/AssetPostprocessors/AssetPostProcessors.cs @@ -18,7 +18,7 @@ private void OnPreprocessTexture() // AssetPostprocessorModel.OnPreprocessTexture(importer); // } - if (upperPath.Contains("ASSETS/_DDD/_RAW/SPRITES/")) + if (upperPath.Contains(PathConstants.RawSpritesPathUpper)) { AssetPostprocessorSprite.OnPreprocessTexture(importer); } @@ -34,7 +34,7 @@ public static void OnPostprocessAllAssets(string[] importedAssets, string[] dele var upperPath = toPath.ToUpper(); // 특정 폴더일 때만 작동 - if (upperPath.Contains("ASSETS/_DDD/_RAW/SPRITES/")) + if (upperPath.Contains(PathConstants.RawSpritesPathUpper)) { if (AssetDatabase.LoadAssetAtPath(toPath) == null) { diff --git a/Assets/_DDD/_Scripts/AssetPostprocessors/AssetPostprocessorSprite.cs b/Assets/_DDD/_Scripts/AssetPostprocessors/AssetPostprocessorSprite.cs index 491930cee..338246f3f 100644 --- a/Assets/_DDD/_Scripts/AssetPostprocessors/AssetPostprocessorSprite.cs +++ b/Assets/_DDD/_Scripts/AssetPostprocessors/AssetPostprocessorSprite.cs @@ -99,8 +99,8 @@ private static void TryApplyPivotAfterImport(string path) public static void OnRemove(string path, string movePath) { var upperPath = path.ToUpper(); - if (upperPath.Contains("ASSETS/_DDD/_RAW/SPRITES/") == false || - upperPath.Contains(".PNG") == false) return; + if (upperPath.Contains(PathConstants.RawSpritesPathUpper) == false || + upperPath.Contains(ExtenstionConstants.PngExtensionUpper) == false) return; if (TargetPaths.Contains(path) == false) { @@ -111,8 +111,8 @@ public static void OnRemove(string path, string movePath) public static void OnAdd(string path) { var upperPath = path.ToUpper(); - if (upperPath.Contains("ASSETS/_DDD/_RAW/SPRITES/") == false || - upperPath.Contains(".PNG") == false) return; + if (upperPath.Contains(PathConstants.RawSpritesPathUpper) == false || + upperPath.Contains(ExtenstionConstants.PngExtensionUpper) == false) return; if (TargetPaths.Contains(path) == false) { @@ -135,15 +135,15 @@ public static void CreateAtlas(string path, string destPath) var objects = new List(); foreach (var file in di.GetFiles()) { - if (file.Name.ToUpper().IsRight(".PNG") == false) continue; + if (file.Name.ToUpper().IsRight(ExtenstionConstants.PngExtensionUpper) == false) continue; var filePath = path + "/" + file.Name; - var fileName = file.Name.Substring(0, file.Name.Length - ".png".Length); + var fileName = file.Name.Substring(0, file.Name.Length - ExtenstionConstants.PngExtensionLower.Length); var sprite = AssetDatabase.LoadAssetAtPath(filePath); var maxSize = sprite.rect.size.x > sprite.rect.size.y ? sprite.rect.size.x : sprite.rect.size.y; if (maxSize > 1024) { - CreateSingleAtlas(filePath, path.Replace("/_Raw/", "/_Addressables/") + $"_{fileName}.spriteatlasv2"); + CreateSingleAtlas(filePath, path.Replace(PathConstants.RawFolderPath, PathConstants.AddressablesFolderPath) + $"_{fileName}{ExtenstionConstants.SpriteAtlasExtenstionLower}"); continue; } @@ -243,7 +243,7 @@ public static void CreatePrefab(string path, string destPath) prefab.transform.localRotation = Quaternion.identity; prefab.name = sprite.name; - GameObject visualLook = new GameObject("VisualLook"); + GameObject visualLook = new GameObject(CommonConstants.VisualLook); visualLook.transform.SetParent(prefab.transform); visualLook.transform.localPosition = Vector3.zero; @@ -253,74 +253,8 @@ public static void CreatePrefab(string path, string destPath) spriteRenderer.sprite = sprite; spriteRenderer.sortingOrder = 5; - // var guids = AssetDatabase.FindAssets("t:Material", new string[] { Utils.FolderPath(path) }); - // var materials = guids - // .Select(guid => AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(guid))) - // .ToDictionary(m => m.name); - // - // foreach (var renderer in model.GetComponentsInChildren()) - // { - // var sharedMaterials = - // new Material[renderer.sharedMaterials.Length]; // Material을 직접 엘리먼트로 대입하면 안되고 배열을 통으로 넣어야함 - // for (var i = 0; i < renderer.sharedMaterials.Length; ++i) - // { - // if (materials.TryGetValue($"{renderer.name}_{i + 1}", out var numMat)) - // { - // sharedMaterials[i] = numMat; - // } - // else if (materials.TryGetValue(renderer.name, out var mat)) - // { - // sharedMaterials[i] = mat; - // } - // else if (materials.TryGetValue(go.name, out var defaultMat)) - // { - // sharedMaterials[i] = defaultMat; - // } - // else - // { - // sharedMaterials[i] = renderer.sharedMaterials[i]; - // // 에러인가? 잠깐 파일 안갖다놨을뿐인가? - // } - // } - // - // renderer.sharedMaterials = sharedMaterials; - // } - // - // var res = prefab.AddComponent(); - - //res.Init(); - Utils.MakeFolderFromFilePath(destPath); - // { - // // Make Duumy(for test) - // var dummyObj = Object.Instantiate(model); - // var anim = dummyObj.GetComponentInChildren(); - // var controller = - // AnimatorController.CreateAnimatorControllerAtPath(GetPrefabPath(path) - // .Replace(".prefab", ".controller")); - // - // anim.runtimeAnimatorController = controller; - // var rootStateMachine = controller.layers[0].stateMachine; - // - // var clipids = AssetDatabase.FindAssets("t:AnimationClip", - // new string[] { SLFileUtility.FolderPath(path) }); - // foreach (var guid in clipids) - // { - // var clip = AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(guid)); - // if (clip != null) - // { - // var state = rootStateMachine.AddState(clip.name); - // state.motion = clip; - // } - // } - // - // var dummy = PrefabUtility.SaveAsPrefabAssetAndConnect(dummyObj, GetPrefabPath(path), - // InteractionMode.AutomatedAction); - // - // Object.DestroyImmediate(dummyObj, false); - // } - AssetDatabase.DeleteAsset(destPath); var newPrefab = PrefabUtility.SaveAsPrefabAssetAndConnect(prefab, destPath, InteractionMode.AutomatedAction); @@ -338,12 +272,9 @@ public static void BuildTarget() { foreach (var path in TargetPaths) { - CreateAtlas(Utils.FolderPath(path), - Utils.FolderPath(path).Replace("/_Raw/", "/_Addressables/") + ".spriteatlasv2"); - //CreatePrefab(path, (path.Replace("/Raw/Sprites/", "/_Addressables/") + ".prefab").Replace(".png", "")); + CreateAtlas(Utils.FolderPath(path), Utils.FolderPath(path).Replace(PathConstants.RawFolderPath, PathConstants.AddressablesFolderPath) + ExtenstionConstants.SpriteAtlasExtenstionLower); } - TargetPaths.Clear(); } } diff --git a/Assets/_DDD/_Scripts/GameData/DataManager.cs b/Assets/_DDD/_Scripts/GameData/DataManager.cs index 8056de96e..6b65cca4e 100644 --- a/Assets/_DDD/_Scripts/GameData/DataManager.cs +++ b/Assets/_DDD/_Scripts/GameData/DataManager.cs @@ -46,7 +46,7 @@ public async void PostInit() { if (sprite == null) continue; - var key = sprite.name.Replace("(Clone)", "").Trim(); + var key = sprite.name.Replace(CommonConstants.Clone, string.Empty).Trim(); _spriteAtlas.TryAdd(key, sprite); } } diff --git a/Assets/_DDD/_Scripts/GameFramework/EventBus.meta b/Assets/_DDD/_Scripts/GameFramework/EventBus.meta new file mode 100644 index 000000000..29eb753fb --- /dev/null +++ b/Assets/_DDD/_Scripts/GameFramework/EventBus.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: d9d81b77c0e15e5459af3bbbacf9c8b3 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/_DDD/_Scripts/GameFramework/EventBus/EventBus.cs b/Assets/_DDD/_Scripts/GameFramework/EventBus/EventBus.cs new file mode 100644 index 000000000..15a8f5d2c --- /dev/null +++ b/Assets/_DDD/_Scripts/GameFramework/EventBus/EventBus.cs @@ -0,0 +1,52 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace DDD +{ + public static class EventBus + { + private static readonly Dictionary> HandlerDictionary = new(); + + public static void Register(IEventHandler handler) where T : IEvent + { + var type = typeof(T); + if (!HandlerDictionary.ContainsKey(type)) + { + HandlerDictionary[type] = new List(); + } + + HandlerDictionary[type].Add(handler); + } + + public static void Unregister(IEventHandler handler) where T : IEvent + { + var type = typeof(T); + if (HandlerDictionary.TryGetValue(type, out var list)) + { + list.Remove(handler); + if (list.Count == 0) + { + HandlerDictionary.Remove(type); + } + } + } + + public static void Publish(T evt) where T : IEvent + { + var type = typeof(T); + if (HandlerDictionary.TryGetValue(type, out var list)) + { + foreach (var handler in list.Cast>()) + { + handler.Handle(evt); + } + } + } + + public static void ClearAll() + { + HandlerDictionary.Clear(); + } + } +} \ No newline at end of file diff --git a/Assets/_DDD/_Scripts/GameFramework/EventBus/EventBus.cs.meta b/Assets/_DDD/_Scripts/GameFramework/EventBus/EventBus.cs.meta new file mode 100644 index 000000000..a745c2e40 --- /dev/null +++ b/Assets/_DDD/_Scripts/GameFramework/EventBus/EventBus.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: e57263a6fcda2cb43a03e0b4efd4848e \ No newline at end of file diff --git a/Assets/_DDD/_Scripts/GameFramework/EventBus/IEvent.cs b/Assets/_DDD/_Scripts/GameFramework/EventBus/IEvent.cs new file mode 100644 index 000000000..b09e7bc5d --- /dev/null +++ b/Assets/_DDD/_Scripts/GameFramework/EventBus/IEvent.cs @@ -0,0 +1,7 @@ +namespace DDD +{ + public interface IEvent + { + + } +} \ No newline at end of file diff --git a/Assets/_DDD/_Scripts/GameFramework/EventBus/IEvent.cs.meta b/Assets/_DDD/_Scripts/GameFramework/EventBus/IEvent.cs.meta new file mode 100644 index 000000000..f9181e193 --- /dev/null +++ b/Assets/_DDD/_Scripts/GameFramework/EventBus/IEvent.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: ffb2216f8e1a979449b7fb4caa575033 \ No newline at end of file diff --git a/Assets/_DDD/_Scripts/GameFramework/EventBus/IEventHandler.cs b/Assets/_DDD/_Scripts/GameFramework/EventBus/IEventHandler.cs new file mode 100644 index 000000000..eb26c0f31 --- /dev/null +++ b/Assets/_DDD/_Scripts/GameFramework/EventBus/IEventHandler.cs @@ -0,0 +1,7 @@ +namespace DDD +{ + public interface IEventHandler where T : IEvent + { + void Handle(T evt); + } +} \ No newline at end of file diff --git a/Assets/_DDD/_Scripts/GameFramework/EventBus/IEventHandler.cs.meta b/Assets/_DDD/_Scripts/GameFramework/EventBus/IEventHandler.cs.meta new file mode 100644 index 000000000..74fdac7c0 --- /dev/null +++ b/Assets/_DDD/_Scripts/GameFramework/EventBus/IEventHandler.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 0dd9940e2db491b4fae6d77773427b36 \ No newline at end of file diff --git a/Assets/_DDD/_Scripts/Utilities/Constants.cs b/Assets/_DDD/_Scripts/Utilities/Constants.cs index 927fb949d..0043760c8 100644 --- a/Assets/_DDD/_Scripts/Utilities/Constants.cs +++ b/Assets/_DDD/_Scripts/Utilities/Constants.cs @@ -5,6 +5,7 @@ public static class CommonConstants public const string VisualLook = "VisualLook"; public const string RestaurantPlayer = "RestaurantPlayer"; public const string BaseRestaurantEnvironment = "BaseRestaurantEnvironment"; + public const string Clone = "(Clone)"; } public static class DataConstants @@ -24,4 +25,18 @@ public static class RestaurantPlayerAnimation public const string Walk = "RunFast"; public const string Dash = "Dash"; } + + public static class PathConstants + { + public const string RawSpritesPathUpper = "ASSETS/_DDD/_RAW/SPRITES/"; + public const string RawFolderPath = "/_Raw"; + public const string AddressablesFolderPath = "/_Addressables"; + } + + public static class ExtenstionConstants + { + public const string PngExtensionUpper = ".PNG"; + public const string PngExtensionLower = ".png"; + public const string SpriteAtlasExtenstionLower = ".spriteatlasv2"; + } } \ No newline at end of file