Пример #1
0
    /// <summary>
    /// 建造家具
    /// </summary>
    /// <param name="listBuildPosition"></param>
    protected void BuildItemForFurniture(List <Vector3> listBuildPosition)
    {
        GameDataBean gameData = GameDataHandler.Instance.manager.GetGameData();

        //将家具添加到家具容器中
        buildItemCpt.transform.parent = InnBuildHandler.Instance.builderForFurniture.buildContainer.transform;
        //增加一个家具
        InnResBean addData = new InnResBean(buildItemCpt.buildItemData.id, buildItemCpt.transform.position, listBuildPosition, buildItemCpt.direction);

        //如果是门。需要重置一下墙体
        if (buildItemCpt.buildItemData.build_type == (int)BuildItemTypeEnum.Door)
        {
            //gameData.GetInnBuildData().InitWall(innBuildManager);
            //innWallBuilder.StartBuild();
        }
        else if (buildItemCpt.buildItemData.build_type == (int)BuildItemTypeEnum.Bed)
        {
            //如果是床。需要加上备注ID
            BuildBedCpt buildBedCpt = (BuildBedCpt)buildItemCpt;
            buildBedCpt.buildBedData.isSet = true;
            addData.remarkId = buildBedCpt.buildBedData.remarkId;
        }
        else if (buildItemCpt.buildItemData.build_type == (int)BuildItemTypeEnum.Stairs)
        {
            BuildStairsCpt buildStairsCpt = (BuildStairsCpt)buildItemCpt;
            //所有坐标下移
            List <Vector3> listFirstBuildPosition = new List <Vector3>();
            foreach (Vector3 itemPosition in listBuildPosition)
            {
                Vector3 firstPostion = itemPosition + new Vector3(0, -100, 0);
                listFirstBuildPosition.Add(firstPostion);
                //删除当前坐标下的建筑
                BuildItemForDismantle(buildLayer - 1, firstPostion, firstPostion);
            }

            //楼下也要添加同样的数据
            GameObject objFirstStairs = Instantiate(InnBuildHandler.Instance.builderForFurniture.buildContainer, buildItemCpt.gameObject);
            objFirstStairs.transform.position += new Vector3(0, -100, 0);
            BuildStairsCpt firstStairs = objFirstStairs.GetComponent <BuildStairsCpt>();
            firstStairs.SetLayer(buildLayer - 1);
            InnResBean addFirstData = new InnResBean(firstStairs.buildItemData.id, objFirstStairs.transform.position, listFirstBuildPosition, firstStairs.direction);
            //设置相同的备注ID
            addData.remarkId      = SystemUtil.GetUUID(SystemUtil.UUIDTypeEnum.N);
            addData.remark        = "2";
            addFirstData.remarkId = addData.remarkId;
            addFirstData.remark   = "1";
            gameData.GetInnBuildData().AddFurniture(buildLayer - 1, addFirstData);
            firstStairs.SetRemarkId(addData.remarkId);
            buildStairsCpt.SetRemarkId(addData.remarkId);
        }
        gameData.GetInnBuildData().AddFurniture(buildLayer, addData);
        //背包里删除一个
        ItemBean itemData = gameData.AddBuildNumber(buildItemCpt.buildItemData.id, -1);

        //动画
        buildItemCpt.transform
        .DOScale(new Vector3(0.2f, 0.2f, 0.2f), 0.5f)
        .From()
        .SetEase(Ease.OutBack);

        if (buildItemCpt.buildItemData.build_type == (int)BuildItemTypeEnum.Bed || itemData.itemNumber <= 0)
        {
            //如果没有了,则不能继续建造
            ClearSelectBuildItem();
        }
        else
        {
            //如果还有则实例化一个新的
            //物体先在建筑控件上显示
            GameObject objCopy = Instantiate(GameControlHandler.Instance.gameObject, buildItemCpt.gameObject);
            objCopy.transform.localScale = new Vector3(1, 1, 1);
            buildItemCpt = objCopy.GetComponent <BaseBuildItemCpt>();
        }
    }
Пример #2
0
    /// <summary>
    /// 通过ID获取家具Obj
    /// </summary>
    /// <param name="id"></param>
    /// <returns></returns>
    public GameObject GetFurnitureObjById(InnResBean furnitureData, Transform tfFather, BuildBedBean buildBedData)
    {
        BuildItemBean    buildItemData     = GetBuildDataById(furnitureData.id);
        GameObject       furnitureObjModel = GetModel(dicFurnitureCpt, "model/furniture", buildItemData.model_name);
        GameObject       furnitureObj      = Instantiate(tfFather.gameObject, furnitureObjModel);
        BaseBuildItemCpt buildItemCpt      = furnitureObj.GetComponent <BaseBuildItemCpt>();
        List <string>    listIcon          = buildItemData.GetIconList();

        switch ((BuildItemTypeEnum)buildItemData.build_type)
        {
        case BuildItemTypeEnum.Counter:
            BuildCounterCpt buildCounter   = (BuildCounterCpt)buildItemCpt;
            Sprite          spLeftCounter  = GetFurnitureSpriteByName(listIcon[0] + "_0");
            Sprite          spRightCounter = GetFurnitureSpriteByName(listIcon[0] + "_1");
            Sprite          spDownCounter  = GetFurnitureSpriteByName(listIcon[0] + "_2");
            Sprite          spUpCounter    = GetFurnitureSpriteByName(listIcon[0] + "_3");
            buildCounter.SetData(buildItemData, spLeftCounter, spRightCounter, spDownCounter, spUpCounter);
            break;

        case BuildItemTypeEnum.Stove:
            BuildStoveCpt buildStove   = (BuildStoveCpt)buildItemCpt;
            Sprite        spLeftStove  = GetFurnitureSpriteByName(listIcon[0] + "_0");
            Sprite        spRightStove = GetFurnitureSpriteByName(listIcon[0] + "_1");
            Sprite        spDownStove  = GetFurnitureSpriteByName(listIcon[0] + "_2");
            Sprite        spUpStove    = GetFurnitureSpriteByName(listIcon[0] + "_3");
            buildStove.SetData(buildItemData, spLeftStove, spRightStove, spDownStove, spUpStove);
            break;

        case BuildItemTypeEnum.Table:
            BuildTableCpt buildTable = (BuildTableCpt)buildItemCpt;

            Sprite spLeftChair  = GetFurnitureSpriteByName(listIcon[1] + "_0");
            Sprite spRightChair = GetFurnitureSpriteByName(listIcon[1] + "_1");
            Sprite spDownChair  = GetFurnitureSpriteByName(listIcon[1] + "_2");
            Sprite spUpChair    = GetFurnitureSpriteByName(listIcon[1] + "_3");

            if (buildItemData.model_name.Equals("Table_1"))
            {
                Sprite spTable = GetFurnitureSpriteByName(listIcon[0]);
                buildTable.SetData(buildItemData, spTable, spLeftChair, spRightChair, spDownChair, spUpChair);
            }
            else if (buildItemData.model_name.Equals("Table_2"))
            {
                Sprite spLeftTable  = GetFurnitureSpriteByName(listIcon[0] + "_0");
                Sprite spRightTable = GetFurnitureSpriteByName(listIcon[0] + "_1");
                Sprite spDownTable  = GetFurnitureSpriteByName(listIcon[0] + "_2");
                Sprite spUpTable    = GetFurnitureSpriteByName(listIcon[0] + "_3");
                buildTable.SetData(buildItemData, spLeftTable, spRightTable, spDownTable, spUpTable, spLeftChair, spRightChair, spDownChair, spUpChair);
            }

            break;

        case BuildItemTypeEnum.Decoration:
            BuildDecorationCpt buildDecoration = (BuildDecorationCpt)buildItemCpt;
            Sprite             spDecoration    = GetFurnitureSpriteByName(buildItemData.icon_key);
            buildDecoration.SetData(buildItemData, spDecoration);
            break;

        case BuildItemTypeEnum.Door:
            BuildDoorCpt buildDoor = (BuildDoorCpt)buildItemCpt;
            Sprite       spDoor    = GetFurnitureSpriteByName(listIcon[0]);
            buildDoor.SetData(buildItemData, spDoor);
            break;

        case BuildItemTypeEnum.Floor:
            BuildFloorCpt buildFloor = (BuildFloorCpt)buildItemCpt;
            Sprite        spFloor    = GetFloorSpriteByName(buildItemData.icon_key);
            buildFloor.SetData(buildItemData, spFloor);
            break;

        case BuildItemTypeEnum.Wall:
            BuildWallCpt buildWall = (BuildWallCpt)buildItemCpt;
            Sprite       spWall    = GetWallSpriteByName(buildItemData.icon_key);
            buildWall.SetData(buildItemData, spWall);
            break;

        case BuildItemTypeEnum.Bed:
            BuildBedCpt buildBed = (BuildBedCpt)buildItemCpt;
            buildBed.SetData(buildItemData, buildBedData);
            break;

        case BuildItemTypeEnum.Stairs:
            BuildStairsCpt buildStairs = (BuildStairsCpt)buildItemCpt;
            buildStairs.SetData(buildItemData);
            buildStairs.SetRemarkId(furnitureData.remarkId);
            if (furnitureData.remark != null && furnitureData.remark.Equals("1"))
            {
                buildStairs.SetLayer(1);
            }
            else
            {
                buildStairs.SetLayer(2);
            }
            break;

        default:
            buildItemCpt.SetData(buildItemData);
            break;
        }
        return(furnitureObj);
    }