Exemple #1
0
        /// <summary>
        /// 创建的时候,父区块知道是否要创建子区块s
        /// </summary>
        public void Create()
        {
            if (unitLevel == 0)
            {
                RenderUnit(false);
            }
            else
            {
                // 获得子区块的基础数据
                WorldUnitVo childUnitVo = WorldManager.GetInstance().GetChildWorldUnitVoByParentLevel(this.unitLevel);

                // 计算横向纵向各有多少个子区块
                int horChildUnitCount = unit_width_count / childUnitVo.unit_count_width;
                int verChildUnitCount = unit_height_count / childUnitVo.unit_count_height;

                float childUnitWidth  = childUnitVo.unit_count_width * originWorldUnitSize;
                float childUnitHeight = childUnitVo.unit_count_height * originWorldUnitSize;

                float startChildPos_x = realPos_x - (unit_width / 2) + childUnitWidth / 2;
                float startChildPos_y = realPos_y + (unit_height / 2) - childUnitHeight / 2;


                // 一行一行地去创建子区块
                for (int verIndex = 0; verIndex < verChildUnitCount; ++verIndex)
                {
                    for (int horIndex = 0; horIndex < horChildUnitCount; ++horIndex)
                    {
                        WorldUnit childUnit = new WorldUnit();
                        childUnit.unitLevel         = childUnitVo.level;
                        childUnit.unit_width_count  = childUnitVo.unit_count_width;
                        childUnit.unit_height_count = childUnitVo.unit_count_height;
                        childUnit.realPos_x         = startChildPos_x + horIndex * childUnitWidth;
                        childUnit.realPos_y         = startChildPos_y - verIndex * childUnitHeight;
                        unExplorUnits.Add(childUnit);
                        childWorldUnits.Add(childUnit);
                    }
                }

                // 调用子区块的Create方法

                for (int unitIndex = 0; unitIndex < childWorldUnits.Count; ++unitIndex)
                {
                    childWorldUnits [unitIndex].Create();
                }
            }
        }
Exemple #2
0
    public void CreateTopLevel (int topLevelIndexPosX, int topLevelIndexPosY)
    {
        WorldUnit unit = new WorldUnit ();
        unit.unitLevel = 3;
        unit.unit_width_count = 30;
        unit.unit_height_count = 30;
        unit.realPos_x = topLevelIndexPosX * unit.unit_width;
        unit.realPos_y = topLevelIndexPosY * unit.unit_height;
        unit.topLevelIndexPosX = topLevelIndexPosX;
        unit.topLevelIndexPosY = topLevelIndexPosY;

        unit.Create (); 

        topLevelWorldUnits.Add (unit); 
    }
Exemple #3
0
    // 当进入某一个顶层区块时,就要相应地创建它的相邻顶层区块,
    private void CheckAndCreateNeighborTopLevelWorldUnit (WorldUnit currTopUnit)
    {
        // top Neighbor
        int neighborIndexPosX = currTopUnit.topLevelIndexPosX;
        int neighborIndexPosY = currTopUnit.topLevelIndexPosY + 1;

        if (!IsTopWorldUnitExist (neighborIndexPosX, neighborIndexPosY))
        {
            CreateTopLevel (neighborIndexPosX, neighborIndexPosY);
        }
       

        // down Neighbor
        neighborIndexPosX = currTopUnit.topLevelIndexPosX;
        neighborIndexPosY = currTopUnit.topLevelIndexPosY - 1;
        if (!IsTopWorldUnitExist (neighborIndexPosX, neighborIndexPosY))
        {
            CreateTopLevel (neighborIndexPosX, neighborIndexPosY);
        }

        // left Neighbor
        neighborIndexPosX = currTopUnit.topLevelIndexPosX - 1;
        neighborIndexPosY = currTopUnit.topLevelIndexPosY;
        if (!IsTopWorldUnitExist (neighborIndexPosX, neighborIndexPosY))
        {
            CreateTopLevel (neighborIndexPosX, neighborIndexPosY);
        }

        // right neighbor
        neighborIndexPosX = currTopUnit.topLevelIndexPosX + 1;
        neighborIndexPosY = currTopUnit.topLevelIndexPosY;
        if (!IsTopWorldUnitExist (neighborIndexPosX, neighborIndexPosY))
        {
            CreateTopLevel (neighborIndexPosX, neighborIndexPosY);
        }

        // left top
        neighborIndexPosX = currTopUnit.topLevelIndexPosX - 1;
        neighborIndexPosY = currTopUnit.topLevelIndexPosY + 1;
        if (!IsTopWorldUnitExist (neighborIndexPosX, neighborIndexPosY))
        {
            CreateTopLevel (neighborIndexPosX, neighborIndexPosY);
        }

        // left down
        neighborIndexPosX = currTopUnit.topLevelIndexPosX - 1;
        neighborIndexPosY = currTopUnit.topLevelIndexPosY - 1;
        if (!IsTopWorldUnitExist (neighborIndexPosX, neighborIndexPosY))
        {
            CreateTopLevel (neighborIndexPosX, neighborIndexPosY);
        }

        // right top
        neighborIndexPosX = currTopUnit.topLevelIndexPosX + 1;
        neighborIndexPosY = currTopUnit.topLevelIndexPosY + 1;
        if (!IsTopWorldUnitExist (neighborIndexPosX, neighborIndexPosY))
        {
            CreateTopLevel (neighborIndexPosX, neighborIndexPosY);
        }

        // right down
        neighborIndexPosX = currTopUnit.topLevelIndexPosX + 1;
        neighborIndexPosY = currTopUnit.topLevelIndexPosY - 1;
        if (!IsTopWorldUnitExist (neighborIndexPosX, neighborIndexPosY))
        {
            CreateTopLevel (neighborIndexPosX, neighborIndexPosY);
        }

    }
Exemple #4
0
        /// <summary>
        /// 创建的时候,父区块知道是否要创建子区块s 
        /// </summary>
        public void Create ()
        {
            if (unitLevel == 0)
            {
                RenderUnit (false);
            }
            else
            {
                // 获得子区块的基础数据
                WorldUnitVo childUnitVo = WorldManager.GetInstance ().GetChildWorldUnitVoByParentLevel (this.unitLevel);

                // 计算横向纵向各有多少个子区块
                int horChildUnitCount = unit_width_count / childUnitVo.unit_count_width;
                int verChildUnitCount = unit_height_count / childUnitVo.unit_count_height;

                float childUnitWidth = childUnitVo.unit_count_width * originWorldUnitSize;
                float childUnitHeight = childUnitVo.unit_count_height * originWorldUnitSize;

                float startChildPos_x = realPos_x - (unit_width / 2) + childUnitWidth / 2;
                float startChildPos_y = realPos_y + (unit_height / 2) - childUnitHeight / 2;


                // 一行一行地去创建子区块
                for (int verIndex = 0; verIndex < verChildUnitCount; ++verIndex)
                {
                    for (int horIndex = 0; horIndex < horChildUnitCount; ++horIndex)
                    {
                        WorldUnit childUnit = new WorldUnit ();
                        childUnit.unitLevel = childUnitVo.level;
                        childUnit.unit_width_count = childUnitVo.unit_count_width;
                        childUnit.unit_height_count = childUnitVo.unit_count_height;
                        childUnit.realPos_x = startChildPos_x + horIndex * childUnitWidth;
                        childUnit.realPos_y = startChildPos_y - verIndex * childUnitHeight;
                        unExplorUnits.Add (childUnit);
                        childWorldUnits.Add (childUnit);
                    }
                }

                // 调用子区块的Create方法

                for (int unitIndex = 0; unitIndex < childWorldUnits.Count; ++unitIndex)
                {
                    childWorldUnits [unitIndex].Create ();
                }

            }

        }