diff --git a/Megumin.Explosion/Megumin/Class/EqualComparer.cs b/Megumin.Explosion/Megumin/Class/EqualComparer.cs
new file mode 100644
index 0000000..0c935d6
--- /dev/null
+++ b/Megumin.Explosion/Megumin/Class/EqualComparer.cs
@@ -0,0 +1,54 @@
+using System;
+using System.Collections.Generic;
+
+namespace Megumin
+{
+ ///
+ /// 解决泛型不能直接判断 == 问题
+ /// "/>
+ ///
+ ///
+ public class EqualComparer
+ {
+ protected virtual bool EqualsKey(object x, object y)
+ {
+ return x == y;
+ }
+
+ protected virtual bool EqualsValue(object x, object y)
+ {
+ return x == y;
+ }
+
+ protected bool EqualsValue(bool x, bool y)
+ {
+ return x == y;
+ }
+
+ protected bool EqualsValue(int x, int y)
+ {
+ return x == y;
+ }
+
+ protected bool EqualsValue(float x, float y)
+ {
+ return x == y;
+ }
+
+ protected virtual bool EqualsValue(V x, V y)
+ {
+ bool flag = EqualityComparer.Default.Equals(x, y);
+ return flag;
+ }
+
+ protected virtual bool EqualsValue(N x, N y)
+ where N : IEquatable
+ {
+ bool flag = x.Equals(y);
+ return flag;
+ }
+ }
+}
+
+
+
diff --git a/Megumin.Explosion/Megumin/Class/EventValue.cs b/Megumin.Explosion/Megumin/Class/EventValue.cs
index 2844cea..f61d755 100644
--- a/Megumin.Explosion/Megumin/Class/EventValue.cs
+++ b/Megumin.Explosion/Megumin/Class/EventValue.cs
@@ -4,7 +4,7 @@
namespace Megumin
{
[Serializable]
- public partial class EventValue
+ public partial class EventValue : EqualComparer
{
///
/// 这里public是为了能在unity中序列化,这里没办法标记SerializeField
@@ -40,14 +40,36 @@ public T Value
}
}
- public void SetValue(T value)
+ ///
+ ///
+ ///
+ ///
+ /// Ignore = -1,Force:101,
+ public void SetValue(T value, int raiseEvent = 0)
{
- Value = value;
+ var old = this.value;
+ this.value = value;
+
+ //先赋值完成在触发回调
+ if (raiseEvent >= 0)
+ {
+ OnValueSet?.Invoke(value, old);
+ if (raiseEvent > 100)
+ {
+ if (OnValueChanged != null)
+ {
+ if (!EqualsValue(value, old))
+ {
+ OnValueChanged.Invoke(value, old);
+ }
+ }
+ }
+ }
}
public void SetValueSilent(T value)
{
- this.value = value;
+ SetValue(value, -1);
}
}
diff --git a/Megumin.Explosion/Megumin/Class/Multiple.cs b/Megumin.Explosion/Megumin/Class/Multiple.cs
index af98720..e7f0c76 100644
--- a/Megumin.Explosion/Megumin/Class/Multiple.cs
+++ b/Megumin.Explosion/Megumin/Class/Multiple.cs
@@ -9,7 +9,7 @@ namespace Megumin
///
///
///
- public abstract partial class Multiple : IMultiple
+ public abstract partial class Multiple : EqualComparer, IMultiple
{
protected readonly Dictionary ElementDic = new Dictionary();
public event OnChanged ValueChanged;
@@ -92,39 +92,6 @@ protected virtual bool EqualsKey(K x, K y)
return flag;
}
- protected virtual bool EqualsValue(V x, V y)
- {
- bool flag = EqualityComparer.Default.Equals(x, y);
- return flag;
- }
-
- //public bool Equals(object objA, object objB)
- //{
- // return object.Equals(objA, objB);
- //}
-
- protected virtual bool EqualsKey(object x, object y)
- {
- return Equals(x, y);
- }
-
- protected bool EqualsValue(bool x, bool y)
- {
- return x == y;
- }
-
- protected bool EqualsValue(int x, int y)
- {
- return x == y;
- }
-
- protected virtual bool EqualsValue(N x, N y)
- where N : IEquatable
- {
- bool flag = x.Equals(y);
- return flag;
- }
-
///
/// 计算新的值, 返回值也可以用KeyValuePair,没什么区别.
///
diff --git a/Megumin.UnityPackage/Packages/megumin.explosion4unity/Plugins/Megumin.Explosion.dll b/Megumin.UnityPackage/Packages/megumin.explosion4unity/Plugins/Megumin.Explosion.dll
index 01b49ec..ffdeae2 100644
Binary files a/Megumin.UnityPackage/Packages/megumin.explosion4unity/Plugins/Megumin.Explosion.dll and b/Megumin.UnityPackage/Packages/megumin.explosion4unity/Plugins/Megumin.Explosion.dll differ
diff --git a/Megumin.UnityPackage/Packages/megumin.explosion4unity/Plugins/Megumin.Explosion.pdb b/Megumin.UnityPackage/Packages/megumin.explosion4unity/Plugins/Megumin.Explosion.pdb
index 0925559..914f316 100644
Binary files a/Megumin.UnityPackage/Packages/megumin.explosion4unity/Plugins/Megumin.Explosion.pdb and b/Megumin.UnityPackage/Packages/megumin.explosion4unity/Plugins/Megumin.Explosion.pdb differ
diff --git a/Megumin.UnityPackage/Packages/megumin.explosion4unity/Plugins/Megumin.Explosion.xml b/Megumin.UnityPackage/Packages/megumin.explosion4unity/Plugins/Megumin.Explosion.xml
index 1882c19..10f37fe 100644
--- a/Megumin.UnityPackage/Packages/megumin.explosion4unity/Plugins/Megumin.Explosion.xml
+++ b/Megumin.UnityPackage/Packages/megumin.explosion4unity/Plugins/Megumin.Explosion.xml
@@ -419,11 +419,25 @@
C# 不允许匿名类实现接口,所以必须声明一个类型。
+
+
+ 解决泛型不能直接判断 == 问题
+ "/>
+
+
+
这里public是为了能在unity中序列化,这里没办法标记SerializeField
+
+
+
+
+
+ Ignore = -1,Force:101,
+
为什么需要这个类型包装一次,IObserver.OnNext 不能与ValueChange时间匹配。