Skip to content

Commit 471484e

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

9 files changed

+62
-25
lines changed

Runtime/Extension/CollectionExtension.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ public static HashSet<T> ToHashSet<T>(this IEnumerable<T> target)
3939
public static IEnumerable<T> Foreach<T>(this IEnumerable<T> target, System.Action<T> OnEach)
4040
{
4141
foreach (var item in target)
42+
{
4243
OnEach(item);
44+
}
4345

4446
return target;
4547
}

Runtime/SimplePool.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,25 @@ public class SimplePool<T>
1414
protected T _originItem { get; private set; }
1515
protected Func<T, T> _OnCreateInstance;
1616

17+
public SimplePool(T originItem)
18+
{
19+
_OnCreateInstance = (origin) => Activator.CreateInstance<T>();
20+
Init(originItem, 0);
21+
}
22+
1723
public SimplePool(T originItem, int initializeSize = 0)
1824
{
1925
_OnCreateInstance = (origin) => Activator.CreateInstance<T>();
2026
Init(originItem, initializeSize);
2127
}
2228

23-
public SimplePool(Func<T> onCreateInstance, int initializeSize = 0)
29+
public SimplePool(Func<T> onCreateInstance)
30+
{
31+
_OnCreateInstance = (origin) => onCreateInstance();
32+
Init(onCreateInstance(), 0);
33+
}
34+
35+
public SimplePool(Func<T> onCreateInstance, int initializeSize)
2436
{
2537
_OnCreateInstance = (origin) => onCreateInstance();
2638
Init(onCreateInstance(), initializeSize);

Runtime/SingletonComponentBase.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ public static T instance
2222
}
2323
}
2424

25-
private static T s_instance;
26-
protected static bool s_isQuitApp { get; private set; } = false;
25+
private static T s_instance { get; set; }
26+
private static bool s_isQuitApp { get; set; }
2727

2828
void Awake()
2929
{

Runtime/StateMachineGeneric.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public enum CommandType
2727
}
2828

2929
[System.Serializable]
30-
public struct Command
30+
public struct Command : System.IEquatable<Command>
3131
{
3232
public CommandType commandType { get; private set; }
3333
public STATE_ID stateID { get; private set; }
@@ -43,6 +43,16 @@ public Command(CommandType commandType, STATE_ID stateID)
4343
this.commandType = commandType;
4444
this.stateID = stateID;
4545
}
46+
47+
public bool Equals(Command other)
48+
{
49+
if (commandType.Equals(other.commandType) == false)
50+
{
51+
return false;
52+
}
53+
54+
return stateID.Equals(other.stateID);
55+
}
4656
}
4757

4858
public event System.Action<STATE_ID, TSTATE> OnChangeState;

Runtime/Unsubscriber.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,14 @@ public class Unsubscriber<T> : IDisposable
1010
private IObserver<T> _observer;
1111
private Action<Unsubscriber<T>> _onDisplose;
1212

13-
public void Reset(HashSet<IObserver<T>> observers, IObserver<T> observer, Action<Unsubscriber<T>> onDisplose = null)
13+
public void Reset(HashSet<IObserver<T>> observers, IObserver<T> observer)
14+
{
15+
this._observers = observers;
16+
this._observer = observer;
17+
this._onDisplose = null;
18+
}
19+
20+
public void Reset(HashSet<IObserver<T>> observers, IObserver<T> observer, Action<Unsubscriber<T>> onDisplose)
1421
{
1522
this._observers = observers;
1623
this._observer = observer;

Tests/Runtime/CollectionExtensionTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ public class CollectionExtensionTests
88
[Test]
99
public void ToStringCollectionExample()
1010
{
11-
string list = new List<int>() { 1, 2, 3, 4, 5 }.ToStringCollection();
11+
string list = new List<int> { 1, 2, 3, 4, 5 }.ToStringCollection();
1212
Debug.Log(list);
1313

14-
string dictionary = new Dictionary<string, int>()
14+
string dictionary = new Dictionary<string, int>
1515
{
1616
{"one", 1}, {"two", 2}, {"three", 3},
1717
}.ToStringCollection();
@@ -21,14 +21,14 @@ public void ToStringCollectionExample()
2121
[Test]
2222
public void ForeachExample()
2323
{
24-
int[] originArray = new int[] { 1, 2, 3, 4, 5 };
24+
int[] originArray = new[] { 1, 2, 3, 4, 5 };
2525
originArray.Foreach(number => Debug.Log(number));
2626
}
2727

2828
[Test]
2929
public void DequeueExample()
3030
{
31-
List<int> list = new List<int>() { 1, 2, 3 };
31+
List<int> list = new List<int> { 1, 2, 3 };
3232
Assert.AreEqual(list.Dequeue(), 1);
3333
Assert.AreEqual(list.Count, 2);
3434

@@ -42,7 +42,7 @@ public void DequeueExample()
4242
[Test]
4343
public void PopExample()
4444
{
45-
List<int> list = new List<int>() { 1, 2, 3 };
45+
List<int> list = new List<int> { 1, 2, 3 };
4646
Assert.AreEqual(list.Pop(), 3);
4747
Assert.AreEqual(list.Count, 2);
4848

Tests/Runtime/DataSenderTests.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
public class DataSenderTests
77
{
8-
public struct TestData
8+
public class TestData
99
{
1010
public string stringData;
1111
public int numberData;
@@ -26,8 +26,15 @@ public class TestReceiver : MonoBehaviour, IObserver<TestData>
2626
{
2727
public TestData data { get; private set; }
2828

29-
public void OnCompleted() { }
30-
public void OnError(Exception error) { }
29+
public void OnCompleted()
30+
{
31+
// Do nothing because test
32+
}
33+
34+
public void OnError(Exception error)
35+
{
36+
// Do nothing because test
37+
}
3138

3239
public void OnNext(TestData value)
3340
{

Tests/Runtime/RandomExtensionTests.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public class RandomExtensionTests
99
[Test]
1010
public void RandomWorks()
1111
{
12-
int[] numbers = new int[] { 1, 2, 3, 4, 5 };
12+
int[] numbers = new[] { 1, 2, 3, 4, 5 };
1313
Debug.Log(numbers.Random());
1414
Debug.Log(numbers.Random());
1515
}
@@ -30,14 +30,14 @@ public Item(string name, int percent)
3030
public void RandomPercent()
3131
{
3232
// Arrange
33-
Item[] items = new Item[] {
33+
Item[] items = new[] {
3434
new Item("normal sword", 80),
3535
new Item("epic sword", 19),
3636
new Item("regendary sword", 1),
3737
};
3838

3939
int gotchaCount = 1000;
40-
Dictionary<string, int> hasItemCount = new Dictionary<string, int>()
40+
Dictionary<string, int> hasItemCount = new Dictionary<string, int>
4141
{
4242
{"normal", 0}, {"epic", 0}, {"regendary", 0}
4343
};
@@ -61,20 +61,19 @@ public void RandomPercent()
6161
for (int i = 0; i < items.Length; i++)
6262
{
6363
Item item = items[i];
64-
float errorRate = 0.2f;
64+
float errorRate = 0.5f; // 랜덤에 걸리지 않기 위해 범위를 많이 넓힘
6565
int expectCount = (int)(gotchaCount * (item.percent / 100f));
6666
int errorRange = (int)(expectCount * errorRate);
6767
KeyValuePair<string, int> itemCount = hasItemCount.First(hasItem => item.name.StartsWith(hasItem.Key));
6868

69-
// 대부분 통과하나, 랜덤 확률에 의해 가끔 실패함..
70-
// Assert.GreaterOrEqual(itemCount.Value, expectCount - errorRange);
69+
Assert.GreaterOrEqual(itemCount.Value, expectCount - errorRange);
7170
}
7271
}
7372

7473
[Test]
7574
public void RandomFilter()
7675
{
77-
int[] numbers = new int[] { 1, 2, 3, 4, 5 };
76+
int[] numbers = new[] { 1, 2, 3, 4, 5 };
7877
HashSet<int> set = new HashSet<int>();
7978

8079
for (int i = 0; i < numbers.Length; i++)

Tests/Runtime/SimplePoolTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public class SimplePoolTests
88
{
99
public class SimplePoolTarget
1010
{
11-
public static int instanceCount { get; private set; } = 0;
11+
public static int instanceCount { get; private set; }
1212

1313
public static void Reset_InstanceCount()
1414
{
@@ -17,13 +17,13 @@ public static void Reset_InstanceCount()
1717

1818
static public class Factory
1919
{
20-
static public SimplePoolTarget CreateInstance()
20+
static public SimplePoolTarget CreateInstance_FromFactory()
2121
{
2222
return new SimplePoolTarget() { isCreateFromFactory = true };
2323
}
2424
}
2525

26-
public bool isCreateFromFactory { get; private set; } = false;
26+
public bool isCreateFromFactory { get; private set; }
2727

2828
public SimplePoolTarget()
2929
{
@@ -69,13 +69,13 @@ public void 사용예시()
6969

7070
public class PoolEx : SimplePool<SimplePoolTarget>
7171
{
72-
public PoolEx(int initializeSize = 0) : base(new SimplePoolTarget(), initializeSize)
72+
public PoolEx(int initializeSize) : base(new SimplePoolTarget(), initializeSize)
7373
{
7474
}
7575

7676
protected override SimplePoolTarget OnRequireNewInstance(SimplePoolTarget originItem)
7777
{
78-
return SimplePoolTarget.Factory.CreateInstance();
78+
return SimplePoolTarget.Factory.CreateInstance_FromFactory();
7979
}
8080
}
8181

0 commit comments

Comments
 (0)