Example #1
0
 public static Component AddComponent(GameObject gameObject, Type type)
 {
     ObjectFactory.CheckTypeValidity(type);
     if (!type.IsSubclassOf(typeof(Component)))
     {
         throw new ArgumentException("Non-Component type must use ObjectFactory.CreateInstance instead : " + type.FullName);
     }
     return(ObjectFactory.AddDefaultComponent(gameObject, type));
 }
Example #2
0
 public static UnityEngine.Object CreateInstance(Type type)
 {
     ObjectFactory.CheckTypeValidity(type);
     if (type == typeof(GameObject))
     {
         throw new ArgumentException("GameObject type must be created using ObjectFactory.CreateGameObject instead : " + type.FullName);
     }
     if (type.IsSubclassOf(typeof(Component)))
     {
         throw new ArgumentException("Component type must be created using ObjectFactory.AddComponent instead : " + type.FullName);
     }
     if (type.GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic, null, Type.EmptyTypes, null) != null)
     {
         throw new ArgumentException(type.FullName + " constructor is not accessible which prevent this type from being used in ObjectFactory.");
     }
     return(ObjectFactory.CreateDefaultInstance(type));
 }