Help to use IOCContainer more convenience.
You can add package from git url through the Package Manager.
All the following package should be added.
Package | Description |
---|---|
https://github.com/kakashiio/Unity-Reflection.git#1.0.0 | Reflection Library |
https://github.com/kakashiio/Unity-IOC.git#1.0.0 | IOC Library |
https://github.com/kakashiio/Unity-IOC-Unity.git#1.0.0 | IOC-Unity Library |
The basic usage of UnityIOCContainer
is in the sample script BasicDemo.cs
ITypeContainer typeContainer = new TypeContainerCollection(new List<ITypeContainer>
{
new TypeContainer(Assembly.GetExecutingAssembly()),
new TypeContainer(typeof(UnityIOCContainer).Assembly),
new TypeContainer(typeof(IOCContainer).Assembly)
});
new UnityIOCContainer(typeContainer);
Add the code above at the first your application is startup.
- IUnityUpdate
- IUnityLateUpdate
- IUnityFixedUpdate
- IUnityGUI
- IUnityApplication
- IUnityEditor
Assume that you want to let something invoke per frame. The traditional way to achieve this requirement is define a MonoBehaviour, write the per frame code
in that MonoBehaviour's Update
method. With the IOC
library and this IOC-Unity
library. You can simply do it like the following code:
[IOCComponent]
public class NormalClassButNotMonoBehaviour : IUnityUpdate
{
public void Update()
{
// Your per frame code here
}
}
This way will be more high performance than the traditional way.
Help to execute coroutine more convenience. If you want to execute some coroutine. You could simple write the following code:
[IOCComponent]
public class HttpManager4Demo : IUnityGUI
{
[Autowired]
private CoroutineManager _CoroutineManager;
public void Get(string url, Action<string> onGet)
{
_CoroutineManager.StartCoroutine(_StartGet(url, onGet));
}
private IEnumerator _StartGet(string url, Action<string> onGet, Action<string> onError = null)
{
UnityWebRequest unityWebRequest = UnityWebRequest.Get(url);
yield return unityWebRequest.SendWebRequest();
if (unityWebRequest.result == UnityWebRequest.Result.Success)
{
onGet?.Invoke(unityWebRequest.downloadHandler.text);
}
else
{
onError?.Invoke(unityWebRequest.error);
}
}
public void OnGUI()
{
if (GUILayout.Button("Get"))
{
Get("https://unity3d.io", (msg) => Debug.Log(msg));
}
}
}
Will increase more Unity API and Component for game development requirement. Looking forward to your suggestion if you have some requirements.