EquipItems.cs 1006 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using System;
  2. using UnityEngine;
  3. [AddComponentMenu("NGUI/Examples/Equip Items")]
  4. public class EquipItems : MonoBehaviour
  5. {
  6. private void Start()
  7. {
  8. if (this.itemIDs != null && this.itemIDs.Length > 0)
  9. {
  10. InvEquipment invEquipment = base.GetComponent<InvEquipment>();
  11. if (invEquipment == null)
  12. {
  13. invEquipment = base.gameObject.AddComponent<InvEquipment>();
  14. }
  15. int max = 12;
  16. int i = 0;
  17. int num = this.itemIDs.Length;
  18. while (i < num)
  19. {
  20. int num2 = this.itemIDs[i];
  21. InvBaseItem invBaseItem = InvDatabase.FindByID(num2);
  22. if (invBaseItem != null)
  23. {
  24. invEquipment.Equip(new InvGameItem(num2, invBaseItem)
  25. {
  26. quality = (InvGameItem.Quality)UnityEngine.Random.Range(0, max),
  27. itemLevel = NGUITools.RandomRange(invBaseItem.minItemLevel, invBaseItem.maxItemLevel)
  28. });
  29. }
  30. else
  31. {
  32. Debug.LogWarning("Can't resolve the item ID of " + num2);
  33. }
  34. i++;
  35. }
  36. }
  37. UnityEngine.Object.Destroy(this);
  38. }
  39. public int[] itemIDs;
  40. }