Skip to content

Commit 07a9b7e

Browse files
committed
- Release v1.0.0
1 parent 04d5043 commit 07a9b7e

File tree

227 files changed

+10114
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

227 files changed

+10114
-0
lines changed

Attributes.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Attributes/BindAttribute.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using System;
2+
3+
namespace EasyCS
4+
{
5+
6+
[AttributeUsage(AttributeTargets.Field)]
7+
public class BindAttribute : Attribute { }
8+
9+
}

Attributes/BindAttribute.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Attributes/RuntimeOnlyAttribute.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using System;
2+
3+
namespace EasyCS
4+
{
5+
public class RuntimeOnlyAttribute : Attribute
6+
{
7+
8+
}
9+
}

Attributes/RuntimeOnlyAttribute.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Di System.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Di System/EasyCSContainer.cs

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using UnityEngine;
4+
5+
namespace EasyCS
6+
{
7+
public partial class EasyCSContainer : IEasyCSObjectResolver, IUpdate, IFixedUpdate, ILateUpdate, IAwake, IStart, IDisposable
8+
{
9+
protected readonly Dictionary<Type, object> _fallbackServices = new();
10+
protected readonly List<IHasContainer> _hasContainers = new();
11+
protected readonly List<IAwake> _awakeServices = new();
12+
protected readonly List<IStart> _startServices = new();
13+
protected readonly List<IUpdate> _updateServices = new();
14+
protected readonly List<IFixedUpdate> _fixedUpdateServices = new();
15+
protected readonly List<ILateUpdate> _lateUpdateServices = new();
16+
protected readonly List<IDisposable> _disposableServices = new();
17+
private bool _firstUpdatePassed;
18+
private bool _firstFixedUpdatePassed;
19+
private bool _firstLateUpdatePassed;
20+
21+
protected void RegisterInternal<T>(T instance)
22+
{
23+
Type type = typeof(T);
24+
_fallbackServices[type] = instance;
25+
26+
if (instance is IHasContainer hasContainer) _hasContainers.Add(hasContainer);
27+
if (instance is IAwake awake) _awakeServices.Add(awake);
28+
if (instance is IStart start) _startServices.Add(start);
29+
if (instance is IUpdate update) _updateServices.Add(update);
30+
if (instance is IFixedUpdate fixedUpdate) _fixedUpdateServices.Add(fixedUpdate);
31+
if (instance is ILateUpdate lateUpdate) _lateUpdateServices.Add(lateUpdate);
32+
if (instance is IDisposable disposable) _disposableServices.Add(disposable);
33+
}
34+
35+
public void HandleInstantiate<T>(T instance)
36+
{
37+
if (instance is IHasContainer hasContainer)
38+
hasContainer.SetupContainer(this);
39+
}
40+
41+
public void HandleInstantiate(GameObject instance)
42+
{
43+
PrefabRootData rootData = instance.GetComponent<PrefabRootData>();
44+
if (rootData != null)
45+
{
46+
for (int i = 0; i < rootData.HasContainers.Count; i++)
47+
{
48+
IHasContainer hasContainer = (IHasContainer)rootData.HasContainers[i];
49+
HandleInstantiate(hasContainer);
50+
}
51+
}
52+
}
53+
54+
private void SetupServicesDependencies()
55+
{
56+
foreach (var hasContainer in _hasContainers)
57+
{
58+
hasContainer.SetupContainer(this);
59+
}
60+
}
61+
62+
public void OnAwake()
63+
{
64+
Debug.Log("[EasyCS] Awake has been called");
65+
66+
SetupServicesDependencies();
67+
68+
foreach (var service in _awakeServices)
69+
service.OnAwake();
70+
71+
Debug.Log("[EasyCS] Awake has been completed");
72+
}
73+
74+
public void OnStart()
75+
{
76+
Debug.Log("[EasyCS] Start has been called");
77+
78+
foreach (var service in _startServices)
79+
service.OnStart();
80+
81+
Debug.Log("[EasyCS] Start has been completed");
82+
}
83+
84+
public void OnUpdate(float deltaTime)
85+
{
86+
bool logCompletion = false;
87+
88+
if (!_firstUpdatePassed)
89+
{
90+
Debug.Log("[EasyCS] First Update has been called");
91+
_firstUpdatePassed = true;
92+
logCompletion = true;
93+
}
94+
95+
foreach (var service in _updateServices)
96+
service.OnUpdate(deltaTime);
97+
98+
if (logCompletion)
99+
{
100+
Debug.Log("[EasyCS] First Update has been completed");
101+
}
102+
}
103+
104+
public void OnFixedUpdate(float deltaTime)
105+
{
106+
bool logCompletion = false;
107+
108+
if (!_firstFixedUpdatePassed)
109+
{
110+
Debug.Log("[EasyCS] First Fixed Update has been called");
111+
_firstFixedUpdatePassed = true;
112+
logCompletion = true;
113+
}
114+
115+
foreach (var service in _fixedUpdateServices)
116+
service.OnFixedUpdate(deltaTime);
117+
118+
if (logCompletion)
119+
{
120+
Debug.Log("[EasyCS] First Fixed Update has been completed");
121+
}
122+
}
123+
124+
public void OnLateUpdate(float deltaTime)
125+
{
126+
bool logCompletion = false;
127+
128+
if (!_firstLateUpdatePassed)
129+
{
130+
Debug.Log("[EasyCS] First Late Update has been called");
131+
_firstLateUpdatePassed = true;
132+
logCompletion = true;
133+
}
134+
135+
foreach (var service in _lateUpdateServices)
136+
service.OnLateUpdate(deltaTime);
137+
138+
if (logCompletion)
139+
{
140+
Debug.Log("[EasyCS] First Late Update has been completed");
141+
}
142+
}
143+
144+
public void Dispose()
145+
{
146+
foreach (var disposable in _disposableServices)
147+
disposable.Dispose();
148+
149+
_awakeServices.Clear();
150+
_startServices.Clear();
151+
_updateServices.Clear();
152+
_fixedUpdateServices.Clear();
153+
_lateUpdateServices.Clear();
154+
_disposableServices.Clear();
155+
_fallbackServices.Clear();
156+
}
157+
}
158+
}

Di System/EasyCSContainer.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Di System/EasyCSContainerUnity.cs

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
using System;
2+
using UnityEngine;
3+
4+
namespace EasyCS
5+
{
6+
#if !VCONTAINER_ENABLED && !ZENJECT_ENABLED
7+
public partial class EasyCSContainer
8+
{
9+
public void Register<T>(T instance)
10+
{
11+
RegisterInternal(instance);
12+
}
13+
14+
public T Resolve<T>() => (T)_fallbackServices[typeof(T)];
15+
16+
public object Resolve(Type type) => _fallbackServices[type];
17+
18+
public T TryResolve<T>() => _fallbackServices.TryGetValue(typeof(T), out var value) ? (T)value : default;
19+
20+
public object TryResolve(Type type) => _fallbackServices.TryGetValue(type, out var value) ? value : null;
21+
22+
public T Instantiate<T>() where T : new()
23+
{
24+
T instance = new T();
25+
HandleInstantiate(instance);
26+
return instance;
27+
}
28+
29+
public object Instantiate(Type type)
30+
{
31+
object instance = Activator.CreateInstance(type);
32+
HandleInstantiate(instance);
33+
return instance;
34+
}
35+
36+
public GameObject Instantiate(GameObject prefab)
37+
{
38+
GameObject instance = UnityEngine.Object.Instantiate(prefab);
39+
HandleInstantiate(instance);
40+
return instance;
41+
}
42+
43+
public GameObject Instantiate(GameObject prefab, Transform parent)
44+
{
45+
GameObject instance = UnityEngine.Object.Instantiate(prefab, parent);
46+
HandleInstantiate(instance);
47+
return instance;
48+
}
49+
50+
public GameObject Instantiate(GameObject prefab, Vector3 position, Quaternion rotation)
51+
{
52+
GameObject instance = UnityEngine.Object.Instantiate(prefab, position, rotation);
53+
HandleInstantiate(instance);
54+
return instance;
55+
}
56+
57+
}
58+
#endif
59+
}

Di System/EasyCSContainerUnity.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)