Skip to content

Commit 6affd8e

Browse files
committed
- Change ValueHolder's namespace to Core (some items need to be repackaged).
- Add reflection method Components (ReflectionMethodHolderXXX).
1 parent bb59763 commit 6affd8e

File tree

115 files changed

+2590
-1111
lines changed

Some content is hidden

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

115 files changed

+2590
-1111
lines changed

ProjectConfig~/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"dependencies": {
3-
"com.threeyes.alivecursor.sdk": "4.3.4",
3+
"com.threeyes.alivecursor.sdk": "4.3.5",
44
"com.beans.deform": "1.2.1",
55
"com.coffee.ui-effect": "4.0.0-preview.10",
66
"com.dbrizov.naughtyattributes": "2.1.4",

Threeyes/Plugins/ThreeyesPlugin/Core/Extension/LazyExtension_Common.cs

Lines changed: 0 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -272,79 +272,6 @@ public static void WrapRichText(this StringBuilder sB, string color)
272272
}
273273
#endregion
274274

275-
#region Enum
276-
277-
/// <summary>
278-
/// Parse string to Enum,Int, Etc
279-
/// </summary>
280-
/// <typeparam name="T"></typeparam>
281-
/// <param name="myString"></param>
282-
/// <returns></returns>
283-
public static T Parse<T>(this string myString) where T : struct
284-
{
285-
T enumerable = default;
286-
try
287-
{
288-
enumerable = (T)Enum.Parse(typeof(T), myString);
289-
//Foo(enumerable); //Now you have your enum, do whatever you want.
290-
}
291-
catch (Exception)
292-
{
293-
Debug.LogErrorFormat("Parse: Can't convert {0} to enum, please check the spell.", myString);
294-
}
295-
return enumerable;
296-
}
297-
298-
//——Flag——
299-
300-
/// <summary>
301-
/// 检测使用位运算负责的枚举(标记为[Flag]),是否包含某个值(如果报错不会影响后续代码)
302-
/// </summary>
303-
/// <typeparam name="T">枚举类型</typeparam>
304-
/// <param name="en">实例</param>
305-
/// <param name="flag">某个枚举</param>
306-
/// <returns></returns>
307-
public static bool Has(this Enum en, Enum flag, bool ignoreZero = false)
308-
{
309-
try
310-
{
311-
if (ignoreZero && (int)(object)flag == 0)//PS:忽略 (None = 0),否则如果flag为0则一定会返回true
312-
return false;
313-
314-
return en.HasFlag(flag);//PS:Unity2021.2的性能比旧版快100倍以上
315-
//return ((int)(object)en & (int)(object)flag) == (int)(object)flag;//PS: 如果上面的方法在旧版C#不可用,可改用下面的判断
316-
}
317-
catch
318-
{
319-
return false;
320-
}
321-
}
322-
323-
/// <summary>
324-
/// 获取Enum值的具体枚举名称(仅适用于使用了Flag标记的Enum)
325-
/// </summary>
326-
/// <typeparam name="TEnumType"></typeparam>
327-
/// <param name="value"></param>
328-
/// <returns></returns>
329-
public static List<string> GetNamesEx(this Enum value)
330-
{
331-
List<string> result = new List<string>();
332-
Type enumType = value.GetType();
333-
foreach (int i in Enum.GetValues(enumType))
334-
{
335-
if (i == 0 || i == ~0)//排除None或All
336-
continue;
337-
338-
Enum curEnum = Enum.Parse(enumType, i.ToString()) as Enum;
339-
if (value.Has(curEnum))
340-
{
341-
result.Add(curEnum.ToString());
342-
}
343-
}
344-
return result;
345-
}
346-
#endregion
347-
348275
#region Vector Common
349276

350277
/// <summary>
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
using System;
2+
using System.Collections;
3+
using System.Collections.Generic;
4+
using UnityEngine;
5+
namespace Threeyes.Core
6+
{
7+
public static class LazyExtension_Enum
8+
{
9+
/// <summary>
10+
/// Parse string to Enum,Int, Etc
11+
/// </summary>
12+
/// <typeparam name="T"></typeparam>
13+
/// <param name="myString"></param>
14+
/// <returns></returns>
15+
public static T Parse<T>(this string myString) where T : struct
16+
{
17+
T enumerable = default;
18+
try
19+
{
20+
enumerable = (T)Enum.Parse(typeof(T), myString);
21+
//Foo(enumerable); //Now you have your enum, do whatever you want.
22+
}
23+
catch (Exception)
24+
{
25+
Debug.LogErrorFormat("Parse: Can't convert {0} to enum, please check the spell.", myString);
26+
}
27+
return enumerable;
28+
}
29+
30+
//——Flag——
31+
32+
/// <summary>
33+
/// 检测使用位运算负责的枚举(标记为[Flag]),是否包含某个值(如果报错不会影响后续代码)
34+
/// </summary>
35+
/// <typeparam name="T">枚举类型</typeparam>
36+
/// <param name="en">实例</param>
37+
/// <param name="flag">某个枚举</param>
38+
/// <returns></returns>
39+
public static bool Has(this Enum en, Enum flag, bool ignoreZero = false)
40+
{
41+
try
42+
{
43+
if (ignoreZero && (int)(object)flag == 0)//PS:忽略 (None = 0),否则如果flag为0则一定会返回true
44+
return false;
45+
46+
return en.HasFlag(flag);//PS:Unity2021.2的性能比旧版快100倍以上
47+
//return ((int)(object)en & (int)(object)flag) == (int)(object)flag;//PS: 如果上面的方法在旧版C#不可用,可改用下面的判断
48+
}
49+
catch
50+
{
51+
return false;
52+
}
53+
}
54+
55+
/// <summary>
56+
/// 获取Enum值的具体枚举名称,排除None或All
57+
///
58+
/// PS:
59+
/// -【待确认】仅适用于使用了Flag标记的Enum
60+
/// </summary>
61+
/// <typeparam name="TEnumType"></typeparam>
62+
/// <param name="value"></param>
63+
/// <returns></returns>
64+
public static List<string> GetNamesEx(this Enum value, bool ignoreNone = true, bool ignoreEverything = true)
65+
{
66+
List<string> result = new List<string>();
67+
Type enumType = value.GetType();
68+
foreach (int i in Enum.GetValues(enumType))//先转为Value,排除None或All为自定义名称的干扰
69+
{
70+
if (ignoreNone && i == 0) continue;//排除None
71+
72+
if (ignoreEverything && i == ~0) continue;//排除All
73+
74+
Enum curEnum = Enum.Parse(enumType, i.ToString()) as Enum;
75+
if (value.Has(curEnum))
76+
{
77+
result.Add(curEnum.ToString());
78+
}
79+
}
80+
return result;
81+
}
82+
}
83+
}

Threeyes/Plugins/ThreeyesPlugin/Core/Extension/LazyExtension_Enum.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.

Threeyes/Plugins/ThreeyesPlugin/Core/Module/ValueHolder.meta renamed to Threeyes/Plugins/ThreeyesPlugin/Core/Module/MemberHolder.meta

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Threeyes/Plugins/ThreeyesPlugin/Core/Module/ValueHolder/Reflection/Base.meta renamed to Threeyes/Plugins/ThreeyesPlugin/Core/Module/MemberHolder/Base.meta

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
using UnityEngine;
2+
using System;
3+
using System.Reflection;
4+
using UnityEngine.Events;
5+
6+
namespace Threeyes.Core
7+
{
8+
public abstract class ReflectionMemberHolderBase : MonoBehaviour
9+
{
10+
public static string emptyMemberName = "___";//占位,代表不选,用于EditorGUI
11+
public const BindingFlags defaultBindingFlags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance;
12+
13+
public Type TargetType { get { return Target ? Target.GetType() : null; } }
14+
public UnityEngine.Object Target { get { return target; } set { target = value; } }
15+
16+
/// <summary>
17+
/// Target Script instance in Scene or Asset window
18+
/// </summary>
19+
[SerializeField] protected UnityEngine.Object target;
20+
21+
#region Utility
22+
23+
protected bool SetMember<TMemberInfo>(TMemberInfo memberInfo, UnityAction<TMemberInfo, object, object>
24+
actSetValue, object value, Func<TMemberInfo, bool> actCheckIfCanSet = null)
25+
where TMemberInfo : MemberInfo
26+
{
27+
if (memberInfo != null)
28+
{
29+
bool canSet = actCheckIfCanSet != null ? actCheckIfCanSet(memberInfo) : true;//默认代表可写
30+
if (canSet)
31+
{
32+
if (IsSetValueValid(memberInfo, value))
33+
{
34+
try
35+
{
36+
actSetValue(memberInfo, Target, value);
37+
return true;
38+
}
39+
catch (Exception e)
40+
{
41+
Debug.LogError("SetMember with error: \r\n" + e);
42+
}
43+
}
44+
}
45+
}
46+
return false;
47+
}
48+
49+
/// <summary>
50+
/// 在SetValue时判断是否有效
51+
/// (eg:如果需要排除值为null的情况,可以覆写该方法)
52+
/// </summary>
53+
/// <param name="memberInfo"></param>
54+
/// <param name="value"></param>
55+
/// <returns></returns>
56+
protected virtual bool IsSetValueValid(MemberInfo memberInfo, object value) { return true; }
57+
58+
/// <summary>
59+
///
60+
/// Todo:
61+
/// -将GetMemberInfo弄成链式调用,而不是包含
62+
/// </summary>
63+
/// <typeparam name="TMemberInfo"></typeparam>
64+
/// <param name="actGetMemberInfo"></param>
65+
/// <param name="memberName"></param>
66+
/// <param name="bindingFlags"></param>
67+
/// <returns></returns>
68+
protected TMemberInfo GetMemberInfo<TMemberInfo>(Func<Type, string, BindingFlags, TMemberInfo> actGetMemberInfo, string memberName, BindingFlags bindingFlags = defaultBindingFlags)
69+
where TMemberInfo : MemberInfo
70+
{
71+
if (TargetType == null)
72+
return null;
73+
74+
if (memberName == emptyMemberName || string.IsNullOrEmpty(memberName))//该字段没选择任意Member,不当报错
75+
return null;
76+
77+
TMemberInfo memberInfo = actGetMemberInfo(TargetType, memberName, bindingFlags);
78+
if (memberInfo == null)
79+
{
80+
Debug.LogError("Can't find " + typeof(TMemberInfo) + " with name " + memberName + "in" + TargetType + "!");
81+
}
82+
return memberInfo;
83+
}
84+
#endregion
85+
}
86+
}

Threeyes/Plugins/ThreeyesPlugin/Core/Module/MemberHolder/Base/ReflectionMemberHolderBase.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.

Threeyes/Plugins/ThreeyesPlugin/Core/Module/MemberHolder/Editor.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.

0 commit comments

Comments
 (0)