using System; using System.Collections; using System.Collections.Generic; using Sirenix.OdinInspector; using TMPro; using UnityEngine; using UnityEngine.EventSystems; namespace Beyond { public class BlueprintScroll : MonoBehaviour, IPointerClickHandler { public BlueprintObject m_blueprintObject; public SignObject[] m_availableSigns; public RectTransform m_signSlotsContainer; public RectTransform m_signPopup; public RectTransform m_signPopupView; public BlueprintSlotButton m_slotPrefab; public BlueprintSignButton m_signPrefab; public Color m_selectedSlotColor; public int m_selectedId = -1; public TextMeshProUGUI m_title; public TextMeshProUGUI m_description; void ClearChildren(RectTransform root) { List objs = new List(); for (int i = 0; i < root.childCount; i++) { objs.Add(root.GetChild(i).gameObject); } foreach (var o in objs) { #if UNITY_EDITOR DestroyImmediate(o); #else Destroy(o); #endif } } internal void OnSignSelected(SignObject m_sign) { if (m_selectedId > -1) { var sb =m_signSlotsContainer.GetChild(m_selectedId).GetComponent(); if (sb) { sb.SetSign(m_sign); } } } internal void OnSlotClicked(BlueprintSlotButton slot) { Debug.Log("Slot id: " + slot.m_id); if (slot.m_id != m_selectedId) { m_selectedId = slot.m_id; //var colors = slot.m_button.colors; //colors.normalColor = m_selectedSlotColor; //slot.m_button.colors = colors; } else { m_selectedId = -1; //var colors = slot.m_button.colors; //colors.normalColor = Color.white; //slot.m_button.colors = colors; } if (m_selectedId != -1) { m_signPopup.gameObject.SetActive(true); } else { m_signPopup.gameObject.SetActive(false); } } internal void OnDeselect(BlueprintSlotButton blueprintSlotButton) { //m_signPopup.gameObject.SetActive(false); } // Start is called before the first frame update [Button] public void Populate() { if (m_blueprintObject == null) { Debug.LogWarning("Blueprint slot is null"); return; } if (m_slotPrefab == null) { Debug.LogWarning("m_slotPrefab slot is null"); return; } ClearChildren(m_signSlotsContainer); for (int i=0; i(m_slotPrefab, m_signSlotsContainer.transform); slot.m_id = i; } ClearChildren(m_signPopupView); for (int i=0; i(m_signPrefab, m_signPopupView); sb.SetSign(m_availableSigns[i]); } m_title.text = m_blueprintObject.m_name; m_description.text = m_blueprintObject.m_description; } void Start() { m_signPopup.gameObject.SetActive(false); } // Update is called once per frame void Update() { } public void OnPointerClick(PointerEventData pointerEventData) { if (pointerEventData.pointerCurrentRaycast.gameObject.name == "Deselector") { m_signPopup.gameObject.SetActive(false); } //Output to console the clicked GameObject's name and the following message. You can replace this with your own actions for when clicking the GameObject. Debug.Log("Clicked: " + pointerEventData.pointerCurrentRaycast.gameObject.name); } public void OnSelect(BaseEventData eventData) { m_signPopup.gameObject.SetActive(false); } } }