-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathFindChildAttribute.cs
More file actions
55 lines (50 loc) · 1.47 KB
/
FindChildAttribute.cs
File metadata and controls
55 lines (50 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using System;
using System.Reflection;
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
namespace Kogane
{
/// <summary>
/// Transform.Find を実行する Attribute
/// </summary>
[AttributeUsage(AttributeTargets.Field)]
public sealed class FindChildAttribute
: Attribute,
IGetComponentAttribute
{
//================================================================================
// 変数(readonly)
//================================================================================
private readonly string m_name;
//================================================================================
// 関数
//================================================================================
/// <summary>
/// コンストラクタ
/// </summary>
public FindChildAttribute(string name)
{
m_name = name;
}
#if UNITY_EDITOR
/// <summary>
/// 指定されたパラメータに参照を割り当てます
/// </summary>
public void Inject
(
MonoBehaviour monoBehaviour,
FieldInfo fieldInfo,
SerializedProperty serializedProperty
)
{
if (serializedProperty.isArray)
{
return;
}
serializedProperty.objectReferenceValue = monoBehaviour.transform.Find(m_name);
}
#endif
}
}