protected override void Awake() { base.Awake(); GameObject masterSlot = GameObject.Find("Canvas/btn_inv"); m_canvas = GameObject.Find("Canvas"); if (m_canvas == null) { UnityEngine.Debug.LogWarning("Could not find canvas"); } if (masterSlot == null) { UnityEngine.Debug.LogWarning("Could not find inventory slot"); } else { m_inventorySlot.Add(InventorySlotUI.CreateFromGameObject(masterSlot, 0)); SetupEvents(m_inventorySlot[0]); } // TODO - Automate all of this using reflection m_healthText = GameObject.Find("Canvas/txt_Health").GetComponent <Text>(); m_mouseTileInfo = GameObject.Find("Canvas/txt_MouseCursorHover").GetComponent <Text>(); m_gameOverMessage = GameObject.Find("Canvas/txt_DeadMessage").GetComponent <Text>(); m_xpSlider = GameObject.Find("Canvas/sld_XP").GetComponent <Slider>(); m_txtLevel = GameObject.Find("Canvas/txt_Level").GetComponent <Text>(); }
private void Duplicate() { if (m_initialized) { return; } if (m_inventorySlot.Count == 0 || m_canvas == null) { return; } RectTransform rtOriginal = m_inventorySlot[0].m_parent.GetComponent <RectTransform>(); for (int i = 1; i < NumInventorySlots; ++i) { GameObject clone = (GameObject)Instantiate(m_inventorySlot[0].m_parent, m_inventorySlot[0].m_parent.transform.position, m_inventorySlot[0].m_parent.transform.rotation); if (clone != null) { clone.name = "btn_inv (" + i + ")"; clone.transform.SetParent(m_canvas.transform); //clone.transform.parent = m_canvas.transform; clone.transform.position = m_inventorySlot[0].m_parent.transform.position; clone.transform.localScale = new Vector3(1.0f, 1.0f, 1.0f); InventorySlotUI ui = InventorySlotUI.CreateFromGameObject(clone, i); m_inventorySlot.Add(ui); RectTransform rtClone = clone.GetComponent <RectTransform>(); Vector2 origin = rtOriginal.localPosition; float width = rtOriginal.GetWidth(); rtClone.localPosition = origin + new Vector2((width + 5) * i, 0f); SetupEvents(ui); if (i == 9) { ui.m_title.text = "0"; } else { ui.m_title.text = (i + 1).ToString(); } } } UpdateText(); m_initialized = true; }