コード例 #1
0
        public static void RandomizeQuickSlots()
        {
            QuickSlots quickSlots = Inventory.main.quickSlots;

            // Make a list of all slots (including empty slots)
            List <InventoryItem> allSlots = new List <InventoryItem>();

            for (int i = 0; i < quickSlots.slotCount; i++)
            {
                allSlots.Add(quickSlots.GetSlotItem(i));
            }

            // Shuffle the list
            System.Random random = new System.Random();
            int           n      = allSlots.Count;

            while (n > 1)
            {
                n--;
                int           k     = random.Next(n + 1);
                InventoryItem value = allSlots[k];
                allSlots[k] = allSlots[n];
                allSlots[n] = value;
            }

            // Set the quick slots
            for (int i = 0; i < quickSlots.slotCount; i++)
            {
                quickSlots.binding[i] = allSlots[i];
            }
            // Notify the game that the slots have changed
            for (int i = 0; i < quickSlots.slotCount; i++)
            {
                quickSlots.NotifyBind(i, allSlots[i] != null);
            }
        }