Skip to content

Commit

Permalink
1.Fixed custom extension.
Browse files Browse the repository at this point in the history
2.Fixed require components check.
  • Loading branch information
ls9512 committed Feb 23, 2021
1 parent dd20724 commit 9d45bb8
Show file tree
Hide file tree
Showing 29 changed files with 129 additions and 106 deletions.
18 changes: 11 additions & 7 deletions Core/Script/Editor/TweenEditorUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,22 @@ static TweenEditorUtil()

internal static void CacheTweenTypes()
{
var types = Assembly.GetExecutingAssembly().GetTypes();
var assemblies = AppDomain.CurrentDomain.GetAssemblies();
var tweenTypes = new List<Type>();
for (var i = 0; i < types.Length; i++)
foreach (var assembly in assemblies)
{
var type = types[i];
if (!type.IsClass || type.IsAbstract) continue;
if (typeof(TweenerEditor).IsAssignableFrom(type))
var types = assembly.GetTypes();
for (var i = 0; i < types.Length; i++)
{
tweenTypes.Add(type);
var type = types[i];
if (!type.IsClass || type.IsAbstract) continue;
if (typeof(TweenerEditor).IsAssignableFrom(type))
{
tweenTypes.Add(type);
}
}
}

TweenerEditorTypeList = tweenTypes;
}

Expand Down
71 changes: 61 additions & 10 deletions Core/Script/TweenAnimation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -440,28 +440,79 @@ public Tweener CreateTweenerEditorTime()

public bool CheckRequireComponent()
{
var requireComponentsAttribute = TweenerType.GetCustomAttribute<RequireComponentsAttribute>();
if (requireComponentsAttribute == null)
var requireOneOfComponentsAttribute = TweenerType.GetCustomAttribute<RequireOneOfComponentsAttribute>();
var requireComponentAttribute = TweenerType.GetCustomAttribute<RequireComponent>();
if (requireOneOfComponentsAttribute == null && requireComponentAttribute == null)
{
HasRequireComponent = true;
}
else
{
var result = RequireComponentsAttribute.Check(TweenerType, gameObject);
HasRequireComponent = result;
if (requireOneOfComponentsAttribute != null)
{
var result = RequireOneOfComponentsAttribute.Check(TweenerType, gameObject);
HasRequireComponent = result;
}

if (requireComponentAttribute != null)
{
var component0 = gameObject.GetComponent(requireComponentAttribute.m_Type0);
if (requireComponentAttribute.m_Type1 == null)
{
HasRequireComponent = component0 != null;
}
else
{
var component1 = gameObject.GetComponent(requireComponentAttribute.m_Type1);
if (requireComponentAttribute.m_Type2 == null)
{
HasRequireComponent = component0 != null && component1 != null;
}
else
{
var component2 = gameObject.GetComponent(requireComponentAttribute.m_Type2);
HasRequireComponent = component0 != null && component1 != null && component2 != null;
}
}
}
}

return HasRequireComponent;
}

public void FixRequireComponent()
{
var requireComponentsAttribute = TweenerType.GetCustomAttribute<RequireComponentsAttribute>();
if (requireComponentsAttribute == null) return;
var componentType = requireComponentsAttribute.Types[0];
var component = gameObject.GetComponent(componentType);
if (component != null) return;
gameObject.AddComponent(componentType);
var requireOneOfComponentsAttribute = TweenerType.GetCustomAttribute<RequireOneOfComponentsAttribute>();
var requireComponentAttribute = TweenerType.GetCustomAttribute<RequireComponent>();
if (requireOneOfComponentsAttribute == null && requireComponentAttribute == null) return;
if (requireOneOfComponentsAttribute != null)
{
var componentType = requireOneOfComponentsAttribute.Types[0];
var component = gameObject.GetComponent(componentType);
if (component != null) return;
gameObject.AddComponent(componentType);
}

if (requireComponentAttribute != null)
{
if (requireComponentAttribute.m_Type0 != null)
{
var component = gameObject.GetComponent(requireComponentAttribute.m_Type0);
if(component == null) gameObject.AddComponent(requireComponentAttribute.m_Type0);
}

if (requireComponentAttribute.m_Type1 != null)
{
var component = gameObject.GetComponent(requireComponentAttribute.m_Type1);
if (component == null) gameObject.AddComponent(requireComponentAttribute.m_Type1);
}

if (requireComponentAttribute.m_Type2 != null)
{
var component = gameObject.GetComponent(requireComponentAttribute.m_Type2);
if (component == null) gameObject.AddComponent(requireComponentAttribute.m_Type2);
}
}
}

#endregion
Expand Down
16 changes: 10 additions & 6 deletions Core/Script/TweenManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,19 @@ public static Dictionary<int, Type> TweenerTypeDic

internal static void CacheTweenTypeDic()
{
var types = Assembly.GetExecutingAssembly().GetTypes();
var tweenTypes = new List<Type>();
for (var i = 0; i < types.Length; i++)
var assemblies = AppDomain.CurrentDomain.GetAssemblies();
foreach (var assembly in assemblies)
{
var type = types[i];
if (!type.IsClass || type.IsAbstract) continue;
if (typeof(Tweener).IsAssignableFrom(type))
var types = assembly.GetTypes();
for (var i = 0; i < types.Length; i++)
{
tweenTypes.Add(type);
var type = types[i];
if (!type.IsClass || type.IsAbstract) continue;
if (typeof(Tweener).IsAssignableFrom(type))
{
tweenTypes.Add(type);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/////////////////////////////////////////////////////////////////////////////
//
// Script : RequireComponentsAttribute.cs
// Script : RequireOneOfComponentsAttribute.cs
// Info : 特性 - 包含至少一个组件
// Author : ls9512 2019
// E-mail : [email protected]
Expand All @@ -13,11 +13,14 @@
namespace Aya.Tween
{
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
internal sealed class RequireComponentsAttribute : Attribute
internal sealed class RequireOneOfComponentsAttribute : Attribute
{
public Type[] Types;

public RequireComponentsAttribute(params Type[] requiredComponents) { Types = requiredComponents; }
public RequireOneOfComponentsAttribute(params Type[] requiredComponents)
{
Types = requiredComponents;
}

/// <summary>
/// 检查是否包含组件
Expand All @@ -39,7 +42,7 @@ public static bool Check(Type type, GameObject target)
/// <returns>结果</returns>
public static Component Find(Type type, GameObject target)
{
var classAttribute = type.GetCustomAttribute<RequireComponentsAttribute>();
var classAttribute = type.GetCustomAttribute<RequireOneOfComponentsAttribute>();
var types = classAttribute.Types;
Component ret = null;
for (var i = 0; i < types.Length; i++)
Expand Down
33 changes: 6 additions & 27 deletions Core/Script/_Base/Ease/EaseType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,34 +94,13 @@ static EaseType()
{
var assembly = typeof(EaseType).Assembly;
var space = typeof(EaseType).Namespace;
var fieldInfos = typeof(EaseType).GetFields();
var fieldsList = new List<FieldInfo>();
var attributeList = new List<EnumPropertyAttribute>();
foreach (var fieldInfo in fieldInfos)
var enumName = nameof(EaseType);
var infos = SerializeEnumAttribute.TypeInfosDic[enumName];
foreach (var info in infos)
{
var attributes = fieldInfo.GetCustomAttributes(true);
foreach (var attribute in attributes)
{
if (attribute.GetType() == typeof(EnumPropertyAttribute))
{
var enumPropertyAttribute = attribute as EnumPropertyAttribute;
if (enumPropertyAttribute == null || !enumPropertyAttribute.Display) continue;
fieldsList.Add(fieldInfo);
attributeList.Add(enumPropertyAttribute);
}
}
}

for (var i = 0; i < fieldsList.Count; i++)
{
var fieldInfo = fieldsList[i];
var attribute = attributeList[i];
var indexValue = (int)fieldInfo.GetValue(null);
var displayName = string.IsNullOrEmpty(attribute.DisplayName) ? fieldInfo.Name : attribute.DisplayName;

ValueNameDic.Add(indexValue, fieldInfo.Name);
ValueShowNameDic.Add(indexValue, displayName);
NameValueDic.Add(displayName, indexValue);
ValueNameDic.Add(info.Index, info.Name);
ValueShowNameDic.Add(info.Index, info.DisplayName);
NameValueDic.Add(info.DisplayName, info.Index);
}

foreach (var kv in ValueNameDic)
Expand Down
31 changes: 5 additions & 26 deletions Core/Script/_Base/TweenType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,33 +90,12 @@ public static class TweenType

static TweenType()
{
var fieldInfos = typeof(TweenType).GetFields();
var fieldsList = new List<FieldInfo>();
var attributeList = new List<EnumPropertyAttribute>();
foreach (var fieldInfo in fieldInfos)
var enumName = nameof(TweenType);
var infos = SerializeEnumAttribute.TypeInfosDic[enumName];
foreach (var info in infos)
{
var attributes = fieldInfo.GetCustomAttributes(true);
foreach (var attribute in attributes)
{
if (attribute.GetType() == typeof(EnumPropertyAttribute))
{
var enumPropertyAttribute = attribute as EnumPropertyAttribute;
if (enumPropertyAttribute == null || !enumPropertyAttribute.Display) continue;
fieldsList.Add(fieldInfo);
attributeList.Add(enumPropertyAttribute);
}
}
}

for (var i = 0; i < fieldsList.Count; i++)
{
var fieldInfo = fieldsList[i];
var attribute = attributeList[i];
var indexValue = (int)fieldInfo.GetValue(null);
var displayName = string.IsNullOrEmpty(attribute.DisplayName) ? fieldInfo.Name : attribute.DisplayName;

ValueTypeDic.Add(indexValue, displayName);
TypeValueDic.Add(displayName, indexValue);
ValueTypeDic.Add(info.Index, info.DisplayName);
TypeValueDic.Add(info.DisplayName, info.Index);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions Core/Script/_TweenColor/TweenColor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace Aya.Tween
{
[RequireComponents(
[RequireOneOfComponents(
typeof(Image),
typeof(RawImage),
typeof(Text),
Expand All @@ -33,7 +33,7 @@ public class TweenColor : TweenColorBase<Component>

public override void Awake()
{
TargetComponent = RequireComponentsAttribute.Find(typeof(TweenColor), Target);
TargetComponent = RequireOneOfComponentsAttribute.Find(typeof(TweenColor), Target);
base.Awake();
}

Expand Down
4 changes: 2 additions & 2 deletions Core/Script/_TweenColor/TweenColorBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace Aya.Tween
{
[RequireComponents(
[RequireOneOfComponents(
typeof(Button),
typeof(Toggle),
typeof(InputField),
Expand All @@ -31,7 +31,7 @@ public class TweenColorBlock : TweenColorBase<Component>

public override void Awake()
{
TargetComponent = RequireComponentsAttribute.Find(typeof(TweenColorBlock), Target);
TargetComponent = RequireOneOfComponentsAttribute.Find(typeof(TweenColorBlock), Target);
base.Awake();
}

Expand Down
2 changes: 1 addition & 1 deletion Core/Script/_TweenComponent/TweenTransform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Aya.Tween
{
[RequireComponents(typeof(Transform))]
[RequireComponent(typeof(Transform))]
[Tweener(TweenType.Transform)]
public class TweenTransform : Tweener<Transform, Transform>
{
Expand Down
4 changes: 2 additions & 2 deletions Core/Script/_TweenFloat/TweenAlpha.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace Aya.Tween
{
[RequireComponents(
[RequireOneOfComponents(
typeof(Image),
typeof(RawImage),
typeof(Text),
Expand All @@ -33,7 +33,7 @@ public class TweenAlpha : TweenFloatBase<Component>

public override void Awake()
{
TargetComponent = RequireComponentsAttribute.Find(typeof(TweenColor), Target);
TargetComponent = RequireOneOfComponentsAttribute.Find(typeof(TweenColor), Target);
base.Awake();
}

Expand Down
2 changes: 1 addition & 1 deletion Core/Script/_TweenFloat/TweenCanvasGroupAlpha.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace Aya.Tween
{
[RequireComponents(typeof(CanvasGroup))]
[RequireComponent(typeof(CanvasGroup))]
[Tweener(TweenType.CanvasGroupAlpha)]
public class TweenCanvasGroupAlpha : TweenFloatBase<CanvasGroup>
{
Expand Down
2 changes: 1 addition & 1 deletion Core/Script/_TweenFloat/TweenHeight.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace Aya.Tween
{
[RequireComponents(typeof(RectTransform))]
[RequireComponent(typeof(RectTransform))]
[Tweener(TweenType.Height)]
public class TweenHeight : TweenFloatBase<RectTransform>
{
Expand Down
3 changes: 2 additions & 1 deletion Core/Script/_TweenFloat/TweenScrollbar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
// E-mail : [email protected]
//
/////////////////////////////////////////////////////////////////////////////
using UnityEngine;
using UnityEngine.UI;

namespace Aya.Tween
{
[RequireComponents(typeof(Scrollbar))]
[RequireComponent(typeof(Scrollbar))]
[Tweener(TweenType.Scrollbar)]
public class TweenScrollbar : TweenFloatBase<Scrollbar>
{
Expand Down
2 changes: 1 addition & 1 deletion Core/Script/_TweenFloat/TweenShake/TweenShake.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Aya.Tween
{
[RequireComponents(typeof(Transform))]
[RequireComponent(typeof(Transform))]
[Tweener(TweenType.Shake)]
public class TweenShake : TweenFloatBase<Transform>
{
Expand Down
3 changes: 2 additions & 1 deletion Core/Script/_TweenFloat/TweenSlider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
// E-mail : [email protected]
//
/////////////////////////////////////////////////////////////////////////////
using UnityEngine;
using UnityEngine.UI;

namespace Aya.Tween
{
[RequireComponents(typeof(Slider))]
[RequireComponent(typeof(Slider))]
[Tweener(TweenType.Slider)]
public class TweenSlider : TweenFloatBase<Slider>
{
Expand Down
2 changes: 1 addition & 1 deletion Core/Script/_TweenFloat/TweenVolume.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace Aya.Tween
{
[RequireComponents(typeof(AudioSource))]
[RequireComponent(typeof(AudioSource))]
[Tweener(TweenType.Volume)]
public class TweenVolume : TweenFloatBase<AudioSource>
{
Expand Down
2 changes: 1 addition & 1 deletion Core/Script/_TweenFloat/TweenWidth.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace Aya.Tween
{
[RequireComponents(typeof(RectTransform))]
[RequireComponent(typeof(RectTransform))]
[Tweener(TweenType.Width)]
public class TweenWidth : TweenFloatBase<RectTransform>
{
Expand Down
Loading

0 comments on commit 9d45bb8

Please sign in to comment.