# 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. ```cs public class YourClass : UnitySingleton { //your class codes } ``` **- UnitySingletonOnce** - Singleton without DontDestroyOnLoad - This script and object will be removed when scene has changed. ```cs 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. ```cs public class MyEvent : EventBase { public int _value1; public object _value2; ... } ``` This is a sample listener script. You can 'Subscribe' and 'Unsubscribe' events with callback function, act after you published event. ```cs 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. ```cs public class Publisher : MonoBehavior { private void OnCommand() { EventBus.Instance.Puplish(new MyEvent()); } } ``` **- Clear()** This will be used when you need to clear all subscribtions.