コード例 #1
0
        public void Init(Player player, EquipmentPanel equipmentPanel)
        {
            this.Player = player;

            Equipment.Slot[] allSlots = (Equipment.Slot[])System.Enum.GetValues(typeof(Equipment.Slot));

            for (int i = 0; i < allSlots.Length; i++)
            {
                if (allSlots[i] == Equipment.Slot.Trinket)
                {
                    for (int j = 0; j < GameManager.Instance.equipmentManager.trinketCount; j++)
                    {
                        InstantiateSlot(player, Equipment.Slot.Trinket, ((string[])System.Enum.GetNames(typeof(Equipment.Slot)))[i], i + j, equipmentPanel, j);
                    }
                }
                else
                {
                    InstantiateSlot(player, allSlots[i], ((string[])System.Enum.GetNames(typeof(Equipment.Slot)))[i], i, equipmentPanel);
                }
            }

            Refresh();
        }
コード例 #2
0
        void InstantiateSlot(Player player, Equipment.Slot slot, string name, int index, EquipmentPanel equipmentPanel, int trinketIndex = -1)
        {
            GameObject slotGO = (GameObject)Instantiate(equipmentSlotPrefab, slotsHolder);

            RectTransform slotTransform = ((RectTransform)slotGO.transform);

            slotTransform.anchorMax = new Vector2(0, 1);
            slotTransform.anchorMin = new Vector2(0, 1);
            int row = index / 2;

            index %= 2;
            slotTransform.anchoredPosition = new Vector2(index * slotTransform.sizeDelta.x, -row * slotTransform.sizeDelta.y) + new Vector2(slotTransform.sizeDelta.x / 2, -slotTransform.sizeDelta.y / 2);

            slotGO.name = name + (trinketIndex > -1 ? (" " + trinketIndex.ToString()) : "");
            EquipmentSlot newSlot = slotGO.GetComponentInChildren <EquipmentSlot>();

            slots.Add(newSlot);
            slots[slots.Count - 1].Init(player, slot, trinketIndex);
            slotGO.transform.Find("Equipment Piece").GetComponent <Text>().text = name + ":";

            newSlot.gameObject.GetComponentInChildren <DroppableArea>().droppable = equipmentPanel;
            newSlot.gameObject.GetComponentInChildren <RemovableArea>().removable = equipmentPanel;
        }