namespace UnityEngine.UI.Extensions { public static class ExtentionMethods { public static T GetOrAddComponent(this GameObject child) where T : Component { T result = child.GetComponent(); if (result == null) { result = child.AddComponent(); } return result; } } }