using UnityEngine; namespace SuperTiled2Unity { public static class GameObjectExtensions { // Like GetComponentInParent but doesn't check current object public static T GetComponentInAncestor(this MonoBehaviour mono) where T : MonoBehaviour { return GetComponentInAncestor(mono.gameObject); } // Like GetComponentInParent but doesn't check current object public static T GetComponentInAncestor(this GameObject go) where T : MonoBehaviour { if (go == null) { return null; } var parent = go.transform.parent; if (parent == null) { return null; } return parent.GetComponentInParent(); } public static bool TryGetCustomPropertySafe(this GameObject go, string name, out CustomProperty property) { property = null; if (go == null) { return false; } var customProperties = go.GetComponent(); if (customProperties == null) { return false; } return customProperties.TryGetCustomProperty(name, out property); } } }