54 lines
1.6 KiB
C#
54 lines
1.6 KiB
C#
using UnityEngine;
|
|
using System.Collections.Generic;
|
|
using UnityEngine.UI;
|
|
using System;
|
|
|
|
namespace Octopus.Simulator
|
|
{
|
|
public class Panel_PlacedObject : MonoBehaviour
|
|
{
|
|
List<Button> buttons = new List<Button>();
|
|
[SerializeField]
|
|
Button ButtonPrefab;
|
|
RectTransform rect;
|
|
[SerializeField]
|
|
RectTransform contentRect;
|
|
|
|
public Action<string> onPlacedObjectSelected;
|
|
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
|
void Awake()
|
|
{
|
|
rect = GetComponent<RectTransform>();
|
|
}
|
|
|
|
void SetButton(string Name)
|
|
{
|
|
var models = DataManager.I.GetModels();
|
|
foreach (var model in models)
|
|
{
|
|
var button = Instantiate(ButtonPrefab, rect);
|
|
button.GetComponent<LogicPlacedObjectButton>().Set(model.name);
|
|
button.onClick.AddListener(() => LogicMappingDataBase.SetMapping(Name, model));
|
|
button.onClick.AddListener(() => Debug.Log(Name));
|
|
button.onClick.AddListener(() => onPlacedObjectSelected?.Invoke(Name));
|
|
buttons.Add(button);
|
|
}
|
|
LayoutRebuilder.ForceRebuildLayoutImmediate(contentRect);
|
|
}
|
|
|
|
void ClearButton()
|
|
{
|
|
foreach (var button in buttons)
|
|
{
|
|
Destroy(button.gameObject);
|
|
}
|
|
buttons.Clear();
|
|
}
|
|
|
|
public void OnLogicDataSelected(ILogicItem item)
|
|
{
|
|
ClearButton();
|
|
SetButton(item.Name);
|
|
}
|
|
}
|
|
} |