コード例 #1
0
        /// <Summary>
        /// Returns a GameObject which is searched by position and map attribute ID.
        /// </Summary>
        /// <param name="eventPos">The position of event on the dungeon.</param>
        /// <param name="mapAttrId">The map attribute id.</param>
        protected GameObject GetEventObj(Vector2Int eventPos, int mapAttrId)
        {
            string     objNamePostfix = "_" + eventPos.x.ToString() + "-" + eventPos.y.ToString();
            string     attrName       = MapAttributeDefine.GetAttrNameById(mapAttrId);
            string     objName        = attrName + objNamePostfix;
            GameObject obj            = GameObject.Find(objName);

            return(obj);
        }
コード例 #2
0
ファイル: DrawDungeonWall.cs プロジェクト: lavumi/DungeonRPG
        /// <Summary>
        /// Instantiate dungeon walls and objects according to map attribute.
        /// </Summary>
        void DrawWalls()
        {
            Vector3 basePos = Vector3.zero;

            GameObject groundPrefab = dungeonParts.groundObj;
            Vector3    groundSize   = new Vector3(groundPrefab.transform.localScale.x, groundPrefab.transform.localScale.y, groundPrefab.transform.localScale.z);

            GameObject wallPrefab = dungeonParts.wallObj;
            Vector3    unitSize   = new Vector3(wallPrefab.transform.localScale.x, wallPrefab.transform.localScale.y, wallPrefab.transform.localScale.z);
            float      height     = (groundSize.y + unitSize.y) / 2;

            Direction direction = new Direction();

            // Instanciate parts on X-Z plane
            for (int zAxis = 0; zAxis < currentFloorMapData.floorSizeVertical; zAxis++)
            {
                for (int xAxis = 0; xAxis < currentFloorMapData.floorSizeHorizontal; xAxis++)
                {
                    int     index           = xAxis + zAxis * currentFloorMapData.floorSizeHorizontal;
                    int     mapAttrData     = currentFloorMapData.mapInfo[index].mapAttr;
                    int     messengerTypeId = currentFloorMapData.mapInfo[index].messengerType;
                    Vector3 posInLoop       = new Vector3(basePos.x + xAxis * unitSize.x, basePos.y + height, basePos.z + zAxis * unitSize.z);
                    string  objName         = MapAttributeDefine.GetAttrNameById(mapAttrData) + "_" + xAxis.ToString() + "-" + zAxis.ToString();
                    Vector3 rotation        = direction.GetRotationOfDirection(currentFloorMapData.mapInfo[index].objectFront);
                    InstantiateWall(mapAttrData, posInLoop, objName, rotation, messengerTypeId, index);
                }
            }

            // Instanciate outside walls
            if (isDrawOutsideWall)
            {
                // Horizontal walls - South
                string  outsideObjName     = "OutsideWall_South_Horizontal";
                Vector3 scale              = new Vector3(unitSize.x * (currentFloorMapData.floorSizeHorizontal + outsideWallSize * 2), unitSize.y, unitSize.z * outsideWallSize);
                float   outSideWallOffsetX = (1 + outsideWallSize) * 0.5f * unitSize.x;
                float   outSideWallOffsetZ = (1 + outsideWallSize) * 0.5f * unitSize.z;
                Vector3 baseOffset         = new Vector3(unitSize.x / 2, 0f, unitSize.z / 2);
                float   posX = baseOffset.x + scale.x / 2 - outSideWallOffsetX * 2;
                float   posZ = -1 * outSideWallOffsetZ;
                Vector3 pos  = new Vector3(posX, height, posZ);
                InstantiateOutsideWalls(pos, scale, outsideObjName);

                // Horizontal walls - North
                outsideObjName = "OutsideWall_North_Horizontal";
                posZ           = (currentFloorMapData.floorSizeVertical - 1) * unitSize.z + outSideWallOffsetZ;
                pos            = new Vector3(posX, height, posZ);
                InstantiateOutsideWalls(pos, scale, outsideObjName);

                // Vertical walls - West
                outsideObjName = "OutsideWall_West_Vertial";
                scale          = new Vector3(unitSize.x * outsideWallSize, unitSize.y, unitSize.z * currentFloorMapData.floorSizeVertical);
                posX           = -1 * outSideWallOffsetX;
                posZ           = baseOffset.z + (scale.z + outsideWallSize * 2 * unitSize.z) / 2 - outSideWallOffsetZ * 2;
                pos            = new Vector3(posX, height, posZ);
                InstantiateOutsideWalls(pos, scale, outsideObjName);

                // Vertical walls - East
                outsideObjName = "OutsideWall_East_Vertial";
                posX           = (currentFloorMapData.floorSizeHorizontal - 1) * unitSize.x + outSideWallOffsetX;
                pos            = new Vector3(posX, height, posZ);
                InstantiateOutsideWalls(pos, scale, outsideObjName);
            }
        }