<NME> TileMapRenderer.cs <BEF> ﻿using UnityEngine; using System.Collections; using System.Linq; // used for Sum of array /// Tile map renderer. /// </summary> /// Renders the tile map in 3d public class TileMapRenderer : Loader{ static bool debugtextures=false; 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 const int TILE_DIAG_SE= 2; const int TILE_DIAG_SW =3; const int TILE_DIAG_NE= 4; const int TILE_DIAG_NW =5; 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; const int vEAST =1; const int vBOTTOM= 2; const int vWEST= 3; const int vNORTH= 4; const int vSOUTH= 5; //BrushFaces const int fSELF =128; 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 FLOOR_ADJ =0;//-2; const float doorwidth = 0.8f; const float doorframewidth = 1.2f; const float doorSideWidth = (doorframewidth-doorwidth)/2f; const float doorheight = 7f * 0.15f; /// <summary> /// Generates the level from tile map. /// </summary> /// <param name="parent">Parent.</param> /// <param name="sceneryParent">Scenery parent.</param> /// <param name="game">Game.</param> /// <param name="Level">Level.</param> /// <param name="objList">Object list.</param> /// <param name="UpdateOnly">If set to <c>true</c> update only.</param> public static void GenerateLevelFromTileMap(GameObject parent, GameObject sceneryParent, string game, TileMap Level, ObjectLoader objList, bool UpdateOnly) { bool skipCeil=true; CEILING_HEIGHT=Level.CEILING_HEIGHT; 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) { TileInfo tmp=new TileInfo(); //Ceiling tmp.tileType = 1; tmp.Render = true; tmp.isWater = false; tmp.tileX = 0; tmp.tileY = 0; tmp.DimX = TileMap.TileMapSizeX+1; tmp.DimY = TileMap.TileMapSizeY+1; tmp.ceilingHeight = 0; tmp.floorTexture = Level.Tiles[0,0].shockCeilingTexture; tmp.shockCeilingTexture = Level.Tiles[0,0].shockCeilingTexture; tmp.East = Level.Tiles[0,0].shockCeilingTexture;//CAULK; tmp.West = Level.Tiles[0,0].shockCeilingTexture;//CAULK; tmp.North = Level.Tiles[0,0].shockCeilingTexture;//CAULK; tmp.South = Level.Tiles[0,0].shockCeilingTexture;//CAULK; tmp.VisibleFaces[vTOP] = false; tmp.VisibleFaces[vEAST] = false; tmp.VisibleFaces[vBOTTOM] = true; tmp.VisibleFaces[vWEST] = false; tmp.VisibleFaces[vNORTH] = false; tmp.VisibleFaces[vSOUTH] = false; // top,east,bottom,west,north,south //GameObject ceil = GameWorldController.instance.ceiling = RenderTile(sceneryParent, tmp.tileX, tmp.tileX, tmp, false, false, true, false); //ceil.layer= LayerMask.NameToLayer ("UWObjects"); //And at 99,99 for special stuff. for (short x = TileMap.ObjectStorageTile-1; x <= TileMap.ObjectStorageTile+1; x++) { for (short y = TileMap.ObjectStorageTile-1; y <=TileMap.ObjectStorageTile+1; y++) { tmp.tileX = x; 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); } } } } if (!UpdateOnly) { //Render bridges, pillars and door ways switch (_RES) { case GAME_SHOCK: break; default: RenderBridges(sceneryParent,Level,objList); 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) { if (objList==null) { return; } for (int i=0; i<=objList.objInfo.GetUpperBound(0);i++) { if (objList.objInfo[i]!=null) { if (((objList.objInfo[i].item_id>=320) && (objList.objInfo[i].item_id<=335)) && (objList.objInfo[i].InUseFlag==1)) { RenderDoor (Parent, level, objList, i); } } } } public static void RenderDoor (GameObject Parent, TileMap level, ObjectLoader objList,int i) { if (level.Tiles [objList.objInfo [i].tileX, objList.objInfo [i].tileY].tileType != TILE_SOLID) { float floorheight = (float)level.Tiles [objList.objInfo [i].tileX, objList.objInfo [i].tileY].floorHeight * 0.15f; int BridgeIndex = ObjectLoader.findObjectByTypeInTile (objList.objInfo, objList.objInfo [i].tileX, objList.objInfo [i].tileY, ObjectInteraction.BRIDGE); if (BridgeIndex != -1) { floorheight = ObjectLoader.CalcObjectXYZ (_RES, level, level.Tiles, objList.objInfo, BridgeIndex, objList.objInfo [i].tileX, objList.objInfo [i].tileY, 0).y; } 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> /// <param name="objList">Object list.</param> /// <param name="currDoor">Curr door.</param> public static void RenderDoorwayRear(GameObject Parent, TileMap level, ObjectLoader objList, ObjectLoaderInfo currDoor, float floorHeight) { 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; //Uv ratios across the x axis of the door float uvXPos1 = 0f; float uvXPos2 = uvXPos1 + doorSideWidth/ 1.2f; float uvXPos3 =uvXPos2 + doorwidth/1.2f; float uvXPos4 = 1f; // or 1.2f/1.2f //positions Vector3 position = ObjectLoader.CalcObjectXYZ(_RES,level,level.Tiles,objList.objInfo,currDoor.index, currDoor.tileX, currDoor.tileY,0); //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.tileY*1.2f + 1.2f / 2f); break; case NORTH: case SOUTH: position =new Vector3( currDoor.tileX*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.tileX==12) && (currDoor.tileY==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> /// <param name="currDoor">Curr door.</param> public static void RenderDoorwayFront(GameObject Parent, TileMap level, ObjectLoader objList, ObjectLoaderInfo currDoor, float floorHeight) { 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]]; } //Door params //float floorheight =(float) level.Tiles[currDoor.tileX,currDoor.tileY].floorHeight * 0.15f; //if (level.Tiles[currDoor.tileX,currDoor.tileY].hasBridge) //{ /* 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; }*/ //} //Uv ratios across the x axis of the door float uvXPos1 = 0f; float uvXPos2 = uvXPos1 + doorSideWidth/ 1.2f; float uvXPos3 =uvXPos2 + doorwidth/1.2f; float uvXPos4 = 1f; // or 1.2f/1.2f //Vector3 doorposition; //positions Vector3 position =ObjectLoader.CalcObjectXYZ(_RES,level,level.Tiles,objList.objInfo,currDoor.index, currDoor.tileX, currDoor.tileY,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.tileY*1.2f + 1.2f / 2f); break; case NORTH: case SOUTH: position =new Vector3( currDoor.tileX*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(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 Vector3[] overHead = new Vector3[4]; switch (currDoor.heading*45) { case EAST: case WEST: //Swap x and y 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.tileX==12) && (currDoor.tileY==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.tileX==12) && (currDoor.tileY==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.tileX==12) && (currDoor.tileY==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)); } /// <summary> /// Renders the pillar models. /// </summary> /// <param name="Parent">Parent.</param> /// <param name="level">Level.</param> /// <param name="objList">Object list.</param> 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]!=null) { if ((objList.objInfo[i].GetItemType()==ObjectInteraction.PILLAR) && (objList.objInfo[i].InUseFlag==1)) { Vector3 position = ObjectLoader.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); 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])); } else { Debug.Log("RenderPillar: Missing material resource for tmobj/" + TextureIndex); return; } } } } } /// <summary> /// Renders bridges /// </summary> /// <param name="Parent">Parent.</param> /// <param name="level">Level.</param> /// <param name="objList">Object list.</param> public static void RenderBridges(GameObject Parent, TileMap level, ObjectLoader objList) { if (objList==null) { return; } for (int i=0; i<=objList.objInfo.GetUpperBound(0);i++) { if (objList.objInfo[i] !=null) { if ((objList.objInfo[i].GetItemType()==ObjectInteraction.BRIDGE) && (objList.objInfo[i].InUseFlag==1) && (objList.objInfo[i].invis==0)) { Vector3 position = ObjectLoader.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); 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); } int TextureIndex= (objList.objInfo[i].enchantment<<3) | objList.objInfo[i].flags & 0x3F; Material tmobj; if (TextureIndex>=2) { if (_RES==GAME_UW2) { TextureIndex= GameWorldController.instance.currentTileMap().texture_map[TextureIndex-2]; } else { TextureIndex= GameWorldController.instance.currentTileMap().texture_map[TextureIndex-2+48]; } tmobj = GameWorldController.instance.MaterialMasterList[TextureIndex];//(Material)Resources.Load(_RES+"/Materials/tmobj/tmobj_" + (30 + TextureIndex).ToString()); } else { tmobj = (Material)Resources.Load(_RES+"/Materials/tmobj/tmobj_" + (30 + TextureIndex).ToString()); if (tmobj.mainTexture==null) {//UW1 style bridges UW2 has some differences.... tmobj.mainTexture=GameWorldController.instance.TmObjArt.LoadImageAt(30 + 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])); } } } } /// <summary> /// Renders the a 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="invert">If set to <c>true</c> invert.</param> /// <param name="skipFloor">If set to <c>true</c> skip floor.</param> /// <param name="skipCeil">If set to <c>true</c> skip ceil.</param> public static GameObject 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. switch (t.tileType) { case TILE_SOLID: //0 { //solid return RenderSolidTile(parent, x, y, t, Water); } case TILE_OPEN: //1 {//open if (skipFloor != true) { return RenderOpenTile( parent , x, y, t, Water, false); } //floor if ((skipCeil != true)) { return RenderOpenTile( parent , x, y, t, Water, true); } //ceiling break; } case TILE_DIAG_SE: {//diag se if (skipFloor != true) { RenderDiagSETile( parent , x, y, t, Water, false); }//floor if ((skipCeil != true)) { RenderDiagSETile( parent , x, y, t, Water, true); } return null; } 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: { if (skipFloor != true) { RenderRidgeNETile( parent , x, y, t, Water, false); }//floor if ((skipCeil != true)) { RenderRidgeSWTile( parent , x, y, t, Water, true); } break; } case SLOPE_FLOOR_ONLY: { if (skipFloor != true) { RenderRidgeNETile( 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)) { RenderValleyNETile( parent , x, y, t, Water, true); } break; } } 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) { 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; } 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 curFace=0; int [] tris;// = new int[6]; for (int i=0;i<6;i++) { if (curFace == vTOP) { tris = new int[3]; } else { tris = new int[6]; } if (t.VisibleFaces[i]==true) { if (i==vTOP) { 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); } FaceCounter++; curFace++; } } 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 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> /// <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="invert">If set to <c>true</c> invert.</param> static GameObject RenderOpenTile(GameObject parent, int x, int y, TileInfo t, bool Water, bool invert) { if (t.Render == true){ string TileName = ""; if (t.isWater == Water) { if (invert == false) { //Bottom face 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> /// <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="invert">If set to <c>true</c> invert.</param> static GameObject RenderDiagOpenTile(GameObject parent, int x, int y, TileInfo t, bool Water, bool invert) { if (t.Render == true){ string TileName = ""; if (t.isWater == Water) { if (invert == false) { //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; } /// <summary> /// Renders the diag SE 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="invert">If set to <c>true</c> invert.</param> static void RenderDiagSETile(GameObject parent, int x, int y, TileInfo t, bool Water, bool invert) { string TileName = ""; //int BLeftX; int BLeftY; int BLeftZ; int TLeftX; int TLeftY; int TLeftZ; int TRightX; int TRightY; int TRightZ; 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; } /// <summary> /// Renders the diag SW 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="invert">If set to <c>true</c> invert.</param> static void RenderDiagSWTile(GameObject parent,int x, int y, TileInfo t, bool Water, bool invert) { 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; t.VisibleFaces[vEAST] = PreviousEast; } } else { //its' ceiling. //RenderDiagNEPortion( CEILING_HEIGHT - t.ceilingHeight, CEILING_HEIGHT + CEIL_ADJ, t, "TileNe2"); bool vis= t.VisibleFaces[vBOTTOM]; t.VisibleFaces[vBOTTOM]=true; RenderOpenTile( parent , x, y, t, Water, true); t.VisibleFaces[vBOTTOM]=vis; } } return; } /// <summary> /// Renders the diag NE 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="invert">If set to <c>true</c> invert.</param> static void RenderDiagNETile(GameObject parent,int x, int y, TileInfo t, bool Water, bool invert) { string TileName = ""; if (t.Render == true){ if (invert == false) { if (Water != true) { TileName = "Wall_" + x.ToString("D2") + "_" + y.ToString("D2"); RenderDiagNEPortion(parent, FLOOR_ADJ, CEILING_HEIGHT + CEIL_ADJ, t, TileName); } if (t.isWater == Water) { //it's floor //RenderDiagSWPortion( FLOOR_ADJ, t.floorHeight, t, "DiagSW2"); bool PreviousSouth = t.VisibleFaces[vSOUTH]; bool PreviousWest = t.VisibleFaces[vWEST]; t.VisibleFaces[vSOUTH] = false; t.VisibleFaces[vWEST] = false; //RenderOpenTile( parent , x, y, t, Water, false); RenderDiagOpenTile( parent , x, y, t, Water, false); t.VisibleFaces[vSOUTH] = PreviousSouth; t.VisibleFaces[vWEST] = PreviousWest; } } else {//it's ceiling //RenderDiagSWPortion( CEILING_HEIGHT - t.ceilingHeight, CEILING_HEIGHT + CEIL_ADJ, t, "DiagSE3"); bool vis= t.VisibleFaces[vBOTTOM]; t.VisibleFaces[vBOTTOM]=true; RenderOpenTile( parent , x, y, t, Water, true); t.VisibleFaces[vBOTTOM]=vis; } } return; } /// <summary> /// Renders the diag NW 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="invert">If set to <c>true</c> invert.</param> 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) { //It's wall. TileName = "Wall_" + x.ToString("D2") + "_" + y.ToString("D2"); RenderDiagNWPortion(parent, FLOOR_ADJ, CEILING_HEIGHT + CEIL_ADJ, t, TileName); } if (t.isWater == Water) {//TODO:Update these floors to only show the top surface. //it's floor //RenderDiagSEPortion( FLOOR_ADJ, t.floorHeight, t, "DiagSE2"); bool PreviousSouth = t.VisibleFaces[vSOUTH]; bool PreviousEast = t.VisibleFaces[vEAST]; t.VisibleFaces[vSOUTH] = false; t.VisibleFaces[vEAST] = false; RenderDiagOpenTile( parent , x, y, t, Water, false); t.VisibleFaces[vSOUTH] = PreviousSouth; t.VisibleFaces[vEAST] = PreviousEast; } } else {//it's ceiling //RenderDiagSEPortion( CEILING_HEIGHT - t.ceilingHeight, CEILING_HEIGHT + CEIL_ADJ, t, "DiagSE3"); bool vis= t.VisibleFaces[vBOTTOM]; t.VisibleFaces[vBOTTOM]=true; RenderOpenTile( parent , x, y, t, Water, true); t.VisibleFaces[vBOTTOM]=vis; } } return; } /// <summary> /// Renders the slope N 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="invert">If set to <c>true</c> invert.</param> static void RenderSlopeNTile(GameObject parent,int x, int y, TileInfo t, bool Water, bool invert) { string TileName=""; if (t.Render == true){ if (invert == false) { if (t.isWater == Water) { //A floor TileName = "Tile_" + x.ToString("D2") + "_" + y.ToString("D2"); RenderSlopedCuboid(parent, x, y, t, Water, FLOOR_ADJ, t.floorHeight, TILE_SLOPE_N, t.shockSteep, 1, TileName); } } else { //It's invert TileName = "N_Ceiling_" + x.ToString("D2") + "_" + y.ToString("D2"); bool visB= t.VisibleFaces[vBOTTOM]; bool visT= t.VisibleFaces[vTOP]; t.VisibleFaces[vBOTTOM]=true; t.VisibleFaces[vTOP]=false; RenderSlopedCuboid(parent, x, y, t, Water, CEILING_HEIGHT - t.ceilingHeight, CEILING_HEIGHT + CEIL_ADJ, TILE_SLOPE_N, t.shockSteep, 0, TileName); t.VisibleFaces[vBOTTOM]=visB; t.VisibleFaces[vTOP]=visT; } } return; } /// <summary> /// Renders the slope S 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="invert">If set to <c>true</c> invert.</param> static void RenderSlopeSTile(GameObject parent,int x, int y, TileInfo t, bool Water, bool invert) { string TileName=""; if (t.Render == true){ if (invert == false) { if (t.isWater == Water) { //A floor TileName = "Tile_" + x.ToString("D2") + "_" + y.ToString("D2"); RenderSlopedCuboid(parent, x, y, t, Water, FLOOR_ADJ, t.floorHeight, TILE_SLOPE_S, t.shockSteep, 1, TileName); } } else { //It's invert TileName = "S_Ceiling_" + x.ToString("D2") + "_" + y.ToString("D2"); bool visB= t.VisibleFaces[vBOTTOM]; bool visT= t.VisibleFaces[vTOP]; t.VisibleFaces[vBOTTOM]=true; t.VisibleFaces[vTOP]=false; RenderSlopedCuboid(parent, x, y, t, Water, CEILING_HEIGHT - t.ceilingHeight, CEILING_HEIGHT + CEIL_ADJ, TILE_SLOPE_S, t.shockSteep, 0, TileName); t.VisibleFaces[vBOTTOM]=visB; t.VisibleFaces[vTOP]=visT; } } return; } /// <summary> /// Renders the slope W 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="invert">If set to <c>true</c> invert.</param> static void RenderSlopeWTile(GameObject parent,int x, int y, TileInfo t, bool Water, bool invert) { string TileName=""; if (t.Render == true){ if (invert == false) { if (t.isWater == Water) { //A floor TileName = "Tile_" + x.ToString("D2") + "_" + y.ToString("D2"); RenderSlopedCuboid(parent, x, y, t, Water, FLOOR_ADJ, t.floorHeight, TILE_SLOPE_W, t.shockSteep, 1, TileName); } } else { //It's invert TileName = "W_Ceiling_" + x.ToString("D2") + "_" + y.ToString("D2"); bool visB= t.VisibleFaces[vBOTTOM]; bool visT= t.VisibleFaces[vTOP]; t.VisibleFaces[vBOTTOM]=true; t.VisibleFaces[vTOP]=false; RenderSlopedCuboid(parent, x, y, t, Water, CEILING_HEIGHT - t.ceilingHeight, CEILING_HEIGHT + CEIL_ADJ, TILE_SLOPE_W, t.shockSteep, 0, TileName); t.VisibleFaces[vBOTTOM]=visB; t.VisibleFaces[vTOP]=visT; } } return; } /// <summary> /// Renders the slope E 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="invert">If set to <c>true</c> invert.</param> static void RenderSlopeETile(GameObject parent,int x, int y, TileInfo t, bool Water, bool invert) { string TileName=""; if (t.Render == true){ if (invert == false) { if (t.isWater == Water) { //A floor TileName = "Tile_" + x.ToString("D2") + "_" + y.ToString("D2"); RenderSlopedCuboid(parent, x, y, t, Water, FLOOR_ADJ, t.floorHeight, TILE_SLOPE_E, t.shockSteep, 1, TileName); } } else { //It's invert TileName = "E_Ceiling_" + x.ToString("D2") + "_" + y.ToString("D2"); bool visB= t.VisibleFaces[vBOTTOM]; bool visT= t.VisibleFaces[vTOP]; t.VisibleFaces[vBOTTOM]=true; t.VisibleFaces[vTOP]=false; RenderSlopedCuboid(parent, x, y, t, Water, CEILING_HEIGHT - t.ceilingHeight, CEILING_HEIGHT + CEIL_ADJ, TILE_SLOPE_E, t.shockSteep, 0, TileName); t.VisibleFaces[vBOTTOM]=visB; t.VisibleFaces[vTOP]=visT; } } return; } /// <summary> /// Renders the valley NW 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="invert">If set to <c>true</c> invert.</param> static void RenderValleyNWTile(GameObject parent,int x, int y, TileInfo t, bool Water, bool invert) { if (invert == false) { //int originalTile = t.tileType; //t.tileType = TILE_SLOPE_N; //RenderSlopeNTile( parent , x, y, t, Water, invert); //t.tileType = TILE_SLOPE_W; //RenderSlopeWTile( parent , x, y, t, Water, invert); //t.tileType = originalTile; string TileName = "VNW_" + x.ToString("D2") + "_" + y.ToString("D2"); RenderSlopedCuboid(parent, x, y, t, Water, FLOOR_ADJ, t.floorHeight, TILE_VALLEY_NW, t.shockSteep, 1, TileName); } else { string TileName = "VNW_Ceiling_" + x.ToString("D2") + "_" + y.ToString("D2"); t.VisibleFaces[vBOTTOM]=true; RenderSlopedCuboid(parent, x, y, t, Water, CEILING_HEIGHT - t.ceilingHeight, CEILING_HEIGHT + CEIL_ADJ, TILE_RIDGE_SE, t.shockSteep, 0, TileName); } return; } /// <summary> /// Renders the valley NE 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="invert">If set to <c>true</c> invert.</param> static void RenderValleyNETile(GameObject parent,int x, int y, TileInfo t, bool Water, bool invert) { if (invert==false) { //int originalTile = t.tileType; //t.tileType = TILE_SLOPE_E; //RenderSlopeETile( parent , x, y, t, Water, invert); //t.tileType = TILE_SLOPE_N; //RenderSlopeNTile( parent , x, y, t, Water, invert); //t.tileType = originalTile; //return; string TileName = "VNE_" + x.ToString("D2") + "_" + y.ToString("D2"); RenderSlopedCuboid(parent, x, y, t, Water, FLOOR_ADJ, t.floorHeight, TILE_VALLEY_NE, t.shockSteep, 1, TileName); } else { string TileName = "VNE_Ceiling_" + x.ToString("D2") + "_" + y.ToString("D2"); t.VisibleFaces[vBOTTOM]=true; RenderSlopedCuboid(parent, x, y, t, Water, CEILING_HEIGHT - t.ceilingHeight, CEILING_HEIGHT + CEIL_ADJ, TILE_RIDGE_SW, t.shockSteep, 0, TileName); } } /// <summary> /// Renders the valley SW 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="invert">If set to <c>true</c> invert.</param> static void RenderValleySWTile(GameObject parent,int x, int y, TileInfo t, bool Water, bool invert) { if (invert==false) { //int originalTile = t.tileType; //t.tileType = TILE_SLOPE_W; //RenderSlopeWTile(
Implemented the bridge TRAP Bridges are now rendered individually on the start up of the bridge game object instead of during the map rendering Renamed tileX/tileY in the object loader. Added event handler for when objects are consumed and implemented 1 overload for mapobjects to support destruction of their models.