Skip to content

Commit aa3a97f

Browse files
committed
Update file(s) "Packages/unity-utils/." from "unity-korea-community/unity-utils"
1 parent 471484e commit aa3a97f

11 files changed

+76
-21
lines changed

Runtime/DataSender/DataSender.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ public class DataSender<T> : IObservable<T>, IDisposable
1313
public void SendData(T data)
1414
{
1515
foreach (var item in _observers)
16+
{
1617
item.OnNext(data);
18+
}
1719

1820
_lastSendedData = data;
1921
}
@@ -27,7 +29,9 @@ public void Reset()
2729
public IDisposable Subscribe(IObserver<T> observer)
2830
{
2931
if (_observers.Contains(observer) == false)
32+
{
3033
_observers.Add(observer);
34+
}
3135
observer.OnNext(_lastSendedData);
3236

3337
Unsubscriber<T> unsubscriber = _pool.Spawn();
@@ -63,11 +67,13 @@ public void UnSubscribe(IObserver<T> observer)
6367
public void Dispose()
6468
{
6569
foreach (IObserver<T> observer in _observers)
70+
{
6671
observer.OnCompleted();
72+
}
6773

6874
_observers.Clear();
6975
_pool.DeSpawnAll();
7076
_observers = null;
7177
}
7278
}
73-
}
79+
}

Runtime/DataSender/DataSenderUnityExtension.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ public static DataSender<T> InitSiblingComponents<T>(this DataSender<T> target,
3939
{
4040
Transform sibling = parnet.GetChild(i);
4141
if (sibling == transform)
42+
{
4243
continue;
44+
}
4345

4446
sibling.GetComponents<IObserver<T>>(siblings);
4547
target.Subscribe(siblings);

Runtime/Extension/CollectionExtension.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ public static string ToStringCollection<T>(this T[] target)
2121
{
2222
_stringBuilder.Append(target[i].ToString());
2323
if (i < target.Length - 1)
24+
{
2425
_stringBuilder.Append(", ");
26+
}
2527
}
26-
2728
_stringBuilder.Append("]");
28-
2929
}
3030

3131
return _stringBuilder.ToString();

Runtime/Extension/RandomExtension.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ public static T Random<T>(this IEnumerable<T> target, System.Func<T, int> getPer
2626
{
2727
totalvariable += getPercentage(item);
2828
if (random < totalvariable)
29+
{
2930
return item;
31+
}
3032
}
3133

3234
return default;

Runtime/SimplePool.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public SimplePool(T originItem)
2020
Init(originItem, 0);
2121
}
2222

23-
public SimplePool(T originItem, int initializeSize = 0)
23+
public SimplePool(T originItem, int initializeSize)
2424
{
2525
_OnCreateInstance = (origin) => Activator.CreateInstance<T>();
2626
Init(originItem, initializeSize);
@@ -61,7 +61,9 @@ public T Spawn()
6161
public void DeSpawn(T item)
6262
{
6363
if (_use.Contains(item) == false)
64+
{
6465
return;
66+
}
6567

6668
OnDespawn(item);
6769
_use.Remove(item);
@@ -71,7 +73,9 @@ public void DeSpawn(T item)
7173
public void DeSpawnAll()
7274
{
7375
while (_use.Count > 0)
76+
{
7477
DeSpawn(_use.Last());
78+
}
7579
}
7680

7781
protected virtual T OnRequireNewInstance(T originItem) => _OnCreateInstance(originItem);
@@ -83,7 +87,9 @@ protected void Init(T originItem, int initializeSize)
8387
_originItem = originItem;
8488

8589
for (int i = 0; i < initializeSize; i++)
90+
{
8691
Spawn();
92+
}
8793
DeSpawnAll();
8894
}
8995
}

Runtime/SingletonComponentBase.cs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,30 @@ public static T instance
99
{
1010
get
1111
{
12-
if (s_isQuitApp)
12+
if (_isQuitApp)
13+
{
1314
return default;
15+
}
1416

15-
if (s_instance == null)
17+
if (_instance == null)
1618
{
17-
s_instance = FindObjectOfType<T>();
18-
s_instance.InitSingleton();
19+
_instance = FindObjectOfType<T>();
20+
_instance.InitSingleton();
1921
}
2022

21-
return s_instance;
23+
return _instance;
2224
}
2325
}
2426

25-
private static T s_instance { get; set; }
26-
private static bool s_isQuitApp { get; set; }
27+
private static T _instance { get; set; }
28+
private static bool _isQuitApp { get; set; }
2729

28-
void Awake()
30+
protected virtual void Awake()
2931
{
30-
if (s_instance == null)
32+
if (_instance == null)
33+
{
3134
InitSingleton();
35+
}
3236
}
3337

3438
protected virtual void InitSingleton()
@@ -37,7 +41,7 @@ protected virtual void InitSingleton()
3741

3842
private void OnApplicationQuit()
3943
{
40-
s_isQuitApp = true;
44+
_isQuitApp = true;
4145
}
4246
}
4347
}

Runtime/StateMachineGeneric.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,9 @@ public void Start(MonoBehaviour owner, STATE_ID startState, params STATE_ID[] ne
105105
public void ChangeState(STATE_ID state)
106106
{
107107
if (_debug)
108+
{
108109
Debug.Log($"{_owner.name}.FSM.ChangeState changeState:{state}, wait:{_waitQueue.ToStringCollection()}", _owner);
110+
}
109111

110112
_commandQueue.Add(new Command(CommandType.Change, state));
111113
}
@@ -125,7 +127,9 @@ public void FinishState()
125127
public void EnqueueToWaitQueue(params STATE_ID[] nextStates)
126128
{
127129
if (_waitQueue.Count > 10)
130+
{
128131
Debug.LogWarning($"{_owner.name} _waitQueue.Count > 10, wait:{_waitQueue.ToStringCollection()}", _owner);
132+
}
129133
nextStates.Foreach(state => _waitQueue.Add(state));
130134
}
131135

@@ -158,10 +162,14 @@ IEnumerator UpdateCoroutine()
158162
while (true)
159163
{
160164
while (_commandQueue.Count > 0)
165+
{
161166
ProcessCommand(_commandQueue.Dequeue());
167+
}
162168

163169
if (currentState == null && _waitQueue.Count > 0)
170+
{
164171
OnStartState(_waitQueue.Dequeue());
172+
}
165173

166174
yield return null;
167175
}
@@ -187,7 +195,9 @@ private void ProcessCommand(Command command)
187195
private void OnStartState(STATE_ID stateID)
188196
{
189197
if (_debug)
198+
{
190199
Debug.Log($"{_owner.name}.FSM.OnStartState.Entry current:{currentStateID}, new:{stateID}, wait:{_waitQueue.ToStringCollection()}", _owner);
200+
}
191201

192202
if (_stateInstance.TryGetValue(stateID, out TSTATE state) == false)
193203
{
@@ -196,10 +206,14 @@ private void OnStartState(STATE_ID stateID)
196206
}
197207

198208
if (state.Equals(currentState))
209+
{
199210
return;
211+
}
200212

201213
if (_debug)
214+
{
202215
Debug.Log($"{_owner.name}.FSM.OnStartState.Execute current:{currentStateID}, new:{stateID}, wait:{_waitQueue.ToStringCollection()}", _owner);
216+
}
203217

204218
currentState?.OnChangeState(state);
205219
state.OnAwake();
@@ -212,10 +226,14 @@ private void OnStartState(STATE_ID stateID)
212226
private void OnFinishState()
213227
{
214228
if (_debug)
229+
{
215230
Debug.Log($"{_owner.name}.FSM.OnFinishState current:{currentStateID}, wait:{_waitQueue.ToStringCollection()}");
231+
}
216232

217233
if (_currentCoroutine != null)
234+
{
218235
_owner.StopCoroutine(_currentCoroutine);
236+
}
219237
currentState?.OnFinishState();
220238
currentState = null;
221239
_currentStateID = default;

Runtime/UnitytComponentPool.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,21 @@ public class UnitytComponentPool<T> : SimplePool<T>
88
{
99
Transform _parent;
1010

11-
public UnitytComponentPool(T originItem, int initializeSize = 0) : base(originItem, initializeSize)
11+
public UnitytComponentPool(T originItem) : base(originItem)
1212
{
1313
originItem.gameObject.SetActive(false);
1414
}
1515

16-
public UnitytComponentPool(Func<T> onCreateInstance, int initializeSize = 0) : base(onCreateInstance, initializeSize)
16+
public UnitytComponentPool(T originItem, int initializeSize) : base(originItem, initializeSize)
17+
{
18+
originItem.gameObject.SetActive(false);
19+
}
20+
21+
public UnitytComponentPool(Func<T> onCreateInstance) : base(onCreateInstance)
22+
{
23+
}
24+
25+
public UnitytComponentPool(Func<T> onCreateInstance, int initializeSize) : base(onCreateInstance, initializeSize)
1726
{
1827
}
1928

@@ -28,7 +37,9 @@ protected override T OnRequireNewInstance(T originItem)
2837
{
2938
T newInstance = base.OnRequireNewInstance(originItem);
3039
if (_parent != null)
40+
{
3141
newInstance.transform.SetParent(_parent);
42+
}
3243

3344
newInstance.gameObject.SetActive(false);
3445
return newInstance;

Runtime/Unsubscriber.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@ public void Reset(HashSet<IObserver<T>> observers, IObserver<T> observer, Action
2727
public void Dispose()
2828
{
2929
if (_observer != null)
30+
{
3031
_observers.Remove(_observer);
32+
}
3133

3234
_onDisplose?.Invoke(this);
3335
}
3436
}
35-
}
37+
}

Tests/Runtime/DataSenderTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ public class DataSenderTests
77
{
88
public class TestData
99
{
10-
public string stringData;
11-
public int numberData;
10+
public string stringData { get; private set; }
11+
public int numberData { get; private set; }
1212

1313
public TestData(int numberData)
1414
{
@@ -59,4 +59,4 @@ public void 사용예시()
5959
Assert.AreEqual(receiverComponent.data.stringData, testData.stringData);
6060
Assert.AreEqual(receiverComponent.data.numberData, testData.numberData);
6161
}
62-
}
62+
}

Tests/Runtime/SimplePoolTests.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ static public class Factory
1919
{
2020
static public SimplePoolTarget CreateInstance_FromFactory()
2121
{
22-
return new SimplePoolTarget() { isCreateFromFactory = true };
22+
return new SimplePoolTarget { isCreateFromFactory = true };
2323
}
2424
}
2525

@@ -56,10 +56,14 @@ public void 사용예시()
5656
int spawnCount = Random.Range(2, totalInstanceCount);
5757
HashSet<SimplePoolTarget> set = new HashSet<SimplePoolTarget>();
5858
for (int j = 0; j < spawnCount; j++)
59+
{
5960
set.Add(pool.Spawn());
61+
}
6062

6163
foreach (var item in set)
64+
{
6265
pool.DeSpawn(item);
66+
}
6367
}
6468

6569
Assert.AreEqual(pool.allInstance.Count, totalInstanceCount);

0 commit comments

Comments
 (0)