<NME> TileMapRenderer.cs <BEF> ﻿using UnityEngine; using System.Collections; public class TileMapRenderer : Loader{ const int TILE_SOLID= 0; const int TILE_OPEN= 1; //Note the order of these 4 tiles are actually different in SHOCK. I swap them around in BuildTileMapShock for consistancy //Note the order of these 4 tiles are actually different in SHOCK. I swap them around in BuildTileMapShock for consistancy const int TILE_DIAG_SE = 2; const int TILE_DIAG_SW = 3; const int TILE_SLOPE_N =6; const int TILE_SLOPE_S =7; const int TILE_SLOPE_E =8; const int TILE_SLOPE_W =9; const int TILE_VALLEY_NW =10; const int TILE_VALLEY_NE= 11; const int TILE_VALLEY_SE =12; const int TILE_VALLEY_SW= 13; const int TILE_RIDGE_SE= 14; const int TILE_RIDGE_SW= 15; const int TILE_RIDGE_NW= 16; const int TILE_RIDGE_NE =17; const int SLOPE_BOTH_PARALLEL= 0; const int SLOPE_BOTH_OPPOSITE= 1; const int SLOPE_FLOOR_ONLY =2; const int SLOPE_CEILING_ONLY= 3; //Visible faces indices const int vTOP =0; //Visible faces indices const int vTOP = 0; const int vEAST = 1; const int vNORTH= 4; const int vSOUTH= 5; public const int LayerFloor=0; public const int LayerCeil=1; //BrushFaces const int fCEIL = 64; const int fNORTH = 32; const int fSOUTH = 16; const int fEAST = 8; const int fWEST = 4; const int fTOP = 2; const int fBOTTOM = 1; //Door headings const int NORTH = 180; const int SOUTH = 0; const int EAST = 270; const int WEST = 90; public static bool EnableCollision = true; //static int UW_CEILING_HEIGHT; static int CEILING_HEIGHT; const int CEIL_ADJ = 0; const int CEIL_ADJ =0; const int FLOOR_ADJ =0;//-2; public static void GenerateLevelFromTileMap(GameObject parent, GameObject sceneryParent, string game, TileMap Level, ObjectLoader objList, bool UpdateOnly) { //UW_CEILING_HEIGHT=Level.UW_CEILING_HEIGHT; CEILING_HEIGHT=Level.CEILING_HEIGHT; bool skipCeil=true; if (game==GAME_SHOCK) { skipCeil=false; } if (!UpdateOnly) //Clear out the children in the transform foreach (Transform child in parent.transform) { GameObject.Destroy(child.gameObject); } foreach (Transform child in sceneryParent.transform) { GameObject.Destroy(child.gameObject); } } for (int y = 0; y <= TileMap.TileMapSizeY; y++) { for (int x = 0; x <= TileMap.TileMapSizeX; x++) { if ( ( (UpdateOnly) && (Level.Tiles[x, y].NeedsReRender) ) || ( !UpdateOnly ) ) { RenderTile(parent, x, y, Level.Tiles[x, y], false, false, false, skipCeil); if (game != GAME_SHOCK) {//Water RenderTile(parent, x, y, Level.Tiles[x, y], true, false, false, skipCeil); Level.Tiles[x, y].NeedsReRender = false; } } Level.Tiles[x, y].NeedsReRender = false; } } //Do a ceiling if (game != GAME_SHOCK) { if (!UpdateOnly) { GameObject output = RenderCeiling(parent, 0, 0, CEILING_HEIGHT, CEILING_HEIGHT + CEIL_ADJ,Level.UWCeilingTexture, "CEILING"); } } if (!UpdateOnly) { //Render bridges, pillars and door ways switch (_RES) { case GAME_SHOCK: break; default: RenderPillars(sceneryParent, Level, objList); RenderDoorways(sceneryParent, Level, objList); break; } } if ((GameWorldController.EditorMode) && (UpdateOnly)) { UWHUD.instance.editor.RefreshTileMap(); } } /// <summary> /// Renders the doorways. /// </summary> /// <param name="Parent">Parent.</param> /// <param name="level">Level.</param> /// <param name="objList">Object list.</param> public static void RenderDoorways(GameObject Parent, TileMap level, ObjectLoader objList) tmp.tileY = y; if ((x != TileMap.ObjectStorageTile) || (y != TileMap.ObjectStorageTile)) { tmp.tileType = 0; } else { tmp.tileType = 1; } RenderTile(sceneryParent, x, y, tmp, false, false, false, false); } RenderDoor(Parent, level, objList, i); } } if (!UpdateOnly) { //Render bridges, pillars and door ways switch (_RES) { /// </summary> /// <param name="Parent"></param> /// <param name="level"></param> /// <param name="objList"></param> /// <param name="i"></param> public static void RenderDoor(GameObject Parent, TileMap level, ObjectLoader objList, int i) { if ((objList.objInfo[i].ObjectTileX>=64) || (objList.objInfo[i].ObjectTileY >= 64)) {//door is off map! } } public static void RenderDoorways(GameObject Parent, TileMap level, ObjectLoader objList) { if (objList==null) } RenderDoorwayFront(Parent, level, objList, objList.objInfo[i], floorheight); RenderDoorwayRear(Parent, level, objList, objList.objInfo[i], floorheight); } } /// <summary> /// Renders the doorway frame from the rear /// </summary> /// <param name="Parent">Parent.</param> /// <param name="level">Level.</param> } public static void RenderDoorwayRear(GameObject Parent, TileMap level, ObjectLoader objList, ObjectLoaderInfo currDoor) { Material[] MatsToUse = new Material[1]; for (int j = 0; j<=MatsToUse.GetUpperBound(0);j++) { MatsToUse[j]= GameWorldController.instance.MaterialMasterList[ GameWorldController.instance.currentTileMap().texture_map[GameWorldController.instance.currentTileMap().Tiles[currDoor.tileX,currDoor.tileY].wallTexture]]; } float floorheight =(float) level.Tiles[currDoor.tileX,currDoor.tileY].floorHeight * 0.15f; //float doorthickness = 0.1f; float doorwidth = 0.8f; float doorframewidth = 1.2f; float doorSideWidth = (doorframewidth-doorwidth)/2f; float doorheight = 7f * 0.15f; //Uv ratios across the x axis of the door float uvXPos1 = 0f; { case EAST: case WEST: position = new Vector3(position.x - 0.02f, 0f, currDoor.ObjectTileY * 1.2f + 1.2f / 2f); break; case NORTH: case SOUTH: position = new Vector3(currDoor.ObjectTileX * 1.2f + 1.2f / 2f, 0f, position.z - 0.02f); break; } //float y0 = 0f;//+doorthickness /2f; float y1 = 0f;//-doorthickness /2f; float x0 = -doorframewidth / 2f; float x1 = +doorframewidth / 2f; float z0 = 0f; float z1 = CEILING_HEIGHT * 0.15f; //My vertex tris Vector3[] leftHand = new Vector3[4]; switch (currDoor.heading * 45) { case EAST: case WEST: //Swap x and y leftHand[0] = new Vector3(y1, x0, z0); leftHand[1] = new Vector3(y1, x0, z1); leftHand[2] = new Vector3(y1, x0 + doorSideWidth, z1); leftHand[3] = new Vector3(y1, x0 + doorSideWidth, z0); break; case NORTH: case SOUTH: default: leftHand[0] = new Vector3(x0, y1, z0); leftHand[1] = new Vector3(x0, y1, z1); leftHand[2] = new Vector3(x0 + doorSideWidth, y1, z1); leftHand[3] = new Vector3(x0 + doorSideWidth, y1, z0); break; } Vector2[] UVs = new Vector2[4]; UVs[0] = new Vector2(uvXPos1, 0f); UVs[1] = new Vector2(uvXPos1, 4); UVs[2] = new Vector2(uvXPos2, 4); UVs[3] = new Vector2(uvXPos2, 0f); GameObject tile = RenderCuboid(Parent, leftHand, UVs, position, MatsToUse, 1, "rear_leftside_" + ObjectLoader.UniqueObjectName(currDoor)); tile.transform.Rotate(new Vector3(0f, 0f, -180f)); //y0 = +doorthickness /2f; //y1 = -doorthickness /2f; x0 = -doorwidth / 2f; x1 = +doorwidth / 2f; z0 = 0f + floorHeight + doorheight; z1 = CEILING_HEIGHT * 0.15f; //1.2 Vector3[] overHead = new Vector3[4]; switch (currDoor.heading * 45) { case EAST: case WEST: //Swap x and y overHead[0] = new Vector3(y1, x0, z0); overHead[1] = new Vector3(y1, x0, z1); overHead[2] = new Vector3(y1, x1, z1); overHead[3] = new Vector3(y1, x1, z0); break; case NORTH: case SOUTH: default: overHead[0] = new Vector3(x0, y1, z0); overHead[1] = new Vector3(x0, y1, z1); overHead[2] = new Vector3(x1, y1, z1); overHead[3] = new Vector3(x1, y1, z0); break; } float dist = (z0) / 0.15f;//Get back to steps. dist = dist / 8f; //Vector2[] UVs = new Vector2[4]; UVs[0] = new Vector2(uvXPos2, dist); UVs[1] = new Vector2(uvXPos2, CEILING_HEIGHT / 8f); UVs[2] = new Vector2(uvXPos3, CEILING_HEIGHT / 8f); UVs[3] = new Vector2(uvXPos3, dist); tile = RenderCuboid(Parent, overHead, UVs, position, MatsToUse, 1, "rear_over_" + ObjectLoader.UniqueObjectName(currDoor)); tile.transform.Rotate(new Vector3(0f, 0f, -180f));//TODO:FIx for headings. if ((_RES == GAME_UW1) && (currDoor.ObjectTileX == 12) && (currDoor.ObjectTileY == 51) && (level.thisLevelNo == 3)) {//Special case for possible map bug tile.layer = LayerMask.NameToLayer("UWObjects"); } //y0 = +doorthickness /2f; //y1 = -doorthickness /2f; x0 = -doorframewidth / 2f; x1 = +doorframewidth / 2f; z0 = 0f; z1 = CEILING_HEIGHT * 0.15f; //My vertex tris Vector3[] rightHand = new Vector3[4]; switch (currDoor.heading * 45) { case EAST: case WEST: //Swap x and y rightHand[0] = new Vector3(y1, x0 + doorSideWidth + doorwidth, z0); rightHand[1] = new Vector3(y1, x0 + doorSideWidth + doorwidth, z1); rightHand[2] = new Vector3(y1, x0 + doorSideWidth + doorwidth + doorSideWidth, z1); rightHand[3] = new Vector3(y1, x0 + doorSideWidth + doorwidth + doorSideWidth, z0); break; case NORTH: case SOUTH: default: rightHand[0] = new Vector3(x0 + doorSideWidth + doorwidth, y1, z0); rightHand[1] = new Vector3(x0 + doorSideWidth + doorwidth, y1, z1); rightHand[2] = new Vector3(x0 + doorSideWidth + doorwidth + doorSideWidth, y1, z1); rightHand[3] = new Vector3(x0 + doorSideWidth + doorwidth + doorSideWidth, y1, z0); break; } UVs = new Vector2[4]; UVs[0] = new Vector2(uvXPos3, 0f); UVs[1] = new Vector2(uvXPos3, 4); UVs[2] = new Vector2(uvXPos4, 4); UVs[3] = new Vector2(uvXPos4, 0f); tile = RenderCuboid(Parent, rightHand, UVs, position, MatsToUse, 1, "rear_rightside_" + ObjectLoader.UniqueObjectName(currDoor)); tile.transform.Rotate(new Vector3(0f, 0f, -180f)); } /// <summary> /// Renders the doorway front portion /// </summary> /// <param name="Parent">Parent.</param> /// <param name="level">Level.</param> /// <param name="objList">Object list.</param> } public static void RenderDoorwayFront(GameObject Parent, TileMap level, ObjectLoader objList, ObjectLoaderInfo currDoor) { /* int BridgeIndex = ObjectLoader.findObjectByTypeInTile(objList.objInfo, currDoor.tileX, currDoor.tileY, ObjectInteraction.BRIDGE); if (BridgeIndex!=-1) { floorheight = ObjectLoader.CalcObjectXYZ(_RES, level, level.Tiles, objList.objInfo, BridgeIndex, currDoor.tileX,currDoor.tileY,0).y; } //Door params float floorheight =(float) level.Tiles[currDoor.tileX,currDoor.tileY].floorHeight * 0.15f; //float doorthickness = 0.2f; float doorwidth = 0.8f; float doorframewidth = 1.2f; float doorSideWidth = (doorframewidth-doorwidth)/2f; float doorheight = 7.0f * 0.15f ; //Uv ratios across the x axis of the door float uvXPos1 = 0f; float uvXPos3 = uvXPos2 + doorwidth / 1.2f; float uvXPos4 = 1f; // or 1.2f/1.2f //Vector3 doorposition; //positions Vector3 position = ObjectLoader.CalcObjectXYZ(currDoor.index, 0); //doorposition=position; //center in the tile and at the bottom of the map. switch (currDoor.heading * 45) { case EAST: case WEST: position = new Vector3(position.x + 0.02f, 0f, currDoor.ObjectTileY * 1.2f + 1.2f / 2f); break; case NORTH: case SOUTH: position = new Vector3(currDoor.ObjectTileX * 1.2f + 1.2f / 2f, 0f, position.z + 0.02f); break; break; } float y0 = 0f;//+doorthickness /2f; //float y1 = 0f;//-doorthickness /2f; float x0 = -doorframewidth /2f; float z0 = 0f; float z1 = CEILING_HEIGHT * 0.15f; //My vertex tris Vector3[] leftHand = new Vector3[4]; switch (currDoor.heading * 45) { case EAST: case WEST: //Swap x and y leftHand[0] = new Vector3(y0, x0, z0); leftHand[1] = new Vector3(y0, x0, z1); leftHand[2] = new Vector3(y0, x0 + doorSideWidth, z1); leftHand[3] = new Vector3(y0, x0 + doorSideWidth, z0); break; case NORTH: case SOUTH: default: leftHand[0] = new Vector3(x0, y0, z0); leftHand[1] = new Vector3(x0, y0, z1); leftHand[2] = new Vector3(x0 + doorSideWidth, y0, z1); leftHand[3] = new Vector3(x0 + doorSideWidth, y0, z0); break; } Vector2[] UVs = new Vector2[4]; //UVs[0]= new Vector2(0f,0f); //UVs[1]= new Vector2(0f,4); //UVs[2]= new Vector2(doorSideWidth,4); //UVs[3]= new Vector2(doorSideWidth,0f); UVs[0] = new Vector2(uvXPos1, 0f); UVs[1] = new Vector2(uvXPos1, 4); UVs[2] = new Vector2(uvXPos2, 4); UVs[3] = new Vector2(uvXPos2, 0f); RenderCuboid(Parent, leftHand, UVs, position, MatsToUse, 1, "front_leftside_" + ObjectLoader.UniqueObjectName(currDoor)); //y0 = +doorthickness /2f; //y1 = -doorthickness /2f; x0 = -doorwidth / 2f; x1 = +doorwidth / 2f; z0 = 0f + floorHeight + doorheight; z1 = CEILING_HEIGHT * 0.15f; //1.2 //1.2 Vector3[] overHead = new Vector3[4]; switch (currDoor.heading*45) { case EAST: overHead[0] = new Vector3(y0, x0, z0); overHead[1] = new Vector3(y0, x0, z1); overHead[2] = new Vector3(y0, x1, z1); overHead[3] = new Vector3(y0, x1, z0); break; case NORTH: case SOUTH: default: overHead[0] = new Vector3(x0, y0, z0); overHead[1] = new Vector3(x0, y0, z1); overHead[2] = new Vector3(x1, y0, z1); overHead[3] = new Vector3(x1, y0, z0); break; } float dist = (z0) / 0.15f;//Get back to steps. dist = dist / 8f; //Vector2[] UVs = new Vector2[4]; //UVs[0]= new Vector2(0+doorSideWidth, dist); //UVs[1]= new Vector2(0+doorSideWidth, CEILING_HEIGHT/8f); //UVs[2]= new Vector2(doorwidth-doorSideWidth, CEILING_HEIGHT/8f); //UVs[3]= new Vector2(doorwidth-doorSideWidth, dist); UVs[0] = new Vector2(uvXPos2, dist); UVs[1] = new Vector2(uvXPos2, CEILING_HEIGHT / 8f); UVs[2] = new Vector2(uvXPos3, CEILING_HEIGHT / 8f); UVs[3] = new Vector2(uvXPos3, dist); GameObject tile = RenderCuboid(Parent, overHead, UVs, position, MatsToUse, 1, "front_over_" + ObjectLoader.UniqueObjectName(currDoor)); if ((_RES == GAME_UW1) && (currDoor.ObjectTileX == 12) && (currDoor.ObjectTileY == 51) && (level.thisLevelNo == 3)) {//Special case for possible map bug tile.layer = LayerMask.NameToLayer("UWObjects"); } //y0 = +doorthickness /2f; //y1 = -doorthickness /2f; x0 = -doorframewidth / 2f; x1 = +doorframewidth / 2f; z0 = 0f; z1 = CEILING_HEIGHT * 0.15f; //My vertex tris Vector3[] rightHand = new Vector3[4]; switch (currDoor.heading * 45) { case EAST: case WEST: //Swap x and y rightHand[0] = new Vector3(y0, x0 + doorSideWidth + doorwidth, z0); rightHand[1] = new Vector3(y0, x0 + doorSideWidth + doorwidth, z1); rightHand[2] = new Vector3(y0, x0 + doorSideWidth + doorwidth + doorSideWidth, z1); rightHand[3] = new Vector3(y0, x0 + doorSideWidth + doorwidth + doorSideWidth, z0); break; case NORTH: case SOUTH: default: rightHand[0] = new Vector3(x0 + doorSideWidth + doorwidth, y0, z0); rightHand[1] = new Vector3(x0 + doorSideWidth + doorwidth, y0, z1); rightHand[2] = new Vector3(x0 + doorSideWidth + doorwidth + doorSideWidth, y0, z1); rightHand[3] = new Vector3(x0 + doorSideWidth + doorwidth + doorSideWidth, y0, z0); break; } UVs = new Vector2[4]; //UVs[0]= new Vector2(doorSideWidth + doorwidth,0f); //UVs[1]= new Vector2(doorSideWidth + doorwidth,4); //UVs[2]= new Vector2(doorSideWidth + doorwidth + doorSideWidth,4); //UVs[3]= new Vector2(doorSideWidth + doorwidth + doorSideWidth,0f); UVs[0] = new Vector2(uvXPos3, 0f); UVs[1] = new Vector2(uvXPos3, 4); UVs[2] = new Vector2(uvXPos4, 4); UVs[3] = new Vector2(uvXPos4, 0f); RenderCuboid(Parent, rightHand, UVs, position, MatsToUse, 1, "front_rightside_" + ObjectLoader.UniqueObjectName(currDoor)); //Some filler Vector3[] filler = new Vector3[12]; int v = 0; position = new Vector3(position.x, floorHeight, position.z); UVs = new Vector2[12]; UVs[0] = new Vector2(0, 0f); UVs[1] = new Vector2(0, 1); UVs[2] = new Vector2(1, 1); UVs[3] = new Vector2(1, 0f); UVs[4] = new Vector2(0, 0f); UVs[5] = new Vector2(0, 1); UVs[6] = new Vector2(1, 1); UVs[7] = new Vector2(1, 0f); UVs[8] = new Vector2(0, 0f); UVs[9] = new Vector2(0, 1); UVs[10] = new Vector2(1, 1); UVs[11] = new Vector2(1, 0f); switch (currDoor.heading * 45) { case EAST: case WEST: //Swap x and y //side v = 0; filler[v++] = new Vector3(0.04f, -doorwidth / 2, doorheight); filler[v++] = new Vector3(0.04f, -doorwidth / 2, 0f); filler[v++] = new Vector3(-0.00f, -doorwidth / 2, 0f); filler[v++] = new Vector3(-0.00f, -doorwidth / 2, doorheight); RenderCuboid(Parent, filler, UVs, position, MatsToUse, 1, "side1_filler_" + ObjectLoader.UniqueObjectName(currDoor)); //over v = 0; filler[v++] = new Vector3(0.00f, +doorwidth / 2, doorheight); filler[v++] = new Vector3(0.04f, +doorwidth / 2, doorheight); filler[v++] = new Vector3(0.04f, -doorwidth / 2, doorheight); filler[v++] = new Vector3(0.00f, -doorwidth / 2, doorheight); GameObject fillerpiece = RenderCuboid(Parent, filler, UVs, position, MatsToUse, 1, "over_filler_" + ObjectLoader.UniqueObjectName(currDoor)); if ((_RES == GAME_UW1) && (currDoor.ObjectTileX == 12) && (currDoor.ObjectTileY == 51) && (level.thisLevelNo == 3)) {//Special case for possible map bug fillerpiece.layer = LayerMask.NameToLayer("UWObjects"); } v = 0; //side filler[v++] = new Vector3(0.04f, +doorwidth / 2, 0f); filler[v++] = new Vector3(0.04f, +doorwidth / 2, doorheight); filler[v++] = new Vector3(0.00f, +doorwidth / 2, doorheight); filler[v++] = new Vector3(0.00f, +doorwidth / 2, 0f); RenderCuboid(Parent, filler, UVs, position, MatsToUse, 1, "side2_filler_" + ObjectLoader.UniqueObjectName(currDoor)); break; case NORTH: case SOUTH: default: //side v = 0; filler[v++] = new Vector3(-doorwidth / 2, 0.00f, 0f); filler[v++] = new Vector3(-doorwidth / 2, 0.00f, doorheight); filler[v++] = new Vector3(-doorwidth / 2, -0.04f, doorheight); filler[v++] = new Vector3(-doorwidth / 2, -0.04f, 0f); RenderCuboid(Parent, filler, UVs, position, MatsToUse, 1, "side1_filler_" + ObjectLoader.UniqueObjectName(currDoor)); //over v = 0; filler[v++] = new Vector3(+doorwidth / 2, -0.00f, doorheight); filler[v++] = new Vector3(+doorwidth / 2, -0.04f, doorheight); filler[v++] = new Vector3(-doorwidth / 2, -0.04f, doorheight); filler[v++] = new Vector3(-doorwidth / 2, 0.00f, doorheight); GameObject fillerPiece = RenderCuboid(Parent, filler, UVs, position, MatsToUse, 1, "over_filler_" + ObjectLoader.UniqueObjectName(currDoor)); if ((_RES == GAME_UW1) && (currDoor.ObjectTileX == 12) && (currDoor.ObjectTileY == 51) && (level.thisLevelNo == 3)) {//Special case for possible map bug fillerPiece.layer = LayerMask.NameToLayer("UWObjects"); } v = 0; //side filler[v++] = new Vector3(+doorwidth / 2, 0.00f, doorheight); filler[v++] = new Vector3(+doorwidth / 2, 0.00f, 0f); filler[v++] = new Vector3(+doorwidth / 2, -0.04f, 0f); filler[v++] = new Vector3(+doorwidth / 2, -0.04f, doorheight); RenderCuboid(Parent, filler, UVs, position, MatsToUse, 1, "side2_filler_" + ObjectLoader.UniqueObjectName(currDoor)); break; } RenderCuboid(Parent, filler, UVs, position, MatsToUse, 3, "front_filler_" + ObjectLoader.UniqueObjectName(currDoor)); RenderCuboid(Parent,filler,UVs,position,MatsToUse,3,"front_filler_" + ObjectLoader.UniqueObjectName(currDoor)); } public static void RenderPillars(GameObject Parent, TileMap level, ObjectLoader objList) { if (objList==null) { return; } for (int i=0; i<=objList.objInfo.GetUpperBound(0);i++) { if ((objList.objInfo[i].item_id==352) && (objList.objInfo[i].InUseFlag==1)) { Vector3 position = objList.CalcObjectXYZ(_RES,level,level.Tiles,objList.objInfo,i,(int)objList.objInfo[i].tileX,(int)objList.objInfo[i].tileY,0); //position =new Vector3( objList.objInfo[i].tileX*1.2f + 1.2f / 2f,position.y, objList.objInfo[i].tileY*1.2f + 1.2f / 2f); //position =new Vector3( objList.objInfo[i].tileX*1.2f + 1.2f / 2f,position.y, objList.objInfo[i].tileY*1.2f + 1.2f / 2f); Vector3[] Verts = new Vector3[24]; Vector2[] UVs = new Vector2[24]; int t = 0; float x1 = 0.03f; float x0 = -0.03f; float y0 = -0.03f; float y1 = 0.03f; float z1 = (float)(CEILING_HEIGHT * 0.15f) - position.y; float z0 = -position.y; //x1 Verts[t++] = new Vector3(x0, y1, z0); Verts[t++] = new Vector3(x0, y1, z1); Verts[t++] = new Vector3(x1, y1, z1); Verts[t++] = new Vector3(x1, y1, z0); Verts[t++] = new Vector3(x1, y0, z0); Verts[t++] = new Vector3(x1, y0, z1); Verts[t++] = new Vector3(x0, y0, z1); Verts[t++] = new Vector3(x0, y0, z0); Verts[t++] = new Vector3(x1, y1, z0); Verts[t++] = new Vector3(x1, y1, z1); Verts[t++] = new Vector3(x1, y0, z1); Verts[t++] = new Vector3(x1, y0, z0); Verts[t++] = new Vector3(x0, y0, z0); Verts[t++] = new Vector3(x0, y1, z0); Verts[t++] = new Vector3(x1, y1, z0); Verts[t++] = new Vector3(x1, y0, z0); Verts[t++] = new Vector3(x0, y0, z0); Verts[t++] = new Vector3(x0, y0, z1); Verts[t++] = new Vector3(x0, y1, z1); Verts[t++] = new Vector3(x0, y1, z0); Verts[t++] = new Vector3(x1, y0, z1); Verts[t++] = new Vector3(x1, y1, z1); Verts[t++] = new Vector3(x0, y1, z1); Verts[t++] = new Vector3(x0, y0, z1); for (int j = 0; j < 6; j++) { UVs[(j * 4) + 0] = new Vector2(0f, 0f); UVs[(j * 4) + 1] = new Vector2(0f, CEILING_HEIGHT); UVs[(j * 4) + 2] = new Vector2(1f, CEILING_HEIGHT); UVs[(j * 4) + 3] = new Vector2(1f, 0f); } int TextureIndex = objList.objInfo[i].flags & 0x3;//& 0x3F; Material tmobj = (Material)Resources.Load(_RES + "/Materials/tmobj/tmobj_" + (TextureIndex).ToString("d2")); if (tmobj != null) { if (tmobj.mainTexture == null) {//UW1 style bridges UW2 has some differences.... tmobj.mainTexture = GameWorldController.instance.TmObjArt.LoadImageAt(TextureIndex); } Material[] MatsToUse = new Material[6]; for (int j = 0; j <= MatsToUse.GetUpperBound(0); j++) {//tmobj[30]+(objList[x].flags & 0x3F) MatsToUse[j] = tmobj;//GameWorldController.instance.MaterialMasterList[j]; } RenderCuboid(Parent, Verts, UVs, position, MatsToUse, 6, ObjectLoader.UniqueObjectName(objList.objInfo[i])); } { Debug.Log("RenderPillar: Missing material resource for tmobj/" + TextureIndex); return; } } } } public static void RenderBridges(GameObject Parent, TileMap level, ObjectLoader objList) { if (objList==null) { if (objList == null) } for (int i=0; i<=objList.objInfo.GetUpperBound(0);i++) { if ((objList.objInfo[i].item_id==356) && (objList.objInfo[i].InUseFlag==1)) { Vector3 position = objList.CalcObjectXYZ(_RES,level,level.Tiles,objList.objInfo,i,(int)objList.objInfo[i].tileX,(int)objList.objInfo[i].tileY,0); position =new Vector3( objList.objInfo[i].tileX*1.2f + 1.2f / 2f,position.y, objList.objInfo[i].tileY*1.2f + 1.2f / 2f); if ((objList.objInfo[i].GetItemType() == ObjectInteraction.BRIDGE) && (objList.objInfo[i].InUseFlag == 1) && (objList.objInfo[i].invis == 0)) { RenderBridge(Parent, level, objList, i); } } } } /// <summary> /// Renders a specifi bridge /// </summary> /// <param name="Parent"></param> /// <param name="level"></param> /// <param name="objList"></param> /// <param name="i"></param> /// <param name="TextureIndex">When -1 use default rules for texturing otherwise use the specified index</param> public static void RenderBridge(GameObject Parent, TileMap level, ObjectLoader objList, int i) { Vector3 position = ObjectLoader.CalcObjectXYZ(i, 0); position = new Vector3(objList.objInfo[i].ObjectTileX * 1.2f + 1.2f / 2f, position.y, objList.objInfo[i].ObjectTileY * 1.2f + 1.2f / 2f); Vector3[] Verts = new Vector3[24]; Vector2[] UVs = new Vector2[24]; int t = 0; float x1 = 0.6f; float x0 = -0.6f; float y0 = -0.6f; float y1 = 0.6f; float z1 = 0.075f; float z0 = -0.075f; //x1 Verts[t++] = new Vector3(x0, y1, z0); Verts[t++] = new Vector3(x0, y1, z1); Verts[t++] = new Vector3(x1, y1, z1); Verts[t++] = new Vector3(x1, y1, z0); Verts[t++] = new Vector3(x1, y0, z0); Verts[t++] = new Vector3(x1, y0, z1); Verts[t++] = new Vector3(x0, y0, z1); Verts[t++] = new Vector3(x0, y0, z0); Verts[t++] = new Vector3(x1, y1, z0); Verts[t++] = new Vector3(x1, y1, z1); Verts[t++] = new Vector3(x1, y0, z1); Verts[t++] = new Vector3(x1, y0, z0); Verts[t++] = new Vector3(x0, y0, z0); Verts[t++] = new Vector3(x0, y1, z0); Verts[t++] = new Vector3(x1, y1, z0); Verts[t++] = new Vector3(x1, y0, z0); Verts[t++] = new Vector3(x0, y0, z0); Verts[t++] = new Vector3(x0, y0, z1); Verts[t++] = new Vector3(x0, y1, z1); Verts[t++] = new Vector3(x0, y1, z0); Verts[t++] = new Vector3(x1, y0, z1); Verts[t++] = new Vector3(x1, y1, z1); Verts[t++] = new Vector3(x0, y1, z1); Verts[t++] = new Vector3(x0, y0, z1); for (int j = 0; j < 6; j++) { UVs[(j * 4) + 0] = new Vector2(0f, 0f); UVs[(j * 4) + 1] = new Vector2(0f, 1f); UVs[(j * 4) + 2] = new Vector2(1f, 1f); UVs[(j * 4) + 3] = new Vector2(1f, 0f); } Material tmobj; int TextureIndex = (objList.objInfo[i].enchantment << 3) | objList.objInfo[i].flags & 0x3F;//<--Is this correct. Flags is only 3 bits long! if (TextureIndex >= 2) { if (_RES == GAME_UW2) { TextureIndex = CurrentTileMap().texture_map[TextureIndex - 2]; } else } public static void RenderTile(GameObject parent, int x, int y, TileInfo t, bool Water, bool invert, bool skipFloor, bool skipCeil) { //Picks the tile to render based on tile type/flags. MatsToUse[j] = tmobj; } RenderCuboid(Parent, Verts, UVs, position, MatsToUse, 6, ObjectLoader.UniqueObjectName(objList.objInfo[i])); } /// <summary> /// Renders the a tile /// </summary> /// <param name="parent">Parent.</param> if ((skipCeil != true)) { RenderOpenTile( parent , x, y, t, Water, true); } //ceiling return; } case 2: {//diag se if (skipFloor != true) { RenderDiagSETile( parent , x, y, t, Water, false); }//floor if ((skipCeil != true)) { RenderDiagSETile( parent , x, y, t, Water, true); } return; } case 3: { //diag sw if (skipFloor != true) { RenderDiagSWTile( parent , x, y, t, Water, false); }//floor if ((skipCeil != true)) { RenderDiagSWTile( parent , x, y, t, Water, true); } return; } case 4: { //diag ne if (skipFloor != true) { RenderDiagNETile( parent , x, y, t, Water, invert); }//floor if ((skipCeil != true)) { RenderDiagNETile( parent , x, y, t, Water, true); } return; } case 5: {//diag nw if (skipFloor != true) { RenderDiagNWTile( parent , x, y, t, Water, invert); }//floor if ((skipCeil != true)) { RenderDiagNWTile( parent , x, y, t, Water, true); } case TILE_DIAG_SW: { //diag sw if (skipFloor != true) { RenderDiagSWTile(parent, x, y, t, Water, false); }//floor if ((skipCeil != true)) { RenderDiagSWTile(parent, x, y, t, Water, true); } return null; } case TILE_DIAG_NE: { //diag ne if (skipFloor != true) { RenderDiagNETile(parent, x, y, t, Water, invert); }//floor if ((skipCeil != true)) { RenderDiagNETile(parent, x, y, t, Water, true); } return null; } case TILE_DIAG_NW: {//diag nw if (skipFloor != true) { RenderDiagNWTile(parent, x, y, t, Water, invert); }//floor if ((skipCeil != true)) { RenderDiagNWTile(parent, x, y, t, Water, true); } return null; } case TILE_SLOPE_N: //6 {//slope n switch (t.shockSlopeFlag) { case SLOPE_BOTH_PARALLEL: { if (skipFloor != true) { RenderSlopeNTile(parent, x, y, t, Water, false); }//floor if ((skipCeil != true)) { RenderSlopeNTile(parent, x, y, t, Water, true); } break; } case SLOPE_BOTH_OPPOSITE: { if (skipFloor != true) { RenderSlopeNTile(parent, x, y, t, Water, false); }//floor if ((skipCeil != true)) { RenderSlopeSTile(parent, x, y, t, Water, true); } break; } case SLOPE_FLOOR_ONLY: { if (skipFloor != true) { RenderSlopeNTile(parent, x, y, t, Water, false); }//floor if ((skipCeil != true)) { RenderOpenTile(parent, x, y, t, Water, true); } //ceiling break; } case SLOPE_CEILING_ONLY: { if (skipFloor != true) { RenderOpenTile(parent, x, y, t, Water, false); } //floor RenderSlopeNTile(parent, x, y, t, Water, true); break; } } return null; } case TILE_SLOPE_S: //slope s 7 { switch (t.shockSlopeFlag) { case SLOPE_BOTH_PARALLEL: { if (skipFloor != true) { RenderSlopeSTile(parent, x, y, t, Water, false); } //floor RenderSlopeSTile(parent, x, y, t, Water, true); break; } case SLOPE_BOTH_OPPOSITE: { if (skipFloor != true) { RenderSlopeSTile(parent, x, y, t, Water, false); } //floor RenderSlopeNTile(parent, x, y, t, Water, true); break; } case SLOPE_FLOOR_ONLY: { if (skipFloor != true) { RenderSlopeSTile(parent, x, y, t, Water, false); } //floor if ((skipCeil != true)) { RenderOpenTile(parent, x, y, t, Water, true); } //ceiling break; } case SLOPE_CEILING_ONLY: { if (skipFloor != true) { RenderOpenTile(parent, x, y, t, Water, false); } //floor if ((skipCeil != true)) { RenderSlopeSTile(parent, x, y, t, Water, true); } break; } } return null; } case TILE_SLOPE_E: //slope e 8 { switch (t.shockSlopeFlag) { case SLOPE_BOTH_PARALLEL: { if (skipFloor != true) { RenderSlopeETile(parent, x, y, t, Water, false); }//floor RenderSlopeETile(parent, x, y, t, Water, true); break; } case SLOPE_BOTH_OPPOSITE: { if (skipFloor != true) { RenderSlopeETile(parent, x, y, t, Water, false); }//floor RenderSlopeWTile(parent, x, y, t, Water, true); break; } case SLOPE_FLOOR_ONLY: { if (skipFloor != true) { RenderSlopeETile(parent, x, y, t, Water, false); }//floor if ((skipCeil != true)) { RenderOpenTile(parent, x, y, t, Water, true); } //ceiling break; } case SLOPE_CEILING_ONLY: { if (skipFloor != true) { RenderOpenTile(parent, x, y, t, Water, false); } //floor if ((skipCeil != true)) { RenderSlopeETile(parent, x, y, t, Water, true); } break; } } return null; } case TILE_SLOPE_W: //9 { //slope w switch (t.shockSlopeFlag) { case SLOPE_BOTH_PARALLEL: { if (skipFloor != true) { RenderSlopeWTile(parent, x, y, t, Water, false); }//floor if ((skipCeil != true)) { RenderSlopeWTile(parent, x, y, t, Water, true); } break; } case SLOPE_BOTH_OPPOSITE: { if (skipFloor != true) { RenderSlopeWTile(parent, x, y, t, Water, false); }//floor if ((skipCeil != true)) { RenderSlopeETile(parent, x, y, t, Water, true); } break; } case SLOPE_FLOOR_ONLY: { if (skipFloor != true) { RenderSlopeWTile(parent, x, y, t, Water, false); }//floor if ((skipCeil != true)) { RenderOpenTile(parent, x, y, t, Water, true); } //ceiling break; } case SLOPE_CEILING_ONLY: { if (skipFloor != true) { RenderOpenTile(parent, x, y, t, Water, false); } //floor if ((skipCeil != true)) { RenderSlopeWTile(parent, x, y, t, Water, true); } break; } } return null; } case TILE_VALLEY_NW: { //valleyNw(a) switch (t.shockSlopeFlag) { case SLOPE_BOTH_PARALLEL: { if (skipFloor != true) { RenderValleyNWTile(parent, x, y, t, Water, false); }//floor if ((skipCeil != true)) { RenderRidgeNWTile(parent, x, y, t, Water, true); } break; } case SLOPE_BOTH_OPPOSITE: { if (skipFloor != true) { RenderValleyNWTile(parent, x, y, t, Water, false); }//floor if ((skipCeil != true)) { RenderValleySETile(parent, x, y, t, Water, true); } break; } case SLOPE_FLOOR_ONLY: { if (skipFloor != true) { RenderValleyNWTile(parent, x, y, t, Water, false); }//floor if ((skipCeil != true)) { RenderOpenTile(parent, x, y, t, Water, true); } //ceiling break; } case SLOPE_CEILING_ONLY: { if (skipFloor != true) { RenderOpenTile(parent, x, y, t, Water, false); } //floor if ((skipCeil != true)) { RenderRidgeNWTile(parent, x, y, t, Water, true); } break; } } return null; } case TILE_VALLEY_NE: { //valleyne(b) switch (t.shockSlopeFlag) { case SLOPE_BOTH_PARALLEL: { if (skipFloor != true) { RenderValleyNETile(parent, x, y, t, Water, false); }//floor if ((skipCeil != true)) { RenderRidgeNETile(parent, x, y, t, Water, true); } break; } case SLOPE_BOTH_OPPOSITE: { if (skipFloor != true) { RenderValleyNETile(parent, x, y, t, Water, false); }//floor if ((skipCeil != true)) { RenderValleySWTile(parent, x, y, t, Water, true); } break; } case SLOPE_FLOOR_ONLY: { if (skipFloor != true) { RenderValleyNETile(parent, x, y, t, Water, false); }//floor if ((skipCeil != true)) { RenderOpenTile(parent, x, y, t, Water, true); } //ceiling break; } case SLOPE_CEILING_ONLY: { if (skipFloor != true) { RenderOpenTile(parent, x, y, t, Water, false); }//floor if ((skipCeil != true)) { RenderRidgeNETile(parent, x, y, t, Water, true); } break; } } return null; } case TILE_VALLEY_SE: { //valleyse(c) switch (t.shockSlopeFlag) { case SLOPE_BOTH_PARALLEL: { if (skipFloor != true) { RenderValleySETile(parent, x, y, t, Water, false); }//floor if ((skipCeil != true)) { RenderRidgeSETile(parent, x, y, t, Water, true); } break; } case SLOPE_BOTH_OPPOSITE: { if (skipFloor != true) { RenderValleySETile(parent, x, y, t, Water, false); }//floor if ((skipCeil != true)) { RenderValleyNWTile(parent, x, y, t, Water, true); } break; } case SLOPE_FLOOR_ONLY: { if (skipFloor != true) { RenderValleySETile(parent, x, y, t, Water, false); }//floor if ((skipCeil != true)) { RenderOpenTile(parent, x, y, t, Water, true); } //ceiling break; } case SLOPE_CEILING_ONLY: { if (skipFloor != true) { RenderOpenTile(parent, x, y, t, Water, false); } //floor if ((skipCeil != true)) { RenderRidgeSETile(parent, x, y, t, Water, true); } break; } } return null; } case TILE_VALLEY_SW: { //valleysw(d) switch (t.shockSlopeFlag) { case SLOPE_BOTH_PARALLEL: { if (skipFloor != true) { RenderValleySWTile(parent, x, y, t, Water, false); }//floor if ((skipCeil != true)) { RenderRidgeSWTile(parent, x, y, t, Water, true); } break; } case SLOPE_BOTH_OPPOSITE: { if (skipFloor != true) { RenderValleySWTile(parent, x, y, t, Water, false); }//floor if ((skipCeil != true)) { RenderValleyNETile(parent, x, y, t, Water, true); } break; } case SLOPE_FLOOR_ONLY: { if (skipFloor != true) { RenderValleySWTile(parent, x, y, t, Water, false); }//floor if ((skipCeil != true)) { RenderOpenTile(parent, x, y, t, Water, true); } //ceiling break; } case SLOPE_CEILING_ONLY: { if (skipFloor != true) { RenderOpenTile(parent, x, y, t, Water, false); } //floor if ((skipCeil != true)) { RenderRidgeSWTile(parent, x, y, t, Water, true); } break; } } return null; } case TILE_RIDGE_SE: { //ridge se(f) switch (t.shockSlopeFlag) { case SLOPE_BOTH_PARALLEL: { if (skipFloor != true) { RenderRidgeSETile(parent, x, y, t, Water, false); }//floor if ((skipCeil != true)) { RenderValleySETile(parent, x, y, t, Water, true); } break; } case SLOPE_BOTH_OPPOSITE: { if (skipFloor != true) { RenderRidgeSETile(parent, x, y, t, Water, false); }//floor if ((skipCeil != true)) { RenderRidgeNWTile(parent, x, y, t, Water, true); } break; } case SLOPE_FLOOR_ONLY: { if (skipFloor != true) { RenderRidgeSETile(parent, x, y, t, Water, false); }//floor if ((skipCeil != true)) { RenderOpenTile(parent, x, y, t, Water, true); } //ceiling break; } case SLOPE_CEILING_ONLY: { if (skipFloor != true) { RenderOpenTile(parent, x, y, t, Water, false); }//floor if ((skipCeil != true)) { RenderValleySETile(parent, x, y, t, Water, true); } break; } } return null; } case TILE_RIDGE_SW: { //ridgesw(g) switch (t.shockSlopeFlag) { case SLOPE_BOTH_PARALLEL: { if (skipFloor != true) { RenderRidgeSWTile(parent, x, y, t, Water, false); }//floor if ((skipCeil != true)) { RenderValleySWTile(parent, x, y, t, Water, true); } break; } case SLOPE_BOTH_OPPOSITE: { if (skipFloor != true) { RenderRidgeSWTile(parent, x, y, t, Water, false); }//floor if ((skipCeil != true)) { RenderRidgeNETile(parent, x, y, t, Water, true); } break; } case SLOPE_FLOOR_ONLY: { if (skipFloor != true) { RenderRidgeSWTile(parent, x, y, t, Water, false); }//floor if ((skipCeil != true)) { RenderOpenTile(parent, x, y, t, Water, true); } //ceiling break; } case SLOPE_CEILING_ONLY: { if (skipFloor != true) { RenderOpenTile(parent, x, y, t, Water, false); } //floor if ((skipCeil != true)) { RenderValleySWTile(parent, x, y, t, Water, true); } break; } } return null; } case TILE_RIDGE_NW: { //ridgenw(h) switch (t.shockSlopeFlag) { case SLOPE_BOTH_PARALLEL: { if (skipFloor != true) { RenderRidgeNWTile(parent, x, y, t, Water, false); }//floor if ((skipCeil != true)) { RenderValleyNWTile(parent, x, y, t, Water, true); } break; } case SLOPE_BOTH_OPPOSITE: { if (skipFloor != true) { RenderRidgeNWTile(parent, x, y, t, Water, false); }//floor if ((skipCeil != true)) { RenderRidgeSETile(parent, x, y, t, Water, true); } break; } case SLOPE_FLOOR_ONLY: { if (skipFloor != true) { RenderRidgeNWTile(parent, x, y, t, Water, false); }//floor if ((skipCeil != true)) { RenderOpenTile(parent, x, y, t, Water, true); } //ceiling break; } case SLOPE_CEILING_ONLY: { if (skipFloor != true) { RenderOpenTile(parent, x, y, t, Water, false); } //floor if ((skipCeil != true)) { RenderValleyNWTile(parent, x, y, t, Water, true); } break; } } return null; } case TILE_RIDGE_NE: { //ridgene(i) switch (t.shockSlopeFlag) { case SLOPE_BOTH_PARALLEL: { if (skipFloor != true) { RenderRidgeNETile(parent, x, y, t, Water, false); }//floor if ((skipCeil != true)) { RenderValleyNETile(parent, x, y, t, Water, true); } break; } case SLOPE_BOTH_OPPOSITE: { } } static void RenderCuboid(GameObject parent, int x, int y, TileInfo t, bool Water, int Bottom, int Top, string TileName) { return null; } } return null; } /// <summary> /// Renders the a cuboid with no slopes /// </summary> /// <param name="parent">Parent.</param> /// <param name="x">The x coordinate.</param> /// <param name="y">The y coordinate.</param> /// <param name="t">T.</param> /// <param name="Water">If set to <c>true</c> water.</param> /// <param name="Bottom">Bottom.</param> /// <param name="Top">Top.</param> /// <param name="TileName">Tile name.</param> static GameObject RenderCuboid(GameObject parent, int x, int y, TileInfo t, bool Water, int Bottom, int Top, string TileName) { if (UWEBase.EditorMode) { if (t.tileType == TILE_SOLID) {//Make sure this is not the ceiling t.VisibleFaces[vTOP] = true; } } //Draw a cube with no slopes. int NumberOfVisibleFaces = 0; //Get the number of faces for (int i = 0; i < 6; i++) { if (t.VisibleFaces[i] == true) { NumberOfVisibleFaces++; } } //Allocate enough verticea and UVs for the faces Vector3[] verts = new Vector3[NumberOfVisibleFaces * 4]; Vector2[] uvs = new Vector2[NumberOfVisibleFaces * 4]; float floorHeight = (float)(Top * 0.15f); float baseHeight = (float)(Bottom * 0.15f); float dimX = t.DimX; float dimY = t.DimY; //Now create the mesh GameObject Tile = new GameObject(TileName); SetTileLayer(t, Tile); Tile.transform.parent = parent.transform; Tile.transform.position = new Vector3(x * 1.2f, 0.0f, y * 1.2f); Tile.transform.localRotation = Quaternion.Euler(0f, 0f, 0f); MeshFilter mf = Tile.AddComponent<MeshFilter>(); MeshRenderer mr = Tile.AddComponent<MeshRenderer>(); Mesh mesh = new Mesh(); mesh.subMeshCount = NumberOfVisibleFaces;//Should be no of visible faces Material[] MatsToUse = new Material[NumberOfVisibleFaces]; //Now allocate the visible faces to triangles. int FaceCounter = 0;//Tracks which number face we are now on. float PolySize = Top - Bottom; float uv0 = (float)(Bottom * 0.125f); float uv1 = (PolySize / 8.0f) + (uv0); float offset = 0f; for (int i = 0; i < 6; i++) { if (t.VisibleFaces[i] == true) { switch (i) { case vTOP: { //Set the verts MatsToUse[FaceCounter] = GameWorldController.instance.MaterialMasterList[FloorTexture(fSELF, t)]; if (_RES == GAME_UW1) if (GameWorldController.instance.LevelNo == 6) { if (t.floorTexture == 4) {//Special case for tybals floor //MatsToUse[FaceCounter]= (Material)Resources.Load(_RES+ "\\Materials\\Textures\\uw1_224_maze"); MatsToUse[FaceCounter] = GameWorldController.instance.SpecialMaterials[0]; } } if ((t.tileType == TILE_SOLID) && (UWEBase.EditorMode)) { MatsToUse[FaceCounter] = GameWorldController.instance.Jorge; } verts[0 + (4 * FaceCounter)] = new Vector3(0.0f, 0.0f, floorHeight); verts[1 + (4 * FaceCounter)] = new Vector3(0.0f, 1.2f * dimY, floorHeight); verts[2 + (4 * FaceCounter)] = new Vector3(-1.2f * dimX, 1.2f * dimY, floorHeight); verts[3 + (4 * FaceCounter)] = new Vector3(-1.2f * dimX, 0.0f, floorHeight); //Allocate UVs uvs[0 + (4 * FaceCounter)] = new Vector2(0.0f, 1.0f * dimY); uvs[1 + (4 * FaceCounter)] = new Vector2(0.0f, 0.0f); uvs[2 + (4 * FaceCounter)] = new Vector2(1.0f * dimX, 0.0f); uvs[3 + (4 * FaceCounter)] = new Vector2(1.0f * dimX, 1.0f * dimY); break; } case vNORTH: { //north wall vertices offset = CalcCeilOffset(fNORTH, t); MatsToUse[FaceCounter] = GameWorldController.instance.MaterialMasterList[WallTexture(fNORTH, t)]; verts[0 + (4 * FaceCounter)] = new Vector3(-1.2f * dimX, 1.2f * dimY, baseHeight); verts[1 + (4 * FaceCounter)] = new Vector3(-1.2f * dimX, 1.2f * dimY, floorHeight); verts[2 + (4 * FaceCounter)] = new Vector3(0f, 1.2f * dimY, floorHeight); verts[3 + (4 * FaceCounter)] = new Vector3(0f, 1.2f * dimY, baseHeight); uvs[0 + (4 * FaceCounter)] = new Vector2(0.0f, uv0 - offset); uvs[1 + (4 * FaceCounter)] = new Vector2(0.0f, uv1 - offset); uvs[2 + (4 * FaceCounter)] = new Vector2(dimX, uv1 - offset); uvs[3 + (4 * FaceCounter)] = new Vector2(dimX, uv0 - offset); break; } case vWEST: { //west wall vertices offset = CalcCeilOffset(fWEST, t); MatsToUse[FaceCounter] = GameWorldController.instance.MaterialMasterList[WallTexture(fWEST, t)]; verts[0 + (4 * FaceCounter)] = new Vector3(0f, 1.2f * dimY, baseHeight); verts[1 + (4 * FaceCounter)] = new Vector3(0f, 1.2f * dimY, floorHeight); verts[2 + (4 * FaceCounter)] = new Vector3(0f, 0f, floorHeight); verts[3 + (4 * FaceCounter)] = new Vector3(0f, 0f, baseHeight); uvs[0 + (4 * FaceCounter)] = new Vector2(0.0f, uv0 - offset); uvs[1 + (4 * FaceCounter)] = new Vector2(0.0f, uv1 - offset); uvs[2 + (4 * FaceCounter)] = new Vector2(dimY, uv1 - offset); uvs[3 + (4 * FaceCounter)] = new Vector2(dimY, uv0 - offset); break; } case vEAST: { //east wall vertices offset = CalcCeilOffset(fEAST, t); MatsToUse[FaceCounter] = GameWorldController.instance.MaterialMasterList[WallTexture(fEAST, t)]; verts[0 + (4 * FaceCounter)] = new Vector3(-1.2f * dimX, 0f, baseHeight); verts[1 + (4 * FaceCounter)] = new Vector3(-1.2f * dimX, 0f, floorHeight); verts[2 + (4 * FaceCounter)] = new Vector3(-1.2f * dimX, 1.2f * dimY, floorHeight); verts[3 + (4 * FaceCounter)] = new Vector3(-1.2f * dimX, 1.2f * dimY, baseHeight); uvs[0 + (4 * FaceCounter)] = new Vector2(0.0f, uv0 - offset); uvs[1 + (4 * FaceCounter)] = new Vector2(0.0f, uv1 - offset); uvs[2 + (4 * FaceCounter)] = new Vector2(dimY, uv1 - offset); uvs[3 + (4 * FaceCounter)] = new Vector2(dimY, uv0 - offset); break; } case vSOUTH: { offset = CalcCeilOffset(fSOUTH, t); MatsToUse[FaceCounter] = GameWorldController.instance.MaterialMasterList[WallTexture(fSOUTH, t)]; //south wall vertices verts[0 + (4 * FaceCounter)] = new Vector3(0f, 0f, baseHeight); verts[1 + (4 * FaceCounter)] = new Vector3(0f, 0f, floorHeight); verts[2 + (4 * FaceCounter)] = new Vector3(-1.2f * dimX, 0f, floorHeight); verts[3 + (4 * FaceCounter)] = new Vector3(-1.2f * dimX, 0f, baseHeight); uvs[0 + (4 * FaceCounter)] = new Vector2(0.0f, uv0 - offset); uvs[1 + (4 * FaceCounter)] = new Vector2(0.0f, uv1 - offset); uvs[2 + (4 * FaceCounter)] = new Vector2(dimX, uv1 - offset); uvs[3 + (4 * FaceCounter)] = new Vector2(dimX, uv0 - offset); break; } case vBOTTOM: { //bottom wall vertices MatsToUse[FaceCounter] = GameWorldController.instance.MaterialMasterList[FloorTexture(fCEIL, t)]; verts[0 + (4 * FaceCounter)] = new Vector3(0f, 1.2f * dimY, baseHeight); verts[1 + (4 * FaceCounter)] = new Vector3(0f, 0f, baseHeight); verts[2 + (4 * FaceCounter)] = new Vector3(-1.2f * dimX, 0f, baseHeight); verts[3 + (4 * FaceCounter)] = new Vector3(-1.2f * dimX, 1.2f * dimY, baseHeight); //Change default UVs uvs[0 + (4 * FaceCounter)] = new Vector2(0.0f, 0.0f); uvs[1 + (4 * FaceCounter)] = new Vector2(0.0f, 1.0f * dimY); uvs[2 + (4 * FaceCounter)] = new Vector2(dimX, 1.0f * dimY); uvs[3 + (4 * FaceCounter)] = new Vector2(dimX, 0.0f); break; } } FaceCounter++; } } //Apply the uvs and create my tris mesh.vertices = verts; mesh.uv = uvs; FaceCounter = 0; int[] tris = new int[6]; for (int i = 0; i < 6; i++) { if (t.VisibleFaces[i] == true) mc.sharedMesh=mesh; } static void RenderSlopedCuboidOld(GameObject parent, int x, int y, TileInfo t, bool Water, int Bottom, int Top, int SlopeDir, int Steepness, int Floor, string TileName) { //Draws a cube with sloped tops mesh.SetTriangles(tris, FaceCounter); FaceCounter++; } } mr.materials = MatsToUse;//mats; mesh.RecalculateNormals(); mesh.RecalculateBounds(); mf.mesh = mesh; if (EnableCollision) { MeshCollider mc = Tile.AddComponent<MeshCollider>(); mc.sharedMesh = null; mc.sharedMesh = mesh; } return Tile; } /// <summary> /// Renders the a cuboid with no slopes /// </summary> /// <param name="parent">Parent.</param> /// <param name="x">The x coordinate.</param> /// <param name="y">The y coordinate.</param> /// <param name="t">T.</param> /// <param name="Water">If set to <c>true</c> water.</param> /// <param name="Bottom">Bottom.</param> /// <param name="Top">Top.</param> /// <param name="TileName">Tile name.</param> static GameObject RenderCeiling(GameObject parent, int x, int y, int Bottom, int Top, int CeilingTexture, string TileName) { //Draw a cube with no slopes. int NumberOfVisibleFaces = 1; //Allocate enough verticea and UVs for the faces Vector3[] verts = new Vector3[NumberOfVisibleFaces * 4]; Vector2[] uvs = new Vector2[NumberOfVisibleFaces * 4]; float floorHeight = (float)(Top * 0.15f); float baseHeight = (float)(Bottom * 0.15f); //Now create the mesh GameObject Tile = new GameObject(TileName); Tile.layer = LayerMask.NameToLayer("MapMesh"); Tile.transform.parent = parent.transform; Tile.transform.position = new Vector3(x * 1.2f, 0.0f, y * 1.2f); Tile.transform.localRotation = Quaternion.Euler(0f, 0f, 0f); MeshFilter mf = Tile.AddComponent<MeshFilter>(); MeshRenderer mr = Tile.AddComponent<MeshRenderer>(); Mesh mesh = new Mesh(); mesh.subMeshCount = NumberOfVisibleFaces;//Should be no of visible faces Material[] MatsToUse = new Material[NumberOfVisibleFaces]; //Now allocate the visible faces to triangles. int FaceCounter = 0;//Tracks which number face we are now on. float PolySize = Top - Bottom; float uv0 = (float)(Bottom * 0.125f); float uv1 = (PolySize / 8.0f) + (uv0); // float offset = 0f; //bottom wall vertices MatsToUse[FaceCounter] = GameWorldController.instance.MaterialMasterList[CurrentTileMap().texture_map[CeilingTexture]]; verts[0 + (4 * FaceCounter)] = new Vector3(0f, 1.2f * 64, baseHeight); verts[1 + (4 * FaceCounter)] = new Vector3(0f, 0f, baseHeight); verts[2 + (4 * FaceCounter)] = new Vector3(-1.2f * 64, 0f, baseHeight); verts[3 + (4 * FaceCounter)] = new Vector3(-1.2f * 64, 1.2f * 64, baseHeight); //Change default UVs uvs[0 + (4 * FaceCounter)] = new Vector2(0.0f, 0.0f); uvs[1 + (4 * FaceCounter)] = new Vector2(0.0f, 1.0f * 64); uvs[2 + (4 * FaceCounter)] = new Vector2(64, 1.0f * 64); uvs[3 + (4 * FaceCounter)] = new Vector2(64, 0.0f); //Apply the uvs and create my tris mesh.vertices = verts; mesh.uv = uvs; FaceCounter = 0; int[] tris = new int[6]; tris[0] = 0 + (4 * FaceCounter); tris[1] = 1 + (4 * FaceCounter); tris[2] = 2 + (4 * FaceCounter); tris[3] = 0 + (4 * FaceCounter); tris[4] = 2 + (4 * FaceCounter); tris[5] = 3 + (4 * FaceCounter); mesh.SetTriangles(tris, FaceCounter); FaceCounter++; mr.materials = MatsToUse;//mats; mesh.RecalculateNormals(); mesh.RecalculateBounds(); mf.mesh = mesh; if (EnableCollision) { MeshCollider mc = Tile.AddComponent<MeshCollider>(); mc.sharedMesh = null; mc.sharedMesh = mesh; } return Tile; } /// <summary> /// Renders the cuboid from an arbitary set of vertices and uvs /// </summary> /// <param name="parent">Parent.</param> /// <param name="verts">Verts.</param> /// <param name="uvs">Uvs.</param> /// <param name="position">Position.</param> /// <param name="MatsToUse">Mats to use.</param> /// <param name="NoOfFaces">No of faces.</param> /// <param name="name">Name.</param> static GameObject RenderCuboid(GameObject parent, Vector3[] verts, Vector2[] uvs, Vector3 position, Material[] MatsToUse, int NoOfFaces, string name) { GameObject Tile = new GameObject(name); Tile.transform.parent = parent.transform; Tile.transform.position = position; Tile.transform.localRotation = Quaternion.Euler(0f, 0f, 0f); Tile.layer = LayerMask.NameToLayer("MapMesh"); MeshFilter mf = Tile.AddComponent<MeshFilter>(); MeshRenderer mr = Tile.AddComponent<MeshRenderer>(); //MeshCollider mc = Tile.AddComponent<MeshCollider>(); //mc.sharedMesh=null; Mesh mesh = new Mesh(); mesh.vertices = verts; mesh.uv = uvs; mesh.subMeshCount = NoOfFaces;//VisibleFaces.GetUpperBound(0)+1; int FaceCounter = 0; int[] tris = new int[6]; for (int i = 0; i < NoOfFaces; i++) { tris[0] = 0 + (4 * FaceCounter); tris[1] = 1 + (4 * FaceCounter); tris[2] = 2 + (4 * FaceCounter); tris[3] = 0 + (4 * FaceCounter); tris[4] = 2 + (4 * FaceCounter); tris[5] = 3 + (4 * FaceCounter); mesh.SetTriangles(tris, FaceCounter); FaceCounter++; } mr.materials = MatsToUse; mesh.RecalculateNormals(); mesh.RecalculateBounds(); mf.mesh = mesh; if (EnableCollision) { MeshCollider mc = Tile.AddComponent<MeshCollider>(); mc.sharedMesh = null; mc.sharedMesh = mesh; } //mc.sharedMesh=mesh; return Tile; } /// <summary> /// Renders the floor of a diag tile /// </summary> /// <param name="parent">Parent.</param> /// <param name="x">The x coordinate.</param> /// <param name="y">The y coordinate.</param> /// <param name="t">T.</param> /// <param name="Water">If set to <c>true</c> water.</param> /// <param name="Bottom">Bottom.</param> /// <param name="Top">Top.</param> /// <param name="TileName">Tile name.</param> static GameObject RenderPrism(GameObject parent, int x, int y, TileInfo t, bool Water, int Bottom, int Top, string TileName) { //Draw a cube with no slopes. int NumberOfVisibleFaces = 0; //Get the number of faces for (int i = 0; i < 6; i++) { if (t.VisibleFaces[i] == true) { NumberOfVisibleFaces++; } } //Allocate enough verticea and UVs for the faces Vector3[] verts = new Vector3[NumberOfVisibleFaces * 4]; Vector2[] uvs = new Vector2[NumberOfVisibleFaces * 4]; float floorHeight = (float)(Top * 0.15f); float baseHeight = (float)(Bottom * 0.15f); float dimX = t.DimX; float dimY = t.DimY; //Now create the mesh GameObject Tile = new GameObject(TileName); SetTileLayer(t, Tile); Tile.transform.parent = parent.transform; Tile.transform.position = new Vector3(x * 1.2f, 0.0f, y * 1.2f); Tile.transform.localRotation = Quaternion.Euler(0f, 0f, 0f); MeshFilter mf = Tile.AddComponent<MeshFilter>(); MeshRenderer mr = Tile.AddComponent<MeshRenderer>(); Mesh mesh = new Mesh(); mesh.subMeshCount = NumberOfVisibleFaces;//Should be no of visible faces Material[] MatsToUse = new Material[NumberOfVisibleFaces]; //Now allocate the visible faces to triangles. int FaceCounter = 0;//Tracks which number face we are now on. float PolySize = Top - Bottom; float uv0 = (float)(Bottom * 0.125f); float uv1 = (PolySize / 8.0f) + (uv0); float offset = 0f; //int vertCountOffset=0; for (int i = 0; i < 6; i++) { if (t.VisibleFaces[i] == true) { switch (i) { case vTOP: { //Set the verts MatsToUse[FaceCounter] = GameWorldController.instance.MaterialMasterList[FloorTexture(fSELF, t)]; verts[0 + (4 * FaceCounter)] = new Vector3(0.0f, 0.0f, floorHeight); verts[1 + (4 * FaceCounter)] = new Vector3(0.0f, 1.2f * dimY, floorHeight); verts[2 + (4 * FaceCounter)] = new Vector3(-1.2f * dimX, 1.2f * dimY, floorHeight); verts[3 + (4 * FaceCounter)] = new Vector3(-1.2f * dimX, 0.0f, floorHeight); //Allocate UVs uvs[0 + (4 * FaceCounter)] = new Vector2(0.0f, 1.0f * dimY); uvs[1 + (4 * FaceCounter)] = new Vector2(0.0f, 0.0f); uvs[2 + (4 * FaceCounter)] = new Vector2(1.0f * dimX, 0.0f); uvs[3 + (4 * FaceCounter)] = new Vector2(1.0f * dimX, 1.0f * dimY); break; } case vNORTH: { //north wall vertices offset = CalcCeilOffset(fNORTH, t); MatsToUse[FaceCounter] = GameWorldController.instance.MaterialMasterList[WallTexture(fNORTH, t)]; verts[0 + (4 * FaceCounter)] = new Vector3(-1.2f * dimX, 1.2f * dimY, baseHeight); verts[1 + (4 * FaceCounter)] = new Vector3(-1.2f * dimX, 1.2f * dimY, floorHeight); verts[2 + (4 * FaceCounter)] = new Vector3(0f, 1.2f * dimY, floorHeight); verts[3 + (4 * FaceCounter)] = new Vector3(0f, 1.2f * dimY, baseHeight); uvs[0 + (4 * FaceCounter)] = new Vector2(0.0f, uv0 - offset); uvs[1 + (4 * FaceCounter)] = new Vector2(0.0f, uv1 - offset); uvs[2 + (4 * FaceCounter)] = new Vector2(dimX, uv1 - offset); uvs[3 + (4 * FaceCounter)] = new Vector2(dimX, uv0 - offset); break; } mf.mesh=mesh; mc.sharedMesh=mesh; } verts[2 + (4 * FaceCounter)] = new Vector3(0f, 0f, floorHeight); verts[3 + (4 * FaceCounter)] = new Vector3(0f, 0f, baseHeight); uvs[0 + (4 * FaceCounter)] = new Vector2(0.0f, uv0 - offset); uvs[1 + (4 * FaceCounter)] = new Vector2(0.0f, uv1 - offset); uvs[2 + (4 * FaceCounter)] = new Vector2(dimY, uv1 - offset); uvs[3 + (4 * FaceCounter)] = new Vector2(dimY, uv0 - offset); break; } case vEAST: { //east wall vertices offset = CalcCeilOffset(fEAST, t); MatsToUse[FaceCounter] = GameWorldController.instance.MaterialMasterList[WallTexture(fEAST, t)]; verts[0 + (4 * FaceCounter)] = new Vector3(-1.2f * dimX, 0f, baseHeight); verts[1 + (4 * FaceCounter)] = new Vector3(-1.2f * dimX, 0f, floorHeight); verts[2 + (4 * FaceCounter)] = new Vector3(-1.2f * dimX, 1.2f * dimY, floorHeight); verts[3 + (4 * FaceCounter)] = new Vector3(-1.2f * dimX, 1.2f * dimY, baseHeight); uvs[0 + (4 * FaceCounter)] = new Vector2(0.0f, uv0 - offset); uvs[1 + (4 * FaceCounter)] = new Vector2(0.0f, uv1 - offset); uvs[2 + (4 * FaceCounter)] = new Vector2(dimY, uv1 - offset); uvs[3 + (4 * FaceCounter)] = new Vector2(dimY, uv0 - offset); break; } case vSOUTH: { offset = CalcCeilOffset(fSOUTH, t); MatsToUse[FaceCounter] = GameWorldController.instance.MaterialMasterList[WallTexture(fSOUTH, t)]; //south wall vertices verts[0 + (4 * FaceCounter)] = new Vector3(0f, 0f, baseHeight); verts[1 + (4 * FaceCounter)] = new Vector3(0f, 0f, floorHeight); verts[2 + (4 * FaceCounter)] = new Vector3(-1.2f * dimX, 0f, floorHeight); verts[3 + (4 * FaceCounter)] = new Vector3(-1.2f * dimX, 0f, baseHeight); uvs[0 + (4 * FaceCounter)] = new Vector2(0.0f, uv0 - offset); uvs[1 + (4 * FaceCounter)] = new Vector2(0.0f, uv1 - offset); uvs[2 + (4 * FaceCounter)] = new Vector2(dimX, uv1 - offset); uvs[3 + (4 * FaceCounter)] = new Vector2(dimX, uv0 - offset); break; } case vBOTTOM: { //bottom wall vertices MatsToUse[FaceCounter] = GameWorldController.instance.MaterialMasterList[FloorTexture(fCEIL, t)]; } static void RenderSolidTile(GameObject parent, int x, int y, TileInfo t, bool Water) { if (t.Render == 1) } //Apply the uvs and create my tris mesh.vertices = verts; mesh.uv = uvs; FaceCounter = 0; int curFace = 0; int[] tris;// = new int[6]; } static void RenderOpenTile(GameObject parent, int x, int y, TileInfo t, bool Water, bool invert) { if (t.Render == 1){ switch (t.tileType) { case TILE_DIAG_NE: tris[0] = 1 + (4 * FaceCounter); tris[1] = 2 + (4 * FaceCounter); tris[2] = 3 + (4 * FaceCounter); break; case TILE_DIAG_SE: tris[0] = 0 + (4 * FaceCounter); tris[1] = 2 + (4 * FaceCounter); tris[2] = 3 + (4 * FaceCounter); break; case TILE_DIAG_SW: tris[0] = 0 + (4 * FaceCounter); tris[1] = 1 + (4 * FaceCounter); tris[2] = 3 + (4 * FaceCounter); break; case TILE_DIAG_NW: default: tris[0] = 0 + (4 * FaceCounter); tris[1] = 1 + (4 * FaceCounter); tris[2] = 2 + (4 * FaceCounter); break; } //tris[3]=0+(4*FaceCounter); //tris[4]=2+(4*FaceCounter); //tris[5]=3+(4*FaceCounter); mesh.SetTriangles(tris, FaceCounter); } else { tris[0] = 0 + (4 * FaceCounter); tris[1] = 1 + (4 * FaceCounter); tris[2] = 2 + (4 * FaceCounter); tris[3] = 0 + (4 * FaceCounter); tris[4] = 2 + (4 * FaceCounter); tris[5] = 3 + (4 * FaceCounter); mesh.SetTriangles(tris, FaceCounter); } static void RenderDiagSETile(GameObject parent, int x, int y, TileInfo t, bool Water, bool invert) { string TileName = ""; } return Tile; } /// <summary> /// Renders a solid tile that files the entire tilespace /// </summary> /// <param name="parent">Parent.</param> /// <param name="x">The x coordinate.</param> /// <param name="y">The y coordinate.</param> /// <param name="t">T.</param> /// <param name="Water">If set to <c>true</c> water.</param> static GameObject RenderSolidTile(GameObject parent, int x, int y, TileInfo t, bool Water) { if (t.Render == true) { if (t.isWater == Water) { string TileName = "Tile_" + x.ToString("D2") + "_" + y.ToString("D2"); t.VisibleFaces[vTOP] = false; t.VisibleFaces[vBOTTOM] = false; return RenderCuboid(parent, x, y, t, Water, FLOOR_ADJ, CEILING_HEIGHT + CEIL_ADJ, TileName); } } return null; } /// <summary> /// Renders an open tile with no slopes /// </summary> /// <param name="parent">Parent.</param> } /// static void RenderDiagSWTile(GameObject parent,int x, int y, TileInfo t, bool Water, bool invert) { string TileName = ""; if (t.TerrainChange) { TileName = "Tile_" + x.ToString("D2") + "_" + y.ToString("D2"); return RenderCuboid(parent, x, y, t, Water, -16, t.floorHeight, TileName); } else { TileName = "Tile_" + x.ToString("D2") + "_" + y.ToString("D2"); return RenderCuboid(parent, x, y, t, Water, -CEILING_HEIGHT, t.floorHeight, TileName); } } else { //Ceiling version of the tile bool visB = t.VisibleFaces[vBOTTOM]; bool visT = t.VisibleFaces[vTOP]; t.VisibleFaces[vBOTTOM] = true; t.VisibleFaces[vTOP] = false; TileName = "Tile_" + x.ToString("D2") + "_" + y.ToString("D2"); GameObject output = RenderCuboid(parent, x, y, t, Water, CEILING_HEIGHT - t.ceilingHeight, CEILING_HEIGHT + CEIL_ADJ, TileName); t.VisibleFaces[vBOTTOM] = visB; t.VisibleFaces[vTOP] = visT; return output; } } } return null; } /// <summary> /// Renders an open tile with no slopes /// </summary> } static void RenderDiagNETile(GameObject parent,int x, int y, TileInfo t, bool Water, bool invert) { string TileName = ""; //Bottom face if (t.TerrainChange) { TileName = "Tile_" + x.ToString("D2") + "_" + y.ToString("D2"); //return RenderCuboid(parent,x, y, t, Water, -16, t.floorHeight, TileName); return RenderPrism(parent, x, y, t, Water, -16, t.floorHeight, TileName); } else { TileName = "Tile_" + x.ToString("D2") + "_" + y.ToString("D2"); //return RenderCuboid(parent, x, y, t, Water, -CEILING_HEIGHT, t.floorHeight, TileName); return RenderPrism(parent, x, y, t, Water, -CEILING_HEIGHT, t.floorHeight, TileName); } } else { //Ceiling version of the tile bool visB = t.VisibleFaces[vBOTTOM]; bool visT = t.VisibleFaces[vTOP]; t.VisibleFaces[vBOTTOM] = true; t.VisibleFaces[vTOP] = false; TileName = "Tile_" + x.ToString("D2") + "_" + y.ToString("D2"); GameObject output = RenderCuboid(parent, x, y, t, Water, CEILING_HEIGHT - t.ceilingHeight, CEILING_HEIGHT + CEIL_ADJ, TileName); t.VisibleFaces[vBOTTOM] = visB; t.VisibleFaces[vTOP] = visT; return output; } } } return null; } } static void RenderDiagNWTile(GameObject parent,int x, int y, TileInfo t, bool Water, bool invert) { string TileName=""; if (t.Render == true) { if (invert == false) { if (Water != true) { //the wall part TileName = "Wall_" + x.ToString("D2") + "_" + y.ToString("D2"); RenderDiagSEPortion(parent, FLOOR_ADJ, CEILING_HEIGHT + CEIL_ADJ, t, TileName); } if (t.isWater == Water) { //it's floor //RenderDiagNWPortion( FLOOR_ADJ, t.floorHeight, t,"DiagNW1"); bool PreviousNorth = t.VisibleFaces[vNORTH]; bool PreviousWest = t.VisibleFaces[vWEST]; t.VisibleFaces[vNORTH] = false; t.VisibleFaces[vWEST] = false; RenderDiagOpenTile(parent, x, y, t, Water, false); t.VisibleFaces[vNORTH] = PreviousNorth; t.VisibleFaces[vWEST] = PreviousWest; } } else {//it's ceiling //RenderDiagNWPortion( CEILING_HEIGHT - t.ceilingHeight, CEILING_HEIGHT + CEIL_ADJ, t, "DiagNW2a"); bool vis = t.VisibleFaces[vBOTTOM]; t.VisibleFaces[vBOTTOM] = true; RenderOpenTile(parent, x, y, t, Water, true); t.VisibleFaces[vBOTTOM] = vis; } return; } static void RenderSlopeNTile(GameObject parent,int x, int y, TileInfo t, bool Water, bool invert) { string TileName=""; { string TileName = ""; if (t.Render == true) { if (invert == false) { if (Water != true) { //Its wall TileName = "Wall_" + x.ToString("D2") + "_" + y.ToString("D2"); RenderDiagSWPortion(parent, FLOOR_ADJ, CEILING_HEIGHT + CEIL_ADJ, t, TileName); } if (t.isWater == Water) { //it's floor //RenderDiagNEPortion( FLOOR_ADJ, t.floorHeight, t,"TileNe1"); bool PreviousNorth = t.VisibleFaces[vNORTH]; bool PreviousEast = t.VisibleFaces[vEAST]; t.VisibleFaces[vNORTH] = false; t.VisibleFaces[vEAST] = false; //RenderOpenTile( parent , x, y, t, Water, false); RenderDiagOpenTile(parent, x, y, t, Water, false); t.VisibleFaces[vNORTH] = PreviousNorth; return; }
Initialisation of food and hunger levels on startup. Some code documentation Changed a lot of variable types