This editor script creates a cone with the specified tessellation (=number of vertices), top radius, bottom radius, and length. With top radius == bottom radius, the result is a cylinder. With none of the radii == 0, the result is a ***ncated cone. So far the resulting cone has no end caps, but you can create caps on your own by using a cone with one radius==0 and length==0.
Note it is inevitable that a ***e cone (one of the radii == 0) cannot be rendered completely smooth, and will show facetting artifacts.
使用方法:
Place this script as "CreateCone.cs" in YourProject/Assets/Editor and a menu item will automatically appear in the "GameObject/Create Other" menu after it is compiled.
Num Vertices is the number of vertices each end will have.
Radius Top is the radius at the top. The center point will be located at (0/0/0).
Radius Bottom is the radius at the bottom. The center point will be located at (0/0/Length).
Length is the number of world units long the plane will be (+Z direction).
Opening Angle If this is >0, the top radius is set to 0, and the bottom radius is computed depending on the length, so that the given opening angle is created.
Outside defines whether the outside is visible (default).
Inside defines whether the inside is visible. Set both outside and inside to create a double-sided primitive.
Add Collider creates a matching mesh collider for the cone if checked.
C# - CreateCone.cs
using UnityEngine;
using UnityEditor;
using System.Collections;
// a static method to create a cone primitive (so far no end caps)
// the top center is placed at (0/0/0)
// the bottom center is placed at (0/0/length)
// if either one of the radii is 0, the result will be a cone, otherwise a ***ncated cone
// note you will get inevitable breaks in the smooth shading at cone tips
// Author: Wolfram Kresse
public class CreateCone : ScriptableWizard {
public int numVertices = 10;
public float radiusTop = 0f;
public float radiusBottom = 1f;
public float length = 1f;
public float openingAngle = 0f; // if >0, create a cone with this angle by setting radiusTop to 0, and adjust radiusBottom according to length;