Exemplo n.º 1
0
 /// <summary>Creates an ideal sphere.</summary>
 /// <param name="diameter">Diameter of the sphere.</param>
 /// <param name="material">Material for the primitive.</param>
 /// <param name="parent">Parent transform to attach primitive to.</param>
 /// <param name="colliderType">Type of the collider to create on the primitive.</param>
 /// <returns>Sphere game object.</returns>
 /// <seealso href="https://docs.unity3d.com/ScriptReference/Material.html">Unity3D: Material
 /// </seealso>
 /// <seealso href="https://docs.unity3d.com/ScriptReference/Transform.html">Unity3D: Transform
 /// </seealso>
 public static GameObject CreateSphere(
     float diameter, Material material, Transform parent,
     Colliders.PrimitiveCollider colliderType = Colliders.PrimitiveCollider.None) {
   var scale =  new Vector3(diameter, diameter, diameter);
   var obj = CreatePrimitive(PrimitiveType.Sphere, scale, material, parent: parent);
   Colliders.AdjustCollider(obj, scale, colliderType, shapeType: PrimitiveType.Sphere);
   return obj;
 }
Exemplo n.º 2
0
        /// <summary>Creates a primitive mesh without colliders and attaches it to the model.</summary>
        /// <remarks>
        /// <p>
        /// For <see cref="PrimitiveType.Cylinder"/> Z and Y axis will be swapped to make Z "the length".
        /// </p>
        /// <p>
        /// Collider on the primitive will be destroyed. Consider using
        /// <see cref="Colliders.AdjustCollider"/> to setup the right collider when needed.
        /// </p>
        /// </remarks>
        /// <param name="type">The type of the primitive.</param>
        /// <param name="meshScale">
        /// The scale to bring all the mesh vertices to. The scale is applied on the mesh, i.e. it's
        /// applied on the vertices, not the transform.
        /// </param>
        /// <param name="material">The material to use for the primitive.</param>
        /// <param name="parent">The parent transform to attach the primitive to.</param>
        /// <returns>The game object of the new primitive.</returns>
        /// <seealso href="https://docs.unity3d.com/ScriptReference/GameObject.CreatePrimitive.html">
        /// Unity3D: GameObject.CreatePrimitive</seealso>
        /// <seealso href="https://docs.unity3d.com/ScriptReference/Material.html">Unity3D: Material
        /// </seealso>
        public static GameObject CreatePrimitive(
            PrimitiveType type, Vector3 meshScale, Material material, Transform parent)
        {
            var primitive = CreatePrimitiveWithCollider(type, meshScale, material, parent);

            Colliders.SafeDestroy(primitive.GetComponent <Collider>());
            return(primitive);
        }
Exemplo n.º 3
0
        /// <summary>Creates a box.</summary>
        /// <param name="width">X-axis of the box.</param>
        /// <param name="height">Y-axis of the box.</param>
        /// <param name="length">Z-axis of the box.</param>
        /// <param name="material">Material for the primitive.</param>
        /// <param name="parent">Parent transfrom to atatch primitive to.</param>
        /// <param name="colliderType">Type of the collider to create on the primitive.</param>
        /// <returns>Sphere game object.</returns>
        /// <seealso href="https://docs.unity3d.com/ScriptReference/Material.html">Unity3D: Material
        /// </seealso>
        /// <seealso href="https://docs.unity3d.com/ScriptReference/Transform.html">Unity3D: Transform
        /// </seealso>
        public static GameObject CreateBox(
            float width, float height, float length, Material material, Transform parent,
            Colliders.PrimitiveCollider colliderType = Colliders.PrimitiveCollider.None)
        {
            var scale = new Vector3(width, height, length);
            var obj   = CreatePrimitive(PrimitiveType.Cube, scale, material, parent: parent);

            Colliders.AdjustCollider(obj, scale, colliderType, shapeType: PrimitiveType.Cube);
            return(obj);
        }
Exemplo n.º 4
0
 /// <summary>Creates a cylinder.</summary>
 /// <param name="diameter">XY of the cylinder.</param>
 /// <param name="length">Z-axis of the cylinder.</param>
 /// <param name="material">Material for the primitive.</param>
 /// <param name="parent">Parent transform to attach primitive to.</param>
 /// <param name="colliderType">Type of the collider to create on the primitive.</param>
 /// <returns>Sphere game object.</returns>
 /// <seealso href="https://docs.unity3d.com/ScriptReference/Material.html">Unity3D: Material
 /// </seealso>
 /// <seealso href="https://docs.unity3d.com/ScriptReference/Transform.html">Unity3D: Transform
 /// </seealso>
 public static GameObject CreateCylinder(
     float diameter, float length, Material material, Transform parent,
     Colliders.PrimitiveCollider colliderType = Colliders.PrimitiveCollider.None) {
   // Default length scale is 2.0.
   var obj = CreatePrimitive(
       PrimitiveType.Cylinder, new Vector3(diameter, diameter, length / 2),
       material, parent: parent);
   Colliders.AdjustCollider(
       obj, new Vector3(diameter, diameter, length),
       colliderType, shapeType: PrimitiveType.Cylinder);
   return obj;
 }