12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- using System.Collections.Generic;
- using System.Linq;
- using UnityEngine;
- using UnityEngine.UI;
- public class DrawText : DrawShape
- {
- private RectTransform rectTransform_;
- private Vector3[] lineCorners_;
- // Start and end vertices (in absolute coordinates)
- private readonly List<Vector2> _vertices = new List<Vector2>(2);
- private void Awake()
- {
- rectTransform_ = GetComponent<RectTransform>();
- Debug.Log("DrawText awake");
- lineCorners_ = new Vector3[4];
- // 2 вершины будут рассчитываться, другие 2 получаться
- lineCorners_[1] = new Vector3();
- lineCorners_[3] = new Vector3();
- }
- public override void StartDraw(Vector2 position)
- {
- _vertices.Add(position);
- _vertices.Add(position);
- }
- public override void StopDraw(Vector2 position)
- {
- Image image = GetComponent<Image>();
- image.enabled = false;
- }
- public override void UpdateShape(Vector2 newPosition)
- {
- _vertices[_vertices.Count - 1] = newPosition;
- rectTransform_.sizeDelta = new Vector2(Mathf.Abs(_vertices[0].x - _vertices[1].x), Mathf.Abs(_vertices[0].y - _vertices[1].y));
- rectTransform_.transform.position = new Vector2(Mathf.Min(_vertices[0].x, _vertices[1].x), Mathf.Min(_vertices[0].y, _vertices[1].y));
- }
- public override void Clear()
- {
- }
- }
|