using UnityEngine; // Shapes © Freya Holmér - https://twitter.com/FreyaHolmer/ // Website & Documentation - https://acegikmo.com/shapes/ namespace Shapes { /// A Cone shape component [ExecuteAlways] [AddComponentMenu( "Shapes/Cone" )] public class Cone : ShapeRenderer { [SerializeField] float radius = 1; /// The radius of the base of the cone public float Radius { get => radius; set => SetFloatNow( ShapesMaterialUtils.propRadius, radius = Mathf.Max( 0f, value ) ); } [SerializeField] float length = 1.5f; /// The length/height of this cone public float Length { get => length; set => SetFloatNow( ShapesMaterialUtils.propLength, length = Mathf.Max( 0f, value ) ); } [SerializeField] ThicknessSpace sizeSpace = Shapes.ThicknessSpace.Meters; /// this property is obsolete I'm sorry! this was a typo, please use SizeSpace instead! [System.Obsolete( "this property is obsolete I'm sorry! this was a typo, please use SizeSpace instead!", true )] public ThicknessSpace RadiusSpace { get => SizeSpace; set => SizeSpace = value; } /// The space in which radius and length is defined in public ThicknessSpace SizeSpace { get => sizeSpace; set => SetIntNow( ShapesMaterialUtils.propSizeSpace, (int)( sizeSpace = value ) ); } [SerializeField] bool fillCap = true; /// Whether or not the base cap should be filled public bool FillCap { get => fillCap; set { fillCap = value; UpdateMesh( true ); } } private protected override void SetAllMaterialProperties() { SetFloat( ShapesMaterialUtils.propRadius, radius ); SetFloat( ShapesMaterialUtils.propLength, length ); SetInt( ShapesMaterialUtils.propSizeSpace, (int)sizeSpace ); } private protected override void ShapeClampRanges() { radius = Mathf.Max( 0f, radius ); length = Mathf.Max( 0f, length ); } internal override bool HasDetailLevels => true; internal override bool HasScaleModes => false; private protected override Material[] GetMaterials() => new[] { ShapesMaterialUtils.matCone[BlendMode] }; private protected override Mesh GetInitialMeshAsset() => fillCap ? ShapesMeshUtils.ConeMesh[(int)detailLevel] : ShapesMeshUtils.ConeMeshUncapped[(int)detailLevel]; private protected override Bounds GetBounds_Internal() { if( sizeSpace != ThicknessSpace.Meters ) return new Bounds( Vector3.zero, Vector3.one ); return new Bounds( Vector3.zero, new Vector3( radius * 2, radius * 2, length ) ); } } }