diff --git a/Megumin.Explosion/Megumin.Explosion.csproj b/Megumin.Explosion/Megumin.Explosion.csproj index 028b5f4..4ae75aa 100644 --- a/Megumin.Explosion/Megumin.Explosion.csproj +++ b/Megumin.Explosion/Megumin.Explosion.csproj @@ -5,9 +5,9 @@ 云却 - 1.0.1.0 - 1.0.1.0 - 1.0.1.0 + 1.0.2.0 + 1.0.2.0 + 1.0.2.0 MeguminLibrary diff --git a/Megumin.Explosion/Megumin/Class/Multiple.cs b/Megumin.Explosion/Megumin/Class/Multiple.cs index 7722c4c..b3e72b6 100644 --- a/Megumin.Explosion/Megumin/Class/Multiple.cs +++ b/Megumin.Explosion/Megumin/Class/Multiple.cs @@ -32,7 +32,7 @@ protected virtual void ApplyValue() Current = newValue; CurrentKey = newKey; - bool flagV = EqualityComparer.Default.Equals(oldValue, newValue); + bool flagV = EqualsValue(oldValue, newValue); //if (old is IEquatable oe) //{ // //转成接口必然装箱 @@ -50,12 +50,60 @@ protected virtual void ApplyValue() OnValueChangedKV((newKey, newValue), (oldKey, oldValue)); } - if (!flagV || !EqualityComparer.Default.Equals(oldKey, newKey)) + if (!flagV || !EqualsKey(oldKey, newKey)) { OnKeyValueChanged((newKey, newValue), (oldKey, oldValue)); } } + /// + /// 判定Key是否相等 + /// + /// + /// + /// + /// + /// 必须使用EqualsKey,EqualsValue两个函数名,不能同名使用重载,否则在子类重写时会提示二义性,无法重写,编译错误。 + /// + protected virtual bool EqualsKey(K x, K y) + { + bool flag = EqualityComparer.Default.Equals(x, 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.Explosion/Megumin/Class/MultipleControl.cs b/Megumin.Explosion/Megumin/Class/MultipleControl.cs index 50efbdb..5e615ca 100644 --- a/Megumin.Explosion/Megumin/Class/MultipleControl.cs +++ b/Megumin.Explosion/Megumin/Class/MultipleControl.cs @@ -208,6 +208,7 @@ protected override (K Key, V Value) CalNewValue() /// 可以将ascending参数设置为true,改为 只要有个一个源为false,结果就是false. /// /// 处理黑屏,碰撞盒开闭 + [Obsolete("use AnyTrueControl instead")] public class ActiveControl : MultipleControl { /// @@ -227,34 +228,54 @@ public ActiveControl(object defaultHandle, { } + } - /// - /// - /// 重写比较方法提高了性能 - /// - protected override void ApplyValue() + /// + /// 开启控制,只要有个一个控制源为true,结果就是true. + /// + /// + /// 例如处理黑屏过渡 + /// + public class AnyTrueControl : MultipleControl + { + public AnyTrueControl(object defaultHandle, + bool defaultValue, + OnValueChanged<(object, bool)> onValueChangedKV = null, + OnValueChanged onValueChanged = null) + : base(defaultHandle, defaultValue, onValueChangedKV, onValueChanged, false) { - var old = Current; - var oldK = CurrentKey; - var result = CalNewValue(); - Current = result.Value; - CurrentKey = result.Key; - bool flagV = old == result.Value; + } - if (!flagV) - { - OnValueChanged(result.Value, old); - OnValueChangedKV((result.Key, result.Value), (oldK, old)); - } + public AnyTrueControl(OnValueChanged<(object, bool)> onValueChangedKV = null, + OnValueChanged onValueChanged = null) + : this(new(), false, onValueChangedKV, onValueChanged) + { - if (!flagV || Equals(oldK, result.Key)) - { - OnKeyValueChanged((result.Key, result.Value), (oldK, old)); - } } } + /// + /// 关闭控制,只要有一个控制源为false,结果就是false. + /// + public class AnyFalseControl : MultipleControl + { + public AnyFalseControl(object defaultHandle, + bool defaultValue, + OnValueChanged<(object, bool)> onValueChangedKV = null, + OnValueChanged onValueChanged = null) + : base(defaultHandle, defaultValue, onValueChangedKV, onValueChanged, true) + { + + } + + public AnyFalseControl(OnValueChanged<(object, bool)> onValueChangedKV = null, + OnValueChanged onValueChanged = null) + : this(new(), true, onValueChangedKV, onValueChanged) + { + + } + } } diff --git a/Megumin.Explosion/Megumin/Interface/IMultiple.cs b/Megumin.Explosion/Megumin/Interface/IMultiple.cs index dd8cacf..2453ccf 100644 --- a/Megumin.Explosion/Megumin/Interface/IMultiple.cs +++ b/Megumin.Explosion/Megumin/Interface/IMultiple.cs @@ -4,9 +4,11 @@ namespace Megumin { - /// - /// 对象有多个部分构成 + /// 对象有多个部分构成。 + /// 根据一个或多个值,得到一个结果值。多个部分可能随时添加或者移除 + /// 运算规则可能为排序,求和,均值等多种算法,用于不同业务场景。 + /// 例如:是否静音由多个业务模块同时控制。最大血量可能由多个装备求和。 /// public interface IMultiple { @@ -32,7 +34,7 @@ public interface IMultiple V Current { get; } /// - /// 加入一个构成项 + /// 添加一个构成项 /// /// /// diff --git a/Megumin.UnityPackage/Packages/megumin.explosion4unity/Plugins/Megumin.Explosion.dll b/Megumin.UnityPackage/Packages/megumin.explosion4unity/Plugins/Megumin.Explosion.dll index 239f05a..b3df2a7 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 87b71dc..f9a3dc2 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 f001c17..9dc2569 100644 --- a/Megumin.UnityPackage/Packages/megumin.explosion4unity/Plugins/Megumin.Explosion.xml +++ b/Megumin.UnityPackage/Packages/megumin.explosion4unity/Plugins/Megumin.Explosion.xml @@ -631,6 +631,17 @@ 应用值,使用比较是否发生改变,优化了装箱. + + + 判定Key是否相等 + + + + + + 必须使用EqualsKey,EqualsValue两个函数名,不能同名使用重载,否则在子类重写时会提示二义性,无法重写,编译错误。 + + 计算新的值, 返回值也可以用KeyValuePair,没什么区别. @@ -798,10 +809,17 @@ 默认false,降序排列,true=1排在false=0前面,结果为第一个值.任意一个true结果就true - + - - 重写比较方法提高了性能 + 开启控制,只要有个一个控制源为true,结果就是true. + + + 例如处理黑屏过渡 + + + + + 关闭控制,只要有一个控制源为false,结果就是false. @@ -1476,7 +1494,10 @@ - 对象有多个部分构成 + 对象有多个部分构成。 + 根据一个或多个值,得到一个结果值。多个部分可能随时添加或者移除 + 运算规则可能为排序,求和,均值等多种算法,用于不同业务场景。 + 例如:是否静音由多个业务模块同时控制。最大血量可能由多个装备求和。 @@ -1502,7 +1523,7 @@ - 加入一个构成项 + 添加一个构成项 diff --git a/Megumin.UnityPackage/Packages/megumin.explosion4unity/package.json b/Megumin.UnityPackage/Packages/megumin.explosion4unity/package.json index a2a7c12..1f537a0 100644 --- a/Megumin.UnityPackage/Packages/megumin.explosion4unity/package.json +++ b/Megumin.UnityPackage/Packages/megumin.explosion4unity/package.json @@ -1,7 +1,7 @@ { "name": "com.megumin.explosion4unity", "displayName": "Explosion", - "version": "4.1.0", + "version": "4.2.0", "unity": "2021.3", "description": "KumoKyaku's personal common library.\n\n[KumoKyaku](https://github.com/KumoKyaku)\u7684\u79c1\u4eba\u516c\u5171\u7c7b\u5e93\uff0c\u5305\u542b\u4e00\u4e9b\u5e38\u7528\u7684\u7c7b\u548c\u6269\u5c55\u51fd\u6570\u3002", "documentationUrl": "https://github.com/KumoKyaku/Megumin.Explosion", diff --git a/UnitTestProject1/Megumin/Class/ActiveControlTests.cs b/UnitTestProject1/Megumin/Class/ActiveControlTests.cs index 2ef041f..228ff5b 100644 --- a/UnitTestProject1/Megumin/Class/ActiveControlTests.cs +++ b/UnitTestProject1/Megumin/Class/ActiveControlTests.cs @@ -14,7 +14,7 @@ public class ActiveControlTests [TestMethod()] public void ActiveControlRentAutoReturn() { - ActiveControl control = new ActiveControl(new object(), false); + AnyTrueControl control = new AnyTrueControl(); Assert.AreEqual(false, control); var c1 = new object();