예제 #1
0
    void RemoveDead(DeadComponent dead)
    {
        GameObject.Destroy(dead.gameObject, 1);
        //播放死亡动画
        VoxelBlocks map = GameObject.Find("Voxel Map").transform.GetComponent <VoxelBlocks> ();

        map.RemoveBlock(dead.GetComponent <BlockInfoComponent> ().m_logicPosition);
    }
예제 #2
0
    bool GetItem(BasicEntity entity, Vector3 mousePos)
    {
        VoxelBlocks map = GameObject.Find("Voxel Map").transform.GetComponent <VoxelBlocks>();
        //获取角色位置
        Vector3 pos = entity.GetComponent <BlockInfoComponent>().m_logicPosition;

        //判断鼠标位置是否在角色旁边
        if ((Mathf.Abs(pos.x - mousePos.x) <= 1.5f) && (Mathf.Abs(pos.y - mousePos.y) <= 1.5f))
        {
            //获取鼠标位置上的格子信息
            BlockInfo blockInfo = map.GetBlockByLogicPos(mousePos);
            if (blockInfo == null)
            {
                return(false);
            }
            BasicEntity itemEntity = blockInfo.entity;

            if (itemEntity != null)
            {
                ItemInfoComponent itemInfo = itemEntity.GetComponent <ItemInfoComponent>();
                //若该格子上不存在物品则退出
                if (itemInfo == null)
                {
                    return(false);
                }
                ItemComponent itemComp = entity.GetComponent <ItemComponent>();
                //判断物品是否超出持有上限
                if (itemInfo.num + itemComp.item.Count > itemComp.numLimit)
                {
                    //删除物品
                    itemComp.item.RemoveRange(0, itemInfo.num + itemComp.item.Count - itemComp.numLimit);
                }
                //添加物品
                for (int i = 0; i < itemInfo.num; i++)
                {
                    itemComp.item.Add(itemInfo.type);
                }
                map.RemoveBlock(mousePos);
                itemInfo.m_entity.RemoveAllComponent();
                GameObject.Destroy(itemInfo.gameObject);
            }
            return(true);
        }
        else
        {
            return(false);
        }
    }