using UnityEngine;
/// <summary>
/// Fill the specified items into the bag when the script is started.
/// </summary>
[AddComponentMenu("NGUI/Examples/Equip Backpack")]
public class EquipBackpack : MonoBehaviour
{
public int[] itemIDs;
void Start ()
{
if (itemIDs != null && itemIDs.Length > 0)
{
//UIItemStorage used instead of InvEquipment
UIItemStorage eq = GetComponent<UIItemStorage>();
if (eq == null) eq = gameObject.AddComponent<UIItemStorage>();
int qualityLevels = (int)InvGameItem.Quality._LastDoNotUse;
for (int i = 0, imax = itemIDs.Length; i < imax; ++i)
{
int index = itemIDs[i];
InvBaseItem item = InvDatabase.FindByID(index);
if (item != null)
{
InvGameItem gi
= new InvGameItem
(index, item
); gi.quality = (InvGameItem.Quality)Random.Range(0, qualityLevels);
gi.itemLevel = NGUITools.RandomRange(item.minItemLevel, item.maxItemLevel);
//Our custom equip requires a slot # pulled from the inspector in this case.
eq.Equip(i, gi);
}
else
{
Debug.LogWarning("Can't resolve the item ID of " + index);
}
}
}
Destroy(this);
}
}