77 lines
2.2 KiB
C#
77 lines
2.2 KiB
C#
using System;
|
|
using UnityEngine;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using Unity.VisualScripting;
|
|
using Unity.XR.CoreUtils;
|
|
using UnityEngine.UI;
|
|
using Button = UnityEngine.UI.Button;
|
|
|
|
public class ChildModelSelector : MonoBehaviour
|
|
{
|
|
private List<GameObject> Models = new List<GameObject>();
|
|
public ModelManager modelManager;
|
|
public GameObject cmpPrefab; //childModelPickerPrefab (the actual button)
|
|
public GameObject daddy;
|
|
public ColorSelector colorSelector;
|
|
|
|
private string portId { set; get; }
|
|
public string PortID
|
|
{
|
|
set
|
|
{
|
|
portId = value;
|
|
}
|
|
get
|
|
{
|
|
return portId;
|
|
}
|
|
}
|
|
public int PortIndex { set; get; }
|
|
|
|
void Start()
|
|
{
|
|
|
|
}
|
|
|
|
public void AssignButtons()
|
|
{
|
|
Debug.Log($"Destroying Old CMS Pickers: {Models.Count}");
|
|
foreach (var go in Models)
|
|
{
|
|
if (go == null)
|
|
{
|
|
continue;
|
|
}
|
|
Debug.Log($"Destroying {go.name}");
|
|
Destroy(go);
|
|
}
|
|
Models.Clear();
|
|
|
|
var childModels = modelManager.GetChildModelsForPort(PortID);
|
|
foreach (var childModel in childModels)
|
|
{
|
|
Debug.Log($"Adding {childModel}");
|
|
GameObject go = Spawn.GO(cmpPrefab, daddy.transform, Vector3.zero, "picker:" + childModel.Port + ":" + childModel.NameId);
|
|
go.SetActive(true);
|
|
go.GetNamedChild("Icon").GetComponent<Image>().sprite = Resources.Load<Sprite>($"sprites/" + childModel.NameId);
|
|
TextMeshProUGUI[] label = go.GetComponentsInChildren<TextMeshProUGUI>();
|
|
if (label.Length > 0)
|
|
{
|
|
label[0].text = childModel.NameHuman;
|
|
label[1].text = "Bottom Text"; //TODO: add Secondary Text?
|
|
}
|
|
go.GetComponent<Button>().onClick.AddListener(() => OnClick(childModel));
|
|
Models.Add(go);
|
|
}
|
|
}
|
|
|
|
public void OnClick(ChildModel model)
|
|
{
|
|
modelManager.BaseModelBehaviour.UpdateChild(PortIndex, model.NameId);
|
|
|
|
colorSelector.GenerateButtons(model, PortIndex);
|
|
}
|
|
}
|
|
|