/// <summary> /// Create an instance of a type with optional constructor parameters. /// </summary> public static object New(this HUMValue.Data.Create create, Type type, params object[] constructorParameters) { if (type.IsAbstract) { return(null); } if (type == typeof(int)) { return(0); } if (type == typeof(float)) { return(0f); } if (type == typeof(bool)) { return(false); } if (type == typeof(string)) { return(string.Empty); } if (type.Inherits(typeof(UnityEngine.Object))) { return(null); } return(Activator.CreateInstance(type, constructorParameters)); }
/// <summary> /// Creates an instance of a type with optional constructor parameters. /// </summary> public static T New <T>(this HUMValue.Data.Create create, params object[] constructorParameters) { var type = typeof(T); if (type.IsValueType) { return(default(T)); } return((T)Activator.CreateInstance(type, constructorParameters)); }