From 538fdab1bd3fbf2e09d3894d62eaa5ca6ee0c15a Mon Sep 17 00:00:00 2001 From: hyunwoo Date: Sat, 16 Sep 2023 18:35:56 +0900 Subject: [PATCH 1/2] Update readme.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit documentation 추가 --- README.md | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) diff --git a/README.md b/README.md index e7aa439..3271515 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,91 @@ # AssetBase + +Sample Unity project to set a new project with 'dll' contains Singleton, EventBus, Infinity ScrollView etc. +It can help to set your unity project. +# Documentation + +This project has a sample scripts how to use library functions. +You can check functions and explanations here. + +## Singleton +This is a basic singleton design pattern script. +I made two types of singleton that has DontDestroyOnLoad or not. + +**- UnitySingleton** +- Singleton with DontDestroyOnLoad. +- Basic singleton script. +```c# +public class YourClass : UnitySingleton +{ + //your class codes +} +``` + +**- UnitySingletonOnce** +- Singleton without DontDestroyOnLoad +- This script and object will be removed when scene has changed. +```c# +public class YourClass : UnitySingletonOnce +{ + //your class codes +} +``` + +## EventBus +This is a eventbus design pattern script. +You can subscripe your own event(class) and send data to the subscribing object when you publish event. + +EventBus class is using 'Singleton', so you can access by Instance. + +**- Subscribe(EventDelegate callback) where T : EventBase** +**- Unsubscribe(EventDelegate callback) where T : EventBase** +- Add or Remove a generic type of event class inheriting 'EventBase'. +- You can send to the listener with class data. + +This is a sample event class. +```c# +public class MyEvent : EventBase +{ + public int _value1; + public object _value2; + ... +} +``` + +This is a sample listener script. +You can Subscribe, Unsubscribe events and define functions when your event published. +```c# +public class Listener : MonoBehavior +{ + private void OnEnable() + { + EventBus.Instance.Subscribe(OnMyEvent); + } + private voi OnDisable() + { + EventBus.Instance.Unsubscribe(OnMyEvent); + } + + private void OnMyEvent(MyEvent e) + { + //action when your event has publised. + } +} +``` + +**- Publish(EventBase eventType)** +This is how you can publish with data. +You can send any data sealed with class. +```c# +public class Publisher : MonoBehavior +{ + private void OnCommand() + { + EventBus.Instance.Puplish(new MyEvent()); + } +} +``` + +**- Clear()** +This will be used when you need to clear all subscribtions. From 48c5ac0b059dc006547b045829cf38a652468da2 Mon Sep 17 00:00:00 2001 From: hyunwoo Date: Sat, 16 Sep 2023 18:45:09 +0900 Subject: [PATCH 2/2] Update readme.md code block language changes --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 3271515..ca7bf15 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ I made two types of singleton that has DontDestroyOnLoad or not. **- UnitySingleton** - Singleton with DontDestroyOnLoad. - Basic singleton script. -```c# +```cs public class YourClass : UnitySingleton { //your class codes @@ -25,7 +25,7 @@ public class YourClass : UnitySingleton **- UnitySingletonOnce** - Singleton without DontDestroyOnLoad - This script and object will be removed when scene has changed. -```c# +```cs public class YourClass : UnitySingletonOnce { //your class codes @@ -44,7 +44,7 @@ EventBus class is using 'Singleton', so you can access by Instance. - You can send to the listener with class data. This is a sample event class. -```c# +```cs public class MyEvent : EventBase { public int _value1; @@ -55,7 +55,7 @@ public class MyEvent : EventBase This is a sample listener script. You can Subscribe, Unsubscribe events and define functions when your event published. -```c# +```cs public class Listener : MonoBehavior { private void OnEnable() @@ -77,7 +77,7 @@ public class Listener : MonoBehavior **- Publish(EventBase eventType)** This is how you can publish with data. You can send any data sealed with class. -```c# +```cs public class Publisher : MonoBehavior { private void OnCommand()