Skip to content

Commit 9d45bb8

Browse files
committed
1.Fixed custom extension.
2.Fixed require components check.
1 parent dd20724 commit 9d45bb8

29 files changed

+129
-106
lines changed

Core/Script/Editor/TweenEditorUtil.cs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,22 @@ static TweenEditorUtil()
4040

4141
internal static void CacheTweenTypes()
4242
{
43-
var types = Assembly.GetExecutingAssembly().GetTypes();
43+
var assemblies = AppDomain.CurrentDomain.GetAssemblies();
4444
var tweenTypes = new List<Type>();
45-
for (var i = 0; i < types.Length; i++)
45+
foreach (var assembly in assemblies)
4646
{
47-
var type = types[i];
48-
if (!type.IsClass || type.IsAbstract) continue;
49-
if (typeof(TweenerEditor).IsAssignableFrom(type))
47+
var types = assembly.GetTypes();
48+
for (var i = 0; i < types.Length; i++)
5049
{
51-
tweenTypes.Add(type);
50+
var type = types[i];
51+
if (!type.IsClass || type.IsAbstract) continue;
52+
if (typeof(TweenerEditor).IsAssignableFrom(type))
53+
{
54+
tweenTypes.Add(type);
55+
}
5256
}
5357
}
54-
58+
5559
TweenerEditorTypeList = tweenTypes;
5660
}
5761

Core/Script/TweenAnimation.cs

Lines changed: 61 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -440,28 +440,79 @@ public Tweener CreateTweenerEditorTime()
440440

441441
public bool CheckRequireComponent()
442442
{
443-
var requireComponentsAttribute = TweenerType.GetCustomAttribute<RequireComponentsAttribute>();
444-
if (requireComponentsAttribute == null)
443+
var requireOneOfComponentsAttribute = TweenerType.GetCustomAttribute<RequireOneOfComponentsAttribute>();
444+
var requireComponentAttribute = TweenerType.GetCustomAttribute<RequireComponent>();
445+
if (requireOneOfComponentsAttribute == null && requireComponentAttribute == null)
445446
{
446447
HasRequireComponent = true;
447448
}
448449
else
449450
{
450-
var result = RequireComponentsAttribute.Check(TweenerType, gameObject);
451-
HasRequireComponent = result;
451+
if (requireOneOfComponentsAttribute != null)
452+
{
453+
var result = RequireOneOfComponentsAttribute.Check(TweenerType, gameObject);
454+
HasRequireComponent = result;
455+
}
456+
457+
if (requireComponentAttribute != null)
458+
{
459+
var component0 = gameObject.GetComponent(requireComponentAttribute.m_Type0);
460+
if (requireComponentAttribute.m_Type1 == null)
461+
{
462+
HasRequireComponent = component0 != null;
463+
}
464+
else
465+
{
466+
var component1 = gameObject.GetComponent(requireComponentAttribute.m_Type1);
467+
if (requireComponentAttribute.m_Type2 == null)
468+
{
469+
HasRequireComponent = component0 != null && component1 != null;
470+
}
471+
else
472+
{
473+
var component2 = gameObject.GetComponent(requireComponentAttribute.m_Type2);
474+
HasRequireComponent = component0 != null && component1 != null && component2 != null;
475+
}
476+
}
477+
}
452478
}
453479

454480
return HasRequireComponent;
455481
}
456482

457483
public void FixRequireComponent()
458484
{
459-
var requireComponentsAttribute = TweenerType.GetCustomAttribute<RequireComponentsAttribute>();
460-
if (requireComponentsAttribute == null) return;
461-
var componentType = requireComponentsAttribute.Types[0];
462-
var component = gameObject.GetComponent(componentType);
463-
if (component != null) return;
464-
gameObject.AddComponent(componentType);
485+
var requireOneOfComponentsAttribute = TweenerType.GetCustomAttribute<RequireOneOfComponentsAttribute>();
486+
var requireComponentAttribute = TweenerType.GetCustomAttribute<RequireComponent>();
487+
if (requireOneOfComponentsAttribute == null && requireComponentAttribute == null) return;
488+
if (requireOneOfComponentsAttribute != null)
489+
{
490+
var componentType = requireOneOfComponentsAttribute.Types[0];
491+
var component = gameObject.GetComponent(componentType);
492+
if (component != null) return;
493+
gameObject.AddComponent(componentType);
494+
}
495+
496+
if (requireComponentAttribute != null)
497+
{
498+
if (requireComponentAttribute.m_Type0 != null)
499+
{
500+
var component = gameObject.GetComponent(requireComponentAttribute.m_Type0);
501+
if(component == null) gameObject.AddComponent(requireComponentAttribute.m_Type0);
502+
}
503+
504+
if (requireComponentAttribute.m_Type1 != null)
505+
{
506+
var component = gameObject.GetComponent(requireComponentAttribute.m_Type1);
507+
if (component == null) gameObject.AddComponent(requireComponentAttribute.m_Type1);
508+
}
509+
510+
if (requireComponentAttribute.m_Type2 != null)
511+
{
512+
var component = gameObject.GetComponent(requireComponentAttribute.m_Type2);
513+
if (component == null) gameObject.AddComponent(requireComponentAttribute.m_Type2);
514+
}
515+
}
465516
}
466517

467518
#endregion

Core/Script/TweenManager.cs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,19 @@ public static Dictionary<int, Type> TweenerTypeDic
9393

9494
internal static void CacheTweenTypeDic()
9595
{
96-
var types = Assembly.GetExecutingAssembly().GetTypes();
9796
var tweenTypes = new List<Type>();
98-
for (var i = 0; i < types.Length; i++)
97+
var assemblies = AppDomain.CurrentDomain.GetAssemblies();
98+
foreach (var assembly in assemblies)
9999
{
100-
var type = types[i];
101-
if (!type.IsClass || type.IsAbstract) continue;
102-
if (typeof(Tweener).IsAssignableFrom(type))
100+
var types = assembly.GetTypes();
101+
for (var i = 0; i < types.Length; i++)
103102
{
104-
tweenTypes.Add(type);
103+
var type = types[i];
104+
if (!type.IsClass || type.IsAbstract) continue;
105+
if (typeof(Tweener).IsAssignableFrom(type))
106+
{
107+
tweenTypes.Add(type);
108+
}
105109
}
106110
}
107111

Core/Script/_Base/Attribute/RequireComponentsAttribute.cs renamed to Core/Script/_Base/Attribute/RequireOneOfComponentsAttribute.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/////////////////////////////////////////////////////////////////////////////
22
//
3-
// Script : RequireComponentsAttribute.cs
3+
// Script : RequireOneOfComponentsAttribute.cs
44
// Info : 特性 - 包含至少一个组件
55
// Author : ls9512 2019
66
// E-mail : ls9512@vip.qq.com
@@ -13,11 +13,14 @@
1313
namespace Aya.Tween
1414
{
1515
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
16-
internal sealed class RequireComponentsAttribute : Attribute
16+
internal sealed class RequireOneOfComponentsAttribute : Attribute
1717
{
1818
public Type[] Types;
1919

20-
public RequireComponentsAttribute(params Type[] requiredComponents) { Types = requiredComponents; }
20+
public RequireOneOfComponentsAttribute(params Type[] requiredComponents)
21+
{
22+
Types = requiredComponents;
23+
}
2124

2225
/// <summary>
2326
/// 检查是否包含组件
@@ -39,7 +42,7 @@ public static bool Check(Type type, GameObject target)
3942
/// <returns>结果</returns>
4043
public static Component Find(Type type, GameObject target)
4144
{
42-
var classAttribute = type.GetCustomAttribute<RequireComponentsAttribute>();
45+
var classAttribute = type.GetCustomAttribute<RequireOneOfComponentsAttribute>();
4346
var types = classAttribute.Types;
4447
Component ret = null;
4548
for (var i = 0; i < types.Length; i++)

Core/Script/_Base/Ease/EaseType.cs

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -94,34 +94,13 @@ static EaseType()
9494
{
9595
var assembly = typeof(EaseType).Assembly;
9696
var space = typeof(EaseType).Namespace;
97-
var fieldInfos = typeof(EaseType).GetFields();
98-
var fieldsList = new List<FieldInfo>();
99-
var attributeList = new List<EnumPropertyAttribute>();
100-
foreach (var fieldInfo in fieldInfos)
97+
var enumName = nameof(EaseType);
98+
var infos = SerializeEnumAttribute.TypeInfosDic[enumName];
99+
foreach (var info in infos)
101100
{
102-
var attributes = fieldInfo.GetCustomAttributes(true);
103-
foreach (var attribute in attributes)
104-
{
105-
if (attribute.GetType() == typeof(EnumPropertyAttribute))
106-
{
107-
var enumPropertyAttribute = attribute as EnumPropertyAttribute;
108-
if (enumPropertyAttribute == null || !enumPropertyAttribute.Display) continue;
109-
fieldsList.Add(fieldInfo);
110-
attributeList.Add(enumPropertyAttribute);
111-
}
112-
}
113-
}
114-
115-
for (var i = 0; i < fieldsList.Count; i++)
116-
{
117-
var fieldInfo = fieldsList[i];
118-
var attribute = attributeList[i];
119-
var indexValue = (int)fieldInfo.GetValue(null);
120-
var displayName = string.IsNullOrEmpty(attribute.DisplayName) ? fieldInfo.Name : attribute.DisplayName;
121-
122-
ValueNameDic.Add(indexValue, fieldInfo.Name);
123-
ValueShowNameDic.Add(indexValue, displayName);
124-
NameValueDic.Add(displayName, indexValue);
101+
ValueNameDic.Add(info.Index, info.Name);
102+
ValueShowNameDic.Add(info.Index, info.DisplayName);
103+
NameValueDic.Add(info.DisplayName, info.Index);
125104
}
126105

127106
foreach (var kv in ValueNameDic)

Core/Script/_Base/TweenType.cs

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -90,33 +90,12 @@ public static class TweenType
9090

9191
static TweenType()
9292
{
93-
var fieldInfos = typeof(TweenType).GetFields();
94-
var fieldsList = new List<FieldInfo>();
95-
var attributeList = new List<EnumPropertyAttribute>();
96-
foreach (var fieldInfo in fieldInfos)
93+
var enumName = nameof(TweenType);
94+
var infos = SerializeEnumAttribute.TypeInfosDic[enumName];
95+
foreach (var info in infos)
9796
{
98-
var attributes = fieldInfo.GetCustomAttributes(true);
99-
foreach (var attribute in attributes)
100-
{
101-
if (attribute.GetType() == typeof(EnumPropertyAttribute))
102-
{
103-
var enumPropertyAttribute = attribute as EnumPropertyAttribute;
104-
if (enumPropertyAttribute == null || !enumPropertyAttribute.Display) continue;
105-
fieldsList.Add(fieldInfo);
106-
attributeList.Add(enumPropertyAttribute);
107-
}
108-
}
109-
}
110-
111-
for (var i = 0; i < fieldsList.Count; i++)
112-
{
113-
var fieldInfo = fieldsList[i];
114-
var attribute = attributeList[i];
115-
var indexValue = (int)fieldInfo.GetValue(null);
116-
var displayName = string.IsNullOrEmpty(attribute.DisplayName) ? fieldInfo.Name : attribute.DisplayName;
117-
118-
ValueTypeDic.Add(indexValue, displayName);
119-
TypeValueDic.Add(displayName, indexValue);
97+
ValueTypeDic.Add(info.Index, info.DisplayName);
98+
TypeValueDic.Add(info.DisplayName, info.Index);
12099
}
121100
}
122101
}

Core/Script/_TweenColor/TweenColor.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
namespace Aya.Tween
1414
{
15-
[RequireComponents(
15+
[RequireOneOfComponents(
1616
typeof(Image),
1717
typeof(RawImage),
1818
typeof(Text),
@@ -33,7 +33,7 @@ public class TweenColor : TweenColorBase<Component>
3333

3434
public override void Awake()
3535
{
36-
TargetComponent = RequireComponentsAttribute.Find(typeof(TweenColor), Target);
36+
TargetComponent = RequireOneOfComponentsAttribute.Find(typeof(TweenColor), Target);
3737
base.Awake();
3838
}
3939

Core/Script/_TweenColor/TweenColorBlock.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
namespace Aya.Tween
1515
{
16-
[RequireComponents(
16+
[RequireOneOfComponents(
1717
typeof(Button),
1818
typeof(Toggle),
1919
typeof(InputField),
@@ -31,7 +31,7 @@ public class TweenColorBlock : TweenColorBase<Component>
3131

3232
public override void Awake()
3333
{
34-
TargetComponent = RequireComponentsAttribute.Find(typeof(TweenColorBlock), Target);
34+
TargetComponent = RequireOneOfComponentsAttribute.Find(typeof(TweenColorBlock), Target);
3535
base.Awake();
3636
}
3737

Core/Script/_TweenComponent/TweenTransform.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
namespace Aya.Tween
1313
{
14-
[RequireComponents(typeof(Transform))]
14+
[RequireComponent(typeof(Transform))]
1515
[Tweener(TweenType.Transform)]
1616
public class TweenTransform : Tweener<Transform, Transform>
1717
{

Core/Script/_TweenFloat/TweenAlpha.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
namespace Aya.Tween
1414
{
15-
[RequireComponents(
15+
[RequireOneOfComponents(
1616
typeof(Image),
1717
typeof(RawImage),
1818
typeof(Text),
@@ -33,7 +33,7 @@ public class TweenAlpha : TweenFloatBase<Component>
3333

3434
public override void Awake()
3535
{
36-
TargetComponent = RequireComponentsAttribute.Find(typeof(TweenColor), Target);
36+
TargetComponent = RequireOneOfComponentsAttribute.Find(typeof(TweenColor), Target);
3737
base.Awake();
3838
}
3939

Core/Script/_TweenFloat/TweenCanvasGroupAlpha.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
namespace Aya.Tween
1212
{
13-
[RequireComponents(typeof(CanvasGroup))]
13+
[RequireComponent(typeof(CanvasGroup))]
1414
[Tweener(TweenType.CanvasGroupAlpha)]
1515
public class TweenCanvasGroupAlpha : TweenFloatBase<CanvasGroup>
1616
{

Core/Script/_TweenFloat/TweenHeight.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
namespace Aya.Tween
1212
{
13-
[RequireComponents(typeof(RectTransform))]
13+
[RequireComponent(typeof(RectTransform))]
1414
[Tweener(TweenType.Height)]
1515
public class TweenHeight : TweenFloatBase<RectTransform>
1616
{

Core/Script/_TweenFloat/TweenScrollbar.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@
77
// E-mail : ls9512@vip.qq.com
88
//
99
/////////////////////////////////////////////////////////////////////////////
10+
using UnityEngine;
1011
using UnityEngine.UI;
1112

1213
namespace Aya.Tween
1314
{
14-
[RequireComponents(typeof(Scrollbar))]
15+
[RequireComponent(typeof(Scrollbar))]
1516
[Tweener(TweenType.Scrollbar)]
1617
public class TweenScrollbar : TweenFloatBase<Scrollbar>
1718
{

Core/Script/_TweenFloat/TweenShake/TweenShake.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
namespace Aya.Tween
1313
{
14-
[RequireComponents(typeof(Transform))]
14+
[RequireComponent(typeof(Transform))]
1515
[Tweener(TweenType.Shake)]
1616
public class TweenShake : TweenFloatBase<Transform>
1717
{

Core/Script/_TweenFloat/TweenSlider.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@
77
// E-mail : ls9512@vip.qq.com
88
//
99
/////////////////////////////////////////////////////////////////////////////
10+
using UnityEngine;
1011
using UnityEngine.UI;
1112

1213
namespace Aya.Tween
1314
{
14-
[RequireComponents(typeof(Slider))]
15+
[RequireComponent(typeof(Slider))]
1516
[Tweener(TweenType.Slider)]
1617
public class TweenSlider : TweenFloatBase<Slider>
1718
{

Core/Script/_TweenFloat/TweenVolume.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
namespace Aya.Tween
1212
{
13-
[RequireComponents(typeof(AudioSource))]
13+
[RequireComponent(typeof(AudioSource))]
1414
[Tweener(TweenType.Volume)]
1515
public class TweenVolume : TweenFloatBase<AudioSource>
1616
{

Core/Script/_TweenFloat/TweenWidth.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
namespace Aya.Tween
1212
{
13-
[RequireComponents(typeof(RectTransform))]
13+
[RequireComponent(typeof(RectTransform))]
1414
[Tweener(TweenType.Width)]
1515
public class TweenWidth : TweenFloatBase<RectTransform>
1616
{

0 commit comments

Comments
 (0)