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/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