100 lines
3.0 KiB
C#
100 lines
3.0 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class PositionListScript : MonoBehaviour
|
|
{
|
|
[SerializeField]
|
|
PositionListElement _positionListElementTemplate;
|
|
|
|
[SerializeField]
|
|
List<PositionListElement> _positionsList = new();
|
|
|
|
|
|
|
|
|
|
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
|
void Start()
|
|
{
|
|
StartCoroutine(waitForMachineInit());
|
|
}
|
|
|
|
private IEnumerator waitForMachineInit()
|
|
{
|
|
while (MachineCoordinatesMovementScript.CurrentProgram == null) { yield return null; }
|
|
fillList();
|
|
}
|
|
|
|
private void fillList()
|
|
{
|
|
PositionListElement newElement;
|
|
|
|
for (int i = 1; i < MachineCoordinatesMovementScript.CurrentProgram.Count; i+=2)
|
|
{
|
|
newElement = createNewElementObject(-1f * (i - 1) * _positionListElementTemplate.GetComponent<RectTransform>().rect.height/2);
|
|
|
|
_positionsList.Add(newElement);
|
|
|
|
newElement.SetProperty("No", _positionsList.Count.ToString());
|
|
|
|
int smdComponentIndex = MachineCoordinatesMovementScript.ComponentsHoldersCords.IndexOf(
|
|
MachineCoordinatesMovementScript.CurrentProgram[i-1]);
|
|
newElement.SetProperty("Type", smdComponentIndex.ToString());
|
|
|
|
switch (smdComponentIndex)
|
|
{
|
|
case 0:
|
|
newElement.SetProperty("Name", "R6");
|
|
break;
|
|
|
|
case 1:
|
|
newElement.SetProperty("Name", "C2");
|
|
break;
|
|
|
|
case 2:
|
|
newElement.SetProperty("Name", "C1");
|
|
break;
|
|
|
|
case 3:
|
|
newElement.SetProperty("Name", "LED3");
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
|
|
newElement.SetProperty("X", MachineCoordinatesMovementScript.CurrentProgram[i].x.ToString());
|
|
newElement.SetProperty("Y", MachineCoordinatesMovementScript.CurrentProgram[i].y.ToString());
|
|
newElement.SetProperty("Z", MachineCoordinatesMovementScript.CurrentProgram[i].z.ToString());
|
|
newElement.SetProperty("A", "1");
|
|
newElement.SetProperty("Val", "1");
|
|
newElement.SetProperty("Feeder", "B");
|
|
}
|
|
}
|
|
|
|
private PositionListElement createNewElementObject(float y_pos)
|
|
{
|
|
GameObject newObject = Instantiate(_positionListElementTemplate.gameObject, _positionListElementTemplate.transform.parent);
|
|
newObject.GetComponent<RectTransform>().localPosition = new(0, y_pos, 0);
|
|
|
|
newObject.SetActive(true);
|
|
return newObject.GetComponent<PositionListElement>();
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
if (MachineCoordinatesMovementScript.CurrentStep == 0) return;
|
|
//{ _positionsList[MachineCoordinatesMovementScript.CurrentStep]}
|
|
|
|
if (MachineCoordinatesMovementScript.CurrentStep % 2 == 0)
|
|
{
|
|
PositionListElement currentElement = _positionsList[MachineCoordinatesMovementScript.CurrentStep-1];
|
|
currentElement.GetComponent<Image>().color = currentElement.HighlightedColor;
|
|
}
|
|
}
|
|
}
|