/// <summary> /// Creates a new game object with component of type <typeparamref name="T"/>. /// </summary> /// <example> /// GameObject rb = Factory.Create<RigidBody>(); /// </example> /// <typeparam name="T">Type of component.</typeparam> /// <returns>New game object with component <typeparamref name="T"/>.</returns> public static GameObject Create <T>() where T : ScriptComponent { GameObject go = new GameObject(CreateName <T>()); go.AddComponent <T>(); PrefabUtils.PlaceInCurrentStange(go); return(go); }
/// <summary> /// Creates constraint of given type. /// </summary> /// <param name="constraintType">Constraint type.</param> /// <param name="givenAttachmentPair">Optional initial attachment pair. If null, a new one will be created.</param> /// <returns>Constraint game object if the configuration is valid.</returns> public static GameObject Create(ConstraintType constraintType, AttachmentPair givenAttachmentPair = null) { var constraint = Constraint.Create(constraintType, givenAttachmentPair); if (constraint == null) { return(null); } PrefabUtils.PlaceInCurrentStange(constraint.gameObject); return(constraint.gameObject); }
/// <summary> /// Create a cable given route, radius, resolution and material. /// </summary> /// <param name="radius">Radius of the cable.</param> /// <param name="resolutionPerUnitLength">Resolution of the cable.</param> /// <param name="material">Shape material of the cable.</param> /// <returns>Cable component.</returns> public static Cable CreateCable(float radius = 0.05f, float resolutionPerUnitLength = 5.0f, ShapeMaterial material = null) { GameObject go = new GameObject(CreateName <Cable>()); Cable cable = go.AddComponent <Cable>(); cable.Radius = radius; cable.ResolutionPerUnitLength = resolutionPerUnitLength; cable.Material = material; PrefabUtils.PlaceInCurrentStange(go); return(cable); }
/// <summary> /// Create a wire given route, radius, resolution and material. /// </summary> /// <param name="radius">Radius if the wire.</param> /// <param name="resolutionPerUnitLength">Resolution of the wire.</param> /// <param name="material">Shape material of the wire.</param> /// <returns>A new game object with a Wire component.</returns> public static Wire CreateWire(float radius = 0.02f, float resolutionPerUnitLength = 1.5f, ShapeMaterial material = null) { GameObject go = new GameObject(CreateName <Wire>()); Wire wire = go.AddComponent <Wire>(); wire.Radius = radius; wire.ResolutionPerUnitLength = resolutionPerUnitLength; wire.Material = material; PrefabUtils.PlaceInCurrentStange(go); return(wire); }