using UnityEngine; using System.Collections.Generic; using UnityEngine.Serialization; using System.Collections.ObjectModel; using System.Linq; namespace UnityEngine.ProBuilder { /// /// Represents a component that handles the creation of shapes /// from a set of contiguous points. /// [AddComponentMenu("")] [DisallowMultipleComponent] [ExcludeFromPreset, ExcludeFromObjectFactory] [ProGridsConditionalSnap] public sealed class PolyShape : MonoBehaviour { /// /// Describes the different input states this tool operates in. /// internal enum PolyEditMode { None, Path, Height, Edit } ProBuilderMesh m_Mesh; [FormerlySerializedAs("points")] [SerializeField] internal List m_Points = new List(); [FormerlySerializedAs("extrude")] [SerializeField] float m_Extrude = 0f; [FormerlySerializedAs("polyEditMode")] [SerializeField] PolyEditMode m_EditMode; [FormerlySerializedAs("flipNormals")] [SerializeField] bool m_FlipNormals; [SerializeField] internal bool isOnGrid = true; /// /// Gets the points that form the path for the base of this shape. /// public ReadOnlyCollection controlPoints { get { return new ReadOnlyCollection(m_Points); } } /// /// Sets the list of points that form the path for the base of this shape. /// /// List of positions that define this PolyShape. public void SetControlPoints(IList points) { m_Points = points.ToList(); } /// /// Gets or sets the distance that this shape should extrude from the base. After setting this value, /// you need to invoke to /// rebuild the component. /// public float extrude { get { return m_Extrude; } set { m_Extrude = value; } } internal PolyEditMode polyEditMode { get { return m_EditMode; } set { m_EditMode = value; } } /// /// Defines the direction for this shape's normals. Use this to invert the normals, creating a /// volume with the normals facing inwards. /// public bool flipNormals { get { return m_FlipNormals; } set { m_FlipNormals = value; } } internal ProBuilderMesh mesh { get { if (m_Mesh == null) m_Mesh = GetComponent(); return m_Mesh; } set { m_Mesh = value; } } /// /// ProGridsConditionalSnap tells pg_Editor to reflect this value. /// /// bool IsSnapEnabled() { return isOnGrid; } } }