Exemple #1
0
    void DisplayItems()
    {
        if (selectedType != null)
        {
            //for(int i = 0; i < InventoryDatabase.ElementCount; i++)
            for (int i = 0; i < selectedType.elementIDs.Count; i++)
            {
                InventoryElement item = InventoryDatabase.GetElement(selectedType.elementIDs[i]);

                if (item != null)
                {
                    if (item.type != null)
                    {
                        //if(selectedType.ID == item.type.ID)
                        {
                            EditorGUILayout.BeginHorizontal();
                            if (GUILayout.Button(item.name, GUILayout.ExpandWidth(true)))
                            {
                                GUI.FocusControl(null);
                                editItem  = item;
                                editState = EditState.EDITITEM;
                            }
                            EditorGUILayout.EndHorizontal();
                        }
                    }
                }
            }
        }
    }
    public void DamageBlock(string stringDamage)
    {
        RaycastHit hit;

        if (Physics.Raycast(Camera.main.transform.position, Camera.main.transform.forward, out hit, 10f, 1))
        {
            GameObject go = hit.transform.gameObject;

            if (!InventoryManager.inventory.isFull() || !InventoryManager.actionBar.isFull())
            {
                int    damage  = int.Parse(stringDamage);
                Health _health = go.GetComponent <Health>();
                _health.health -= damage;

                if (_health.health <= 0)
                {
                    LootableObject lo = _health.GetComponent <LootableObject>();

                    InventoryElement ie = new InventoryElement(InventoryDatabase.GetElement(lo.elementID));

                    if (!InventoryManager.inventory.isFull())
                    {
                        InventoryManager.inventory.AddItem(ref ie, false);
                    }
                    else if (!InventoryManager.actionBar.isFull())
                    {
                        InventoryManager.actionBar.AddItem(ref ie, false);
                    }

                    Destroy(go);
                }
            }
        }
    }
Exemple #3
0
    // Update is called once per frame
    void Update()
    {
        if (cameraComponent != null)
        {
            if (Physics.Raycast(transform.position, cameraComponent.transform.forward, out hit, distance, layerMask))
            {
                if (hit.transform.gameObject != null)
                {
                    GameObject possibleItem = hit.transform.gameObject;

                    if (possibleItem.GetComponent <LootableObject>() != null)
                    {
                        if (Input.GetKeyDown(lootKey))
                        {
                            if (lootableObject != possibleItem.GetComponent <LootableObject>())
                            {
                                lootableObject = possibleItem.GetComponent <LootableObject>();

                                InventoryElement invElem = InventoryDatabase.GetElement(lootableObject.elementID);

                                temp = new InventoryElement(invElem);
                            }
                            else
                            {
                                lootableObject.stack = temp.stack;
                            }

                            if (temp != null)
                            {
                                temp.stack = lootableObject.stack;

                                if (priority.Count > 0)
                                {
                                    foreach (InventoryObject invOb in priority)
                                    {
                                        if (invOb != null)
                                        {
                                            if (invOb.AddItem(ref temp, false))
                                            {
                                                Destroy(lootableObject.gameObject);
                                            }

                                            break;
                                        }
                                    }
                                }
                                else
                                {
                                    Debug.Log("Set up the priority system in FirstPersonLooting!");
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    public List <InventoryElement> GetElements()
    {
        List <InventoryElement> temp = new List <InventoryElement>();

        elementIDs.ForEach(x => temp.Add(InventoryDatabase.GetElement(x)));

        GetSubTypes().ForEach(x => x.elementIDs.ForEach(e => temp.Add(InventoryDatabase.GetElement(e))));

        return(temp);
    }
Exemple #5
0
    void Search()
    {
        if (InventoryDatabase.ElementCount > 0)
        {
            GUILayout.Label("Elements", EditorStyles.boldLabel);
        }

        for (int i = 0; i < InventoryDatabase.ElementCount; i++)
        {
            InventoryElement item = InventoryDatabase.GetElement(i);

            if (item != null)
            {
                if (item.name.IndexOf(searchString, StringComparison.CurrentCultureIgnoreCase) != -1)
                {
                    if (GUILayout.Button(item.name))
                    {
                        editItem  = item;
                        editState = EditState.EDITITEM;
                    }
                }
            }
        }

        if (InventoryDatabase.ElementTypeCount > 0)
        {
            GUILayout.Label("Types", EditorStyles.boldLabel);
        }

        for (int i = 0; i < InventoryDatabase.ElementTypeCount; i++)
        {
            ElementType elemType = InventoryDatabase.GetElementType(i);

            if (elemType != null)
            {
                if (elemType.name != null)
                {
                    if (elemType.name.IndexOf(searchString, StringComparison.CurrentCultureIgnoreCase) != -1)
                    {
                        if (GUILayout.Button(elemType.name))
                        {
                            editType  = elemType;
                            editState = EditState.EDITTYPE;
                        }
                    }
                }
            }
        }
    }
    void Loot()
    {
        if (hit.transform.gameObject != null)
        {
            GameObject possibleItem = hit.transform.gameObject;

            LootableObject cache = possibleItem.GetComponent <LootableObject>();

            if (cache != null)
            {
                InventoryElement invElem = InventoryDatabase.GetElement(cache.elementID);

                temp = new InventoryElement(invElem);

                if (temp != null)
                {
                    temp.stack = cache.stack;

                    if (priority.Count > 0)
                    {
                        foreach (InventoryObject invOb in priority)
                        {
                            if (invOb != null)
                            {
                                if (temp.stack > 0)
                                {
                                    invOb.AddItem(ref temp, false);
                                }

                                if (temp.stack == 0)
                                {
                                    Destroy(cache.gameObject);
                                    break;
                                }
                            }
                        }
                    }
                    else
                    {
                        Debug.Log("Set up the priority system in FirstPersonLooting!");
                    }
                }
            }
        }
    }
Exemple #7
0
    /// <summary>
    /// Returns Items if they were previously stored under 'key'
    /// </summary>
    public void Load(string key)
    {
        if (PlayerPrefs.HasKey(key))
        {
            BinaryFormatter binaryFormatter = new BinaryFormatter();

            string temp = PlayerPrefs.GetString(key);

            if (temp == "" || temp == null)
            {
                return;
            }

            MemoryStream memoryStream = new MemoryStream(System.Convert.FromBase64String(temp));

            List <SerializableItem> serializedItems = binaryFormatter.Deserialize(memoryStream) as List <SerializableItem>;

            foreach (Slot slot in Slots)
            {
                slot.inventoryElement = InventoryElement.Empty;
            }

            if (serializedItems != null)
            {
                if (InventoryDatabase.Instance != null)
                {
                    foreach (SerializableItem si in serializedItems)
                    {
                        if (si != null)
                        {
                            if (InventoryDatabase.Instance != null)
                            {
                                InventoryElement tempEl = InventoryDatabase.GetElement(si.itemID);

                                if (tempEl != null)
                                {
                                    if (Slots.Count > serializedItems.IndexOf(si))
                                    {
                                        Slots[serializedItems.IndexOf(si)].inventoryElement       = new InventoryElement(tempEl);
                                        Slots[serializedItems.IndexOf(si)].inventoryElement.stack = si.stack;
                                    }
                                }
                                else
                                {
                                    if (Slots.Count > serializedItems.IndexOf(si))
                                    {
                                        Slots[serializedItems.IndexOf(si)].inventoryElement = InventoryElement.Empty;
                                    }
                                }
                            }
                            else
                            {
                                Debug.LogError("There is no Inventory Database Instance!");
                            }
                        }
                    }

                    if (Application.isPlaying)
                    {
                        PlayerPrefs.DeleteKey(key);
                    }
                }
            }
        }
    }
    public override void OnInspectorGUI()
    {
        Slot slot = (Slot)target;

        serializedObject.Update();

        items.Clear();
        items.Add("None");

        for (int a = 0; a < InventoryDatabase.ElementCount; a++)
        {
            InventoryElement element = InventoryDatabase.GetElement(a);

            if (element != null)
            {
                if (element.id != -1)
                {
                    items.Add(element.name);
                }
            }
        }

        itemTypes.Clear();
        itemTypes.Add("None");

        for (int i = 0; i < InventoryDatabase.ElementTypeCount; i++)
        {
            ElementType it = InventoryDatabase.GetElementType(i);

            if (it.name != "")
            {
                itemTypes.Add(it.name);
            }
        }

        GUILayout.BeginHorizontal();
        slot.itemTypesFoldout = EditorGUILayout.Foldout(slot.itemTypesFoldout, "Accepted Element Types");
        GUILayout.EndHorizontal();

        if (slot.itemTypesFoldout)
        {
            GUILayout.BeginHorizontal();
            GUILayout.Space(15);
            slot.selectedItemType = EditorGUILayout.Popup("Element Types", slot.selectedItemType, itemTypes.ToArray());
            if (GUILayout.Button("Add", EditorStyles.miniButton) && slot.selectedItemType > 0)
            {
                ElementType elementType = InventoryDatabase.FindElementType(itemTypes[slot.selectedItemType]);
                slot.acceptedTypes.Add(elementType);
            }

            GUILayout.EndHorizontal();
        }
        for (int b = 0; b < slot.acceptedTypes.Count; b++)
        {
            string it = slot.acceptedTypes[b].name;

            GUILayout.BeginHorizontal(EditorStyles.toolbar);
            GUILayout.Space(15);
            EditorGUILayout.LabelField(b.ToString(), it);
            if (GUILayout.Button("-", EditorStyles.miniButton))
            {
                slot.acceptedTypes.RemoveAt(b);
            }
            GUILayout.EndHorizontal();
        }

        GUILayout.BeginHorizontal();
        slot.itemFoldout = EditorGUILayout.Foldout(slot.itemFoldout, "Element");
        GUILayout.EndHorizontal();

        if (slot.itemFoldout)
        {
            GUILayout.BeginHorizontal();
            GUILayout.Space(15);
            if (slot.inventoryElement != null)
            {
                EditorGUILayout.LabelField("Current", slot.inventoryElement.name);
            }
            else
            {
                EditorGUILayout.LabelField("Current", "None", EditorStyles.boldLabel);
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Space(15);
            slot.lockItem = EditorGUILayout.Toggle("Lock In Slot", slot.lockItem);
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Space(15);
            slot.itemSelection = EditorGUILayout.Popup("Add", slot.itemSelection, items.ToArray());

            if (GUILayout.Button("Add", EditorStyles.miniButton))
            {
                if (slot.itemSelection == 0)
                {
                    slot.inventoryElement = new InventoryElement();
                }
                else if (slot.inventoryElement.name == "" || slot.inventoryElement.id != InventoryDatabase.FindElement(items[slot.itemSelection]).id)
                {
                    slot.inventoryElement = new InventoryElement(InventoryDatabase.FindElement(items[slot.itemSelection]));
                }
                else
                {
                    if (slot.inventoryElement.stack < slot.inventoryElement.maxStack)
                    {
                        slot.inventoryElement.stack++;
                    }
                }
                if (slot.inventoryObject != null)
                {
                    slot.inventoryObject.Save(slot.inventoryObject.GetType().ToString());
                }
            }
            GUILayout.EndHorizontal();
        }

        GUILayout.BeginHorizontal();
        slot.slotActivationSettingsFoldout = EditorGUILayout.Foldout(slot.slotActivationSettingsFoldout, "Hotkey Settings");
        GUILayout.EndHorizontal();

        if (slot.slotActivationSettingsFoldout)
        {
            GUILayout.BeginHorizontal();
            GUILayout.Space(15);
            EditorGUILayout.PropertyField(serializedObject.FindProperty("activationCharacterText"), new GUIContent("Text"));
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Space(15);
            slot.activationCharacterFoldout = EditorGUILayout.Foldout(slot.activationCharacterFoldout, "Hotkey Character");
            GUILayout.EndHorizontal();

            if (slot.activationCharacterFoldout)
            {
                GUILayout.BeginHorizontal();
                GUILayout.Space(30);
                slot.activationInt = EditorGUILayout.Popup("Keys", slot.activationInt, slot.activationCharacters);
                GUILayout.EndHorizontal();
            }

            GUILayout.BeginHorizontal();
            GUILayout.Space(15);
            slot.activationResponseFoldout = EditorGUILayout.Foldout(slot.activationResponseFoldout, "Response");
            GUILayout.EndHorizontal();

            if (slot.activationResponseFoldout)
            {
                GUILayout.BeginHorizontal();
                GUILayout.Space(30);
                slot.ifActivateOnHotkey = EditorGUILayout.Toggle("Activate Slot", slot.ifActivateOnHotkey);
                GUILayout.EndHorizontal();

                if (slot.ifActivateOnHotkey)
                {
                    GUILayout.BeginHorizontal();
                    GUILayout.Space(30);
                    slot.changeSize = EditorGUILayout.Toggle("Change Size", slot.changeSize);
                    GUILayout.EndHorizontal();

                    if (slot.changeSize)
                    {
                        GUILayout.BeginHorizontal();
                        GUILayout.Space(30);
                        slot.changeSizeVector2 = EditorGUILayout.Vector2Field("Size", slot.changeSizeVector2);
                        GUILayout.EndHorizontal();
                    }

                    GUILayout.BeginHorizontal();
                    GUILayout.Space(30);
                    slot.changeTexture = EditorGUILayout.Toggle("Change Texture", slot.changeTexture);
                    GUILayout.EndHorizontal();

                    if (slot.changeTexture)
                    {
                        GUILayout.BeginHorizontal();
                        GUILayout.Space(30);
                        slot.changeTextureImage = (Texture)EditorGUILayout.ObjectField("Texture", slot.changeTextureImage, typeof(Texture), true);
                        GUILayout.EndHorizontal();
                    }
                }
            }
        }

        GUILayout.BeginHorizontal();
        slot.backgroundFoldout = EditorGUILayout.Foldout(slot.backgroundFoldout, "Background");
        GUILayout.EndHorizontal();

        if (slot.backgroundFoldout)
        {
            GUILayout.BeginHorizontal();
            GUILayout.Space(15);
            EditorGUILayout.PropertyField(serializedObject.FindProperty("backgroundRawImage"), new GUIContent("Activation Character"));
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Space(15);
            slot.backgroundRawImage.texture = (Texture)EditorGUILayout.ObjectField("Background", slot.backgroundRawImage.texture, typeof(Texture), true);
            GUILayout.EndHorizontal();
        }

        GUILayout.BeginHorizontal();
        slot.slotTextFoldout = EditorGUILayout.Foldout(slot.slotTextFoldout, "Text");
        GUILayout.EndHorizontal();

        if (slot.slotTextFoldout)
        {
            GUILayout.BeginHorizontal();
            GUILayout.Space(15);
            slot.disableTextIfItem = EditorGUILayout.Toggle("Disable Text if Element Exists", slot.disableTextIfItem);
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Space(15);
            EditorGUILayout.PropertyField(serializedObject.FindProperty("slotText"), new GUIContent("Activation Character"));
            GUILayout.EndHorizontal();
        }
        serializedObject.ApplyModifiedProperties();

        if (GUI.changed)
        {
            EditorUtility.SetDirty(target);
        }
    }