Exemplo n.º 1
0
    private void OnInteract(InputValue value)
    {
        LayerMask    layerMask = 1 << LayerMask.NameToLayer(Consts.ITEM_PHYSICS_LAYER);
        float        radius    = m_Manager.InteractionRadius;
        RaycastHit2D hit       = Physics2D.CircleCast(transform.position, radius, Vector2.zero, 0, layerMask);

        if (hit == true)
        {
            ItemGameObject item         = hit.collider.GetComponent <ItemGameObject>();
            bool           itemPickedUp = m_InventoryController.PickUpItem(item);
            if (itemPickedUp)
            {
                Destroy(item.gameObject);
            }
            return;
        }

        layerMask = 1 << LayerMask.NameToLayer(Consts.OBJECT_PHYSICS_LAYER);
        hit       = Physics2D.CircleCast(transform.position, radius, Vector2.zero, 0, layerMask);
        if (hit == true)
        {
            if (hit.collider.gameObject.CompareTag("Chest"))
            {
                hit.collider.GetComponent <Chest>().Interact();
            }
            else
            {
                Debug.LogException(new System.Exception("Unimplemented interaction with object"));
            }
        }
    }
Exemplo n.º 2
0
 public void ItemPickup(ItemGameObject item)
 {
     if (GlobalGameState.Instance.CurrentGameState.inventory.InsertItem(item.Item) != -1)
     {
         GlobalGameState.Instance.CurrentGameState.keyPicked = true;
         GameObject.Destroy(item.gameObject);
     }
 }
    private void PickUpItem(ItemGameObject item) {
        audioSource.PlayOneShotWithRandomPitch(AudioManager.Instance.PickUpObjectClip, 0.2f);

        ItemGameObject i = item.GetComponent<ItemGameObject>();
        if (i.Type == ItemType.Potion)
            Player.Instance.Potions++;
        else
            Player.Instance.Inventory.AddItem(new ItemData(i.Name, i.Type, i.MeshName, i.Sprite, i.Points, i.WeaponLength, i.AttackAngle));
        Destroy(item.gameObject);
    }
Exemplo n.º 4
0
        /// <summary>
        /// Pickup an item and put it into the <see cref="Inventory"/>
        /// </summary>
        /// <param name="item">Item to try to put into the inventory</param>
        void PickupItem(ItemGameObject item)
        {
            item.item.itemStackCount = 1;

            //* if the item can be added to the inventory do that
            if (AddItemToInventory(item.item))
            {
                QuestEvents.CallItemPickupEvent(item.item.GetHashCode());
                //* if the item was added destroy its gameobject and save the inventory
                Destroy(item.gameObject);
                Serialization.Serialization.SerializeInventory(this, inventoryName);
            }
        }
Exemplo n.º 5
0
    public static Sprite GetItemTypeIcon(ItemGameObject item) {
        if ((int)item.Type < 6)
            return ArmorIcon;
        else if (item.Type == ItemType.Shield)
            return ShieldIcon;
        else if (item.Type == ItemType.Weapon)
            return WeaponIcon;
        else if (item.Type == ItemType.Potion)
            return HealthIcon;

        Debug.Log("No corresponding item type found, returning armor icon.");
        return ArmorIcon;
    }
Exemplo n.º 6
0
    private void Start() {
        Transform itemParent = transform.FindChild("ItemInChestParent");
        if (itemParent.childCount == 0)
            return;

        itemInChest = itemParent.GetChild(0).GetComponent<ItemGameObject>();
        itemInChest.gameObject.SetActive(false);
        itemInChest.transform.position = transform.position;
        Destroy(itemInChest.GetComponent<Rigidbody>());
        itemInChest.gameObject.layer = 0;
        itemInChest.GetComponent<Collider>().isTrigger = true;
        itemInChest.GetComponent<Collider>().enabled = false;
    }
Exemplo n.º 7
0
 public void ItemExit(ItemGameObject item)
 {
 }
Exemplo n.º 8
0
 public void ItemEnter(ItemGameObject item)
 {
 }
Exemplo n.º 9
0
 public void ItemEnter(ItemGameObject item)
 {
     ShowPanel("PickupObject");
     PauseCharacter(true);
     itemPickedUp = false;
 }
Exemplo n.º 10
0
 public void ItemPickup(ItemGameObject item)
 {
     HidePanel("PickupObject");
     PauseCharacter(false);
     itemPickedUp = true;
 }
Exemplo n.º 11
0
 public bool PickUpItem(ItemGameObject item)
 {
     return(PickUpItem(item.GetID()));
 }
Exemplo n.º 12
0
    public bool Field1(Object undoObject, ItemGameObject del, bool removeButton = true)
    {
        if (del == null)
        {
            return(false);
        }
        bool prev = GUI.changed;

        GUI.changed = false;
        bool       retVal = false;
        GameObject target = null;
        GameObject parent = null;
        string     ID     = "";
        int        number = 0;

        if (removeButton && del.ID != "")
        {
            target = EditorGUILayout.ObjectField("key", del.target, typeof(GameObject), true) as GameObject;

            GUILayout.Space(-20f);
            GUILayout.BeginHorizontal();
            GUILayout.Space(36f);
            if (del.ID == "")
            {
                ID = "";                //"new point" ;
            }
            else
            {
                ID = del.ID;
            }

#if UNITY_3_5
            if (GUILayout.Button("X", GUILayout.Width(20f)))
#else
            if (GUILayout.Button("", "ToggleMixed", GUILayout.Width(20f)))
#endif
            {
                target = null;
                ID     = "";
            }
            GUILayout.EndHorizontal();
            if (ID != "")
            {
                GUILayout.Space(-20f);
                EditorGUILayout.BeginHorizontal();
                GUILayout.Space(56f);
                ID = EditorGUILayout.TextField("", ID, GUILayout.Width(60f));
                EditorGUILayout.EndHorizontal();
            }
        }
        else
        {
            ID = del.ID;
            string controlName = "point";

            tempstr = EditorGUILayout.TextField("key", tempstr);
            if (Event.current.isKey)
            {
                if (Event.current.keyCode == KeyCode.Return)
                {
                    ID      = tempstr;
                    tempstr = "";
                    //Debug.Log("yay");
                    Event.current.Use();
                }
            }
        }

        if (del.target != target || del.ID != ID)
        {
            NGUIEditorTools.RegisterUndo("del", undoObject);
            del.target = target;
            del.ID     = ID;
            UnityEditor.EditorUtility.SetDirty(undoObject);
        }
        if (del.target != null && del.ID == "")
        {
            GUILayout.Space(6f);
            EditorGUILayout.HelpBox("请设置key,否着无法新增", MessageType.Warning, true);
            GUILayout.Space(6f);
        }
        GUI.changed = prev;

        retVal      = GUI.changed;
        GUI.changed = prev;
        return(retVal);
    }
Exemplo n.º 13
0
    /// <summary>
    /// Draw a list of fields for the specified list of delegates.
    /// </summary>

    public void Field1(Object undoObject, List <ItemGameObject> list /*,Dictionary<string,HlepPoint> dictionary*/)
    {
        bool targetPresent = false;
        bool isValid       = false;

        DictionaryGameObject ut = undoObject as DictionaryGameObject;
        ItemGameObject       tempdel;

        // Draw existing delegates
        for (int i = 0; i < list.Count;)
        {
            ItemGameObject del = list[i];

            /*if (!dictionary.TryGetValue(del.ID,out tempdel))
             * {
             *      dictionary.Add(del.ID,del);
             * }*/
            if (del == null || del.ID == "")
            {
                //dictionary.Remove(del.ID);
                list.RemoveAt(i);
                continue;
            }
            string ID = del.ID;
            Field1(undoObject, del);
            EditorGUILayout.Space();
            if (ID != del.ID)
            {
                if (ut.CheckKey(del.ID) > 1)
                {
                    del.ID = ID;
                }

                /*else
                 * {
                 *      dictionary.Remove(ID);
                 *      dictionary.Add(del.ID,del);
                 * }*/
            }

            /*if(ID != del.ID)
             * {
             *      if (dictionary.TryGetValue(del.ID,out tempdel))
             *      {
             *              del.ID = ID;
             *      }
             *      else
             *      {
             *              dictionary.Remove(ID);
             *              dictionary.Add(del.ID,del);
             *      }
             * }*/

            ++i;
        }

        // Draw a new delegate
        ItemGameObject newDel = new ItemGameObject();

        Field1(undoObject, newDel);

        if (newDel.ID != "")
        {
            targetPresent = true;
            if (ut.CheckKey(newDel.ID) == 0)
            {
                list.Add(newDel);
            }

            /*if (!dictionary.TryGetValue(newDel.ID,out tempdel))
             * {
             *      dictionary.Add(newDel.ID,newDel);
             * }*/
        }
    }