using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class DrawAxes : MonoBehaviour
{
    /// <summary> Model center </summary>
    [SerializeField] private GameObject cube;
    /// <summary> UI - toggle to turn on the axis </summary>
    [SerializeField] private Toggle axisToggle;
    /// <summary> Lines - axes </summary>
    [SerializeField] private LineRenderer axisX, axisY, axisZ;


    private void Start()
    {
        if (axisToggle.isOn)
        {
            //set number of positions
            axisX.positionCount = 2;
            axisY.positionCount = 2;
            axisZ.positionCount = 2;

            Vector3 Cubepos = cube.transform.localPosition;

            axisX.SetPositions(new Vector3[2] { Cubepos, new Vector3(Cubepos.x + 500, Cubepos.y, Cubepos.z) });
            axisY.SetPositions(new Vector3[2] { Cubepos, new Vector3(Cubepos.x, Cubepos.y + 500, Cubepos.z) });
            axisZ.SetPositions(new Vector3[2] { Cubepos, new Vector3(Cubepos.x, Cubepos.y, Cubepos.z - 500) });


        }
        else
        {
            //delete axis
            axisX.positionCount = 0;
            axisY.positionCount = 0;
            axisZ.positionCount = 0;
        }


    }


    /// <summary> Draw axes in center of model </summary>
    public void DrawLocalAxes()
    {
        
        if(axisToggle.isOn)
        {
            //set number of positions
            axisX.positionCount = 2;
            axisY.positionCount = 2;
            axisZ.positionCount = 2;

            Vector3 Cubepos = cube.transform.localPosition;

            axisX.SetPositions(new Vector3[2] { Cubepos, new Vector3(Cubepos.x + 500, Cubepos.y, Cubepos.z ) });
            axisY.SetPositions(new Vector3[2] { Cubepos, new Vector3(Cubepos.x, Cubepos.y + 500, Cubepos.z) });
            axisZ.SetPositions(new Vector3[2] { Cubepos, new Vector3(Cubepos.x, Cubepos.y, Cubepos.z - 500) });


        }
        else
        {
            //delete axis
            axisX.positionCount = 0;
            axisY.positionCount = 0;
            axisZ.positionCount = 0;
        }


    }
}

