Example #1
0
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        AmmoDatabase ammoDB = GameDatabase.Instance.ammoDatabase;

        if (ammoDB.entries == null || ammoDB.entries.Length == 0)
        {
            EditorGUI.HelpBox(position, "Please define at least 1 ammo type in the Game Database", MessageType.Error);
        }
        else
        {
            int currentID  = property.intValue;
            int currentIdx = -1;

            //this is pretty ineffective, maybe find a way to cache that if prove to take too much time
            string[] names = new string[ammoDB.entries.Length];
            for (int i = 0; i < ammoDB.entries.Length; ++i)
            {
                names[i] = ammoDB.entries[i].name;
                if (ammoDB.entries[i].id == currentID)
                {
                    currentIdx = i;
                }
            }

            EditorGUI.BeginChangeCheck();
            int idx = EditorGUI.Popup(position, "Ammo Type", currentIdx, names);
            if (EditorGUI.EndChangeCheck())
            {
                property.intValue = ammoDB.entries[idx].id;
            }
        }
    }
 void Start()
 {
     hotbar = GameObject.Find("Inventory").GetComponent<Hotbar>();
     weaponDatabase = GameObject.Find("Inventory").GetComponent<WeaponDatabase>();
     ammoDatabase = GameObject.Find("Inventory").GetComponent<AmmoDatabase>();
     inventory = GameObject.Find("Inventory").GetComponent<Inventory>();
     itemDatabase = GameObject.Find("Inventory").GetComponent<ItemDatabase>();
     audioSource = gameObject.AddComponent<AudioSource>();
     totalAmmoText = GameObject.Find("TotalAmount").GetComponent<Text>();
     currentAmmoText = GameObject.Find("ClipAmount").GetComponent<Text>();
 }