/// <summary> /// Add user component. /// </summary> /// <typeparam name="T">[NameToType]T.</typeparam> /// <param name="componentTypeName"></param> /// <returns></returns> public static T GetUserComponent <T>(this GameObject gameObject, string componentTypeName) where T : Component { if (string.IsNullOrEmpty(componentTypeName)) { return(null); } if (NameToTypeUtility.TryGetValue(componentTypeName, out var type)) { return(gameObject.GetComponent(type) as T); } DebugUtility.LogError(LoggerTags.Engine, "Can't get the component from {0}, please confirm that whether the class '{1}' has declared the attribute '[NameToType]'", gameObject.name, componentTypeName); return(null); }