1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using Sirenix.OdinInspector;
- using KairoEngine.UI.InteractionHandler;
- [HideMonoScript]
- public class EncyclopediaUi : MonoBehaviour, IClickHandler
- {
- public EncyclopediaController controller;
- public GameObject menuGameObject;
- public GameObject subMenuGameObject;
- public GameObject viewsGameObject;
- public Transform menuContainer;
- public Transform subMenuContainer;
- public bool showDebug = false;
- public List<EncyclopediaUiView> views;
- private void Start()
- {
- if(menuGameObject == null) Debug.LogError("Missing Menu GameObject in EncyclopediaUi", this.gameObject);
- if(subMenuGameObject == null) Debug.LogError("Missing submenu GameObject in EncyclopediaUi", this.gameObject);
- if(viewsGameObject == null) Debug.LogError("Missing views GameObject in EncyclopediaUi", this.gameObject);
- }
- private void Update()
- {
-
- }
- [Button("Show Submenu"), ButtonGroup("EditorActions")]
- public void ShowSubmenu() => subMenuGameObject.SetActive(true);
- [Button("Hide Submenu"), ButtonGroup("EditorActions")]
- public void HideSubmenu() => subMenuGameObject.SetActive(false);
- public void Populate()
- {
- if(controller == null || menuContainer == null) return;
- Button[] oldButtons = menuContainer.GetComponentsInChildren<Button>();
- int counter = 0;
- if(showDebug) Debug.Log($"Destroying {oldButtons.Length} buttons");
- foreach (Button item in oldButtons) DestroyImmediate(item.gameObject);
- foreach (EncyclopediaCategory category in controller.categories)
- {
- var obj = Instantiate(category.buttonPrefab, new Vector3(), Quaternion.identity, menuContainer.transform);
- var btnData = obj.GetComponent<ButtonData>();
- if(btnData != null) btnData.Setup(category.title, category.icon);
- var handler = obj.GetComponent<ClickHandler>();
- if(handler != null) handler.Setup(category.layoutName, this);
- counter += 1;
- }
- if(showDebug) Debug.Log($"Created {counter} buttons");
- }
- public void OnClick(string title)
- {
- throw new System.NotImplementedException();
- }
- [System.Serializable]
- public class EncyclopediaUiView
- {
- [HorizontalGroup("Line", 0.4f), HideLabel] public string title;
- [HorizontalGroup("Line", 0.6f), HideLabel] public GameObject view;
- }
- }
|