Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class DrawPolygon : MonoBehaviour
- {
- public LineRenderer lineRenderer; //рендерер линий
- public GameObject panel;
- public InputField dummyInputField;
- public List<InputField> inpFields = new List<InputField>();
- public List<Vector3> points = new List<Vector3>(); //список вершин многоугольника
- public InputField verticesCountInp;
- public int verticesCount;
- public void DrawOnClick()
- {
- GetVectorList();
- lineRenderer.SetPositions(points.ToArray());
- }
- // Use this for initialization
- void Start()
- {
- inpFields.Clear();
- lineRenderer.startWidth = 0.05f;
- lineRenderer.endWidth = 0.05f;
- }
- // Update is called once per frame
- void Update()
- {
- int _verticesCount;
- try
- {
- _verticesCount = Int32.Parse(verticesCountInp.text);
- }
- catch (FormatException)
- {
- _verticesCount = 0;
- }
- if (verticesCount != _verticesCount)
- {
- verticesCount = _verticesCount;
- }
- if (inpFields.Count < verticesCount * 2)
- {
- for (int i = inpFields.Count; i < verticesCount * 2; i++)
- {
- inpFields.Add(Instantiate(dummyInputField, panel.transform, false));
- }
- }
- if (inpFields.Count > verticesCount * 2)
- {
- for (int i = inpFields.Count; i > verticesCount * 2; i -= 1)
- {
- Destroy(inpFields[i]);
- //inpFields.RemoveAt(i);
- }
- }
- }
- public void GetVectorList()
- {
- for (int i = 0; i <= inpFields.Count; i += 2)
- {
- try
- {
- points[i / 2].Set(Single.Parse(inpFields[i].text, CultureInfo.InvariantCulture), Single.Parse(inpFields[i++].text, CultureInfo.InvariantCulture), 0);
- }
- catch (FormatException)
- {
- points[i / 2].Set(0, 0, 0);
- Debug.LogError("WrongInput at " + points[i / 2] + "vertice.");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement