-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameObjectExtensions.cs
More file actions
48 lines (40 loc) · 1.3 KB
/
Copy pathGameObjectExtensions.cs
File metadata and controls
48 lines (40 loc) · 1.3 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
using UnityEngine;
namespace SuperTiled2Unity
{
public static class GameObjectExtensions
{
// Like GetComponentInParent but doesn't check current object
public static T GetComponentInAncestor<T>(this MonoBehaviour mono) where T : MonoBehaviour
{
return GetComponentInAncestor<T>(mono.gameObject);
}
// Like GetComponentInParent but doesn't check current object
public static T GetComponentInAncestor<T>(this GameObject go) where T : MonoBehaviour
{
if (go == null)
{
return null;
}
var parent = go.transform.parent;
if (parent == null)
{
return null;
}
return parent.GetComponentInParent<T>();
}
public static bool TryGetCustomPropertySafe(this GameObject go, string name, out CustomProperty property)
{
property = null;
if (go == null)
{
return false;
}
var customProperties = go.GetComponent<SuperCustomProperties>();
if (customProperties == null)
{
return false;
}
return customProperties.TryGetCustomProperty(name, out property);
}
}
}