49 lines
1.1 KiB
C#
49 lines
1.1 KiB
C#
|
using Sirenix.OdinInspector;
|
|||
|
|
|||
|
using System.Linq;
|
|||
|
|
|||
|
using UnityEngine;
|
|||
|
using UnityEngine.UI;
|
|||
|
|
|||
|
public abstract class SetterBase<TBehaviour, TValue> : BaseBehaviour where TBehaviour : Component
|
|||
|
{
|
|||
|
#if UNITY_EDITOR
|
|||
|
public bool isContain = true;
|
|||
|
public GameObject key;
|
|||
|
public TValue[] values;
|
|||
|
|
|||
|
public TBehaviour[] behaviours;
|
|||
|
|
|||
|
[Button]
|
|||
|
public virtual void GetBehaviours()
|
|||
|
{
|
|||
|
behaviours = this
|
|||
|
.GetComponentsInChildren<TBehaviour>(true)
|
|||
|
.Where(_ => {
|
|||
|
if (this.isContain == true)
|
|||
|
{
|
|||
|
return _.name.Contains(key.name);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
return _.name == key.name;
|
|||
|
}
|
|||
|
|
|||
|
}).ToArray();
|
|||
|
}
|
|||
|
|
|||
|
[Button]
|
|||
|
public virtual void SetValue()
|
|||
|
{
|
|||
|
for (int i = 0; i < behaviours.Length; i++)
|
|||
|
{
|
|||
|
this.Set(behaviours[i], values[i]);
|
|||
|
#if UNITY_EDITOR
|
|||
|
UnityEditor.EditorUtility.SetDirty(behaviours[i]);
|
|||
|
#endif
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
protected abstract void Set(TBehaviour behaviour, TValue value);
|
|||
|
#endif
|
|||
|
}
|