示例#1
0
 /// <summary>
 /// 修改建造规则
 /// </summary>
 public virtual void ChangeBuildRule(BuildRuleEnum buildRule)
 {
     //方向不同时才修改模型
     if (buildRule == buildBaseData.GetBuildRule())
     {
         return;
     }
     buildBaseData.SetBuildRule(buildRule);
     SetBuildModel(buildRule);
     AnimForChangeRule();
 }
示例#2
0
    public void CreateAllBuild(string modelName)
    {
        BuildHandler.Instance.manager.LoadBuildBaseRes(BuildTypeEnum.Building, modelName);

        List <BuildRuleEnum> ruleList = EnumUtil.GetEnumValue <BuildRuleEnum>();

        for (int i = 0; i < ruleList.Count; i++)
        {
            BuildRuleEnum itemRule = ruleList[i];
            GameObject    objModel = BuildHandler.Instance.manager.GetBuildBaseModel(null, itemRule, modelName);
            GameObject    objBuild = Instantiate(gameObject, modelBuilding.gameObject);

            BuildBase buildBase = objBuild.GetComponent <BuildBase>();

            BuildBaseBean buildBaseData = new BuildBaseBean();
            Vector3       centerPostion = new Vector3(i * 5, 0, 0);
            buildBaseData.SetBuildPosition(centerPostion);
            buildBaseData.SetBuildRule(itemRule);
            buildBaseData.SetBuildType(BuildTypeEnum.Building);

            buildBase.SetBuilBaseData(buildBaseData);
            objBuild.transform.position = centerPostion;

            BuildHandler.Instance.manager.AddBuildBase(buildBase);
            buildBase.AutoCheckBuildRule();
            BuildRuleEnumTool.GetBuildRuleData(itemRule, out int number, out bool up, out bool down, out bool left, out bool right, out bool before, out bool after);
            if (up)
            {
                CreateBuildItem(centerPostion + new Vector3(0, 1, 0));
            }
            if (down)
            {
                CreateBuildItem(centerPostion + new Vector3(0, -1, 0));
            }
            if (left)
            {
                CreateBuildItem(centerPostion + new Vector3(-1, 0, 0));
            }
            if (right)
            {
                CreateBuildItem(centerPostion + new Vector3(1, 0, 0));
            }
            if (before)
            {
                CreateBuildItem(centerPostion + new Vector3(0, 0, -1));
            }
            if (after)
            {
                CreateBuildItem(centerPostion + new Vector3(0, 0, 1));
            }
            buildBase.AutoCheckBuildRule();
        }
    }
示例#3
0
    /// <summary>
    /// 创建一个建筑
    /// </summary>
    /// <param name="buildPosition"></param>
    public T CreateBuildBase<T>(BuildTypeEnum buildType, Vector3 buildPosition) where T : BuildBase
    {
        BuildBase modelBuild = null;
        //设置建造数据
        BuildBaseBean buildBaseData = new BuildBaseBean();
        buildBaseData.SetBuildType(buildType);
        buildBaseData.SetBuildRule(BuildRuleEnum.Zero);
        buildBaseData.SetBuildPosition(buildPosition);
        //生成不同的模型
        switch (buildType)
        {
            case BuildTypeEnum.Building:
                modelBuild = modelForBuilding;
                break;
            case BuildTypeEnum.Foundation:
                modelBuild = modelForFoundation;
                break;
        }
        if (modelBuild == null)
            return null;
        GameObject objBuild = Instantiate(gameObject, modelBuild.gameObject, buildPosition);
        T cptBuild = objBuild.GetComponent<T>();
        cptBuild.SetBuilBaseData(buildBaseData);

        //增加数据
        GameDataHandler.Instance.manager.AddSceneListBuildData(buildBaseData);
        manager.AddBuildBase(cptBuild);
        //建筑动画
        AnimForBuild(buildType, cptBuild);

        //获取周围方块
        List<BuildBase> listAroundBuild = manager.GetAroundBuildBase(cptBuild);
        //改变周围方块状态
        for (int i = 0; i < listAroundBuild.Count; i++)
        {
            BuildBase itemBase = listAroundBuild[i];
            itemBase.AutoCheckBuildRule();
        }

        return cptBuild;
    }
示例#4
0
    protected void CreateBuildItem(Vector3 position)
    {
        GameObject objBuild = Instantiate(gameObject, modelBuilding.gameObject);

        BuildBase buildBase = objBuild.GetComponent <BuildBase>();

        BuildBaseBean buildBaseData = new BuildBaseBean();

        buildBaseData.SetBuildPosition(position);
        buildBaseData.SetBuildRule(BuildRuleEnum.Zero);
        buildBaseData.SetBuildType(BuildTypeEnum.Building);

        buildBase.SetBuilBaseData(buildBaseData);
        objBuild.transform.position = position;

        buildBase.AutoCheckBuildRule();

        Renderer[] rendererArrary = buildBase.GetComponentsInChildren <Renderer>();
        foreach (Renderer renderer in rendererArrary)
        {
            renderer.material.color = Color.black;
        }
        BuildHandler.Instance.manager.AddBuildBase(buildBase);
    }