Ejemplo n.º 1
0
    private void Update()
    {
        // Draw metric carcas
        var points = metric.points;

        for (int i = 1; i < points.Count; i++)
        {
            Debug.DrawLine(points[i - 1] + bounds.center, points[i] + bounds.center, new Color(0, 255, 0, 255));
        }

        var mousePosition = GetSnapedPoint(Input.mousePosition);

        if (!bounds.Contains(mousePosition))
        {
            return;
        }

        // Check if we want to add new point
        if (Input.GetMouseButtonUp(0))
        {
            if (isMetricCycle)
            {
                metric.Clear();
                isMetricCycle = false;
            }

            metric.AddPoint(mousePosition - bounds.center);

            if (points.Count != 1 && mousePosition == points[0])
            {
                isMetricCycle = true;
            }

            Debug.Log(string.Format("Adding point {0}", mousePosition));
        }

        // Draw preliminary point
        if (points.Count != 0 && !isMetricCycle)
        {
            Debug.DrawLine(points[points.Count - 1] + bounds.center, mousePosition, new Color(0, 255, 0, 128));
        }
    }