Merge branch 'main' of https://git.firstvillain.com/Public/AssetBase
This commit is contained in:
commit
717a70ba23
89
README.md
89
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.
|
||||
```cs
|
||||
public class YourClass : UnitySingleton<YourClass>
|
||||
{
|
||||
//your class codes
|
||||
}
|
||||
```
|
||||
|
||||
**- UnitySingletonOnce**
|
||||
- Singleton without DontDestroyOnLoad
|
||||
- This script and object will be removed when scene has changed.
|
||||
```cs
|
||||
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.
|
||||
```cs
|
||||
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.
|
||||
```cs
|
||||
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.
|
||||
```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.
|
||||
|
|
Loading…
Reference in New Issue
Block a user