92 lines
2.2 KiB
Markdown
92 lines
2.2 KiB
Markdown
# 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<YourClass>
|
|
{
|
|
//your class codes
|
|
}
|
|
```
|
|
|
|
**- UnitySingletonOnce**
|
|
- Singleton without DontDestroyOnLoad
|
|
- This script and object will be removed when scene has changed.
|
|
```c#
|
|
public class YourClass : UnitySingletonOnce<YourClass>
|
|
{
|
|
//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<T>(EventDelegate<T> callback) where T : EventBase**
|
|
**- Unsubscribe<T>(EventDelegate<T> 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<MyEvent>(OnMyEvent);
|
|
}
|
|
private voi OnDisable()
|
|
{
|
|
EventBus.Instance.Unsubscribe<MyEvent>(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.
|