示例#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;
 }
示例#2
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);
        }
示例#3
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;
 }