Beispiel #1
0
 /// <summary>
 /// 添加物体方法
 /// </summary>
 void AddItem()
 {
     if (!bag_in.bagList.Contains(item))
     {//若果不包含
         //遍历寻找空的格子
         for (int i = 0; i < bag_in.bagList.Count; i++)
         {
             if (bag_in.bagList[i] == null)
             {//找到第一个空值
                 bag_in.bagList[i] = item;
                 //刷新列表
                 BagManager.RefreshItem();
                 //删除物品
                 Destroy(gameObject);
                 return;
             }
         }
         //若没有找到空值
         BagIsFull();
     }
     else
     {//若包含
         item.itemCount++;
         //刷新列表
         BagManager.RefreshItem();
         //删除物品
         Destroy(gameObject);
     }
 }
    public void Execute()
    {
        foreach (GameEntity e in _entities)
        {
            if (e.isDropped.isdrop == true)
            {
                GameObject    itemonworld = e.view.gameObject;
                BoxCollider2D bc          = itemonworld.GetComponent <BoxCollider2D>();

                Collider2D[]    results       = new Collider2D[3];
                ContactFilter2D contactFilter = new ContactFilter2D();
                contactFilter.useTriggers = true;
                bc.OverlapCollider(contactFilter, results); // 第一次返回的有bug,设置start规避

                foreach (Collider2D other in results)
                {
                    if (start == true && other != null && other.gameObject.CompareTag("Player"))  // 人物名称Tag
                    {
                        Debug.Log("检测到物品与玩家碰撞");
                        e.isDropped.isdrop = false;
                        GameEntity bag          = _Bag.GetEntities()[0];
                        int        character_id = 0;
                        int        item_id      = e.itemIndex.id;

                        BagManager.AddItem2Entity(bag, character_id, item_id);
                        BagManager.RefreshItem(bag, _items);
                        Object.Destroy(itemonworld);
                    }
                }
                start = true;
            }
        }
    }
Beispiel #3
0
 /// <summary>
 /// "O"键功能:
 /// 背包菜单
 /// </summary>
 void OnePressed()
 {
     if (Input.GetKeyDown(KeyCode.O))
     {
         ChangeActiveState(mainMenu);
     }
     else if (Input.GetKeyDown(KeyCode.I))
     {
         ChangeActiveState(myBag);
         if (myBag.activeSelf)
         {
             BagManager.RefreshItem();
         }
     }
 }