Merge pull request 'event_system' (#8) from event_system into develop
Reviewed-on: #8 Reviewed-by: Jeonghyeon <jeonghyeon@capers.co.kr>
This commit is contained in:
commit
7b62494ad5
@ -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<Sprite>(toPath) == null)
|
||||
{
|
||||
|
@ -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<Object>();
|
||||
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<Sprite>(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<Material>(AssetDatabase.GUIDToAssetPath(guid)))
|
||||
// .ToDictionary(m => m.name);
|
||||
//
|
||||
// foreach (var renderer in model.GetComponentsInChildren<Renderer>())
|
||||
// {
|
||||
// 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<SLResourceObject>();
|
||||
|
||||
//res.Init();
|
||||
|
||||
Utils.MakeFolderFromFilePath(destPath);
|
||||
|
||||
// {
|
||||
// // Make Duumy(for test)
|
||||
// var dummyObj = Object.Instantiate(model);
|
||||
// var anim = dummyObj.GetComponentInChildren<Animator>();
|
||||
// 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<AnimationClip>(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();
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
8
Assets/_DDD/_Scripts/GameFramework/EventBus.meta
Normal file
8
Assets/_DDD/_Scripts/GameFramework/EventBus.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d9d81b77c0e15e5459af3bbbacf9c8b3
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
52
Assets/_DDD/_Scripts/GameFramework/EventBus/EventBus.cs
Normal file
52
Assets/_DDD/_Scripts/GameFramework/EventBus/EventBus.cs
Normal file
@ -0,0 +1,52 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace DDD
|
||||
{
|
||||
public static class EventBus
|
||||
{
|
||||
private static readonly Dictionary<Type, List<object>> HandlerDictionary = new();
|
||||
|
||||
public static void Register<T>(IEventHandler<T> handler) where T : IEvent
|
||||
{
|
||||
var type = typeof(T);
|
||||
if (!HandlerDictionary.ContainsKey(type))
|
||||
{
|
||||
HandlerDictionary[type] = new List<object>();
|
||||
}
|
||||
|
||||
HandlerDictionary[type].Add(handler);
|
||||
}
|
||||
|
||||
public static void Unregister<T>(IEventHandler<T> 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>(T evt) where T : IEvent
|
||||
{
|
||||
var type = typeof(T);
|
||||
if (HandlerDictionary.TryGetValue(type, out var list))
|
||||
{
|
||||
foreach (var handler in list.Cast<IEventHandler<T>>())
|
||||
{
|
||||
handler.Handle(evt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void ClearAll()
|
||||
{
|
||||
HandlerDictionary.Clear();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e57263a6fcda2cb43a03e0b4efd4848e
|
7
Assets/_DDD/_Scripts/GameFramework/EventBus/IEvent.cs
Normal file
7
Assets/_DDD/_Scripts/GameFramework/EventBus/IEvent.cs
Normal file
@ -0,0 +1,7 @@
|
||||
namespace DDD
|
||||
{
|
||||
public interface IEvent
|
||||
{
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ffb2216f8e1a979449b7fb4caa575033
|
@ -0,0 +1,7 @@
|
||||
namespace DDD
|
||||
{
|
||||
public interface IEventHandler<in T> where T : IEvent
|
||||
{
|
||||
void Handle(T evt);
|
||||
}
|
||||
}
|
@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0dd9940e2db491b4fae6d77773427b36
|
@ -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";
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user