123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- using System;
- using System.Collections.Generic;
- using UnityEngine;
- [ExecuteInEditMode]
- [AddComponentMenu("NGUI/Examples/Item Database")]
- public class InvDatabase : MonoBehaviour
- {
- public static InvDatabase[] list
- {
- get
- {
- if (InvDatabase.mIsDirty)
- {
- InvDatabase.mIsDirty = false;
- InvDatabase.mList = NGUITools.FindActive<InvDatabase>();
- }
- return InvDatabase.mList;
- }
- }
- private void OnEnable()
- {
- InvDatabase.mIsDirty = true;
- }
- private void OnDisable()
- {
- InvDatabase.mIsDirty = true;
- }
- private InvBaseItem GetItem(int id16)
- {
- int i = 0;
- int count = this.items.Count;
- while (i < count)
- {
- InvBaseItem invBaseItem = this.items[i];
- if (invBaseItem.id16 == id16)
- {
- return invBaseItem;
- }
- i++;
- }
- return null;
- }
- private static InvDatabase GetDatabase(int dbID)
- {
- int i = 0;
- int num = InvDatabase.list.Length;
- while (i < num)
- {
- InvDatabase invDatabase = InvDatabase.list[i];
- if (invDatabase.databaseID == dbID)
- {
- return invDatabase;
- }
- i++;
- }
- return null;
- }
- public static InvBaseItem FindByID(int id32)
- {
- InvDatabase database = InvDatabase.GetDatabase(id32 >> 16);
- return (!(database != null)) ? null : database.GetItem(id32 & 65535);
- }
- public static InvBaseItem FindByName(string exact)
- {
- int i = 0;
- int num = InvDatabase.list.Length;
- while (i < num)
- {
- InvDatabase invDatabase = InvDatabase.list[i];
- int j = 0;
- int count = invDatabase.items.Count;
- while (j < count)
- {
- InvBaseItem invBaseItem = invDatabase.items[j];
- if (invBaseItem.name == exact)
- {
- return invBaseItem;
- }
- j++;
- }
- i++;
- }
- return null;
- }
- public static int FindItemID(InvBaseItem item)
- {
- int i = 0;
- int num = InvDatabase.list.Length;
- while (i < num)
- {
- InvDatabase invDatabase = InvDatabase.list[i];
- if (invDatabase.items.Contains(item))
- {
- return invDatabase.databaseID << 16 | item.id16;
- }
- i++;
- }
- return -1;
- }
- private static InvDatabase[] mList;
- private static bool mIsDirty = true;
- public int databaseID;
- public List<InvBaseItem> items = new List<InvBaseItem>();
- public UIAtlas iconAtlas;
- }
|