<NME> TileMapRenderer.cs <BEF> ﻿using UnityEngine; using System.Collections; using System.Linq; // used for Sum of array /// <summary> /// 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) { 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) { 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); } } } } /// <summary> /// Begins rendering a door way. /// </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! return; } if (level.Tiles[objList.objInfo[i].ObjectTileX, objList.objInfo[i].ObjectTileY].tileType != TILE_SOLID) { float floorheight = (float)level.Tiles[objList.objInfo[i].ObjectTileX, objList.objInfo[i].ObjectTileY].floorHeight * 0.15f; int BridgeIndex = ObjectLoader.findObjectByTypeInTile(objList.objInfo, objList.objInfo[i].ObjectTileX, objList.objInfo[i].ObjectTileY, ObjectInteraction.BRIDGE); if (BridgeIndex != -1) {//Take into account if the door is over a bridge. floorheight = ObjectLoader.CalcObjectXYZ(BridgeIndex, 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[CurrentTileMap().texture_map[CurrentTileMap().Tiles[currDoor.ObjectTileX, currDoor.ObjectTileY].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(currDoor.index, 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.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> /// <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[CurrentTileMap().texture_map[CurrentTileMap().Tiles[currDoor.ObjectTileX, currDoor.ObjectTileY].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(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; } 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.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)); } /// <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(i, 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 the list of bridges in the object list /// </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)) { 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 { TextureIndex = CurrentTileMap().texture_map[TextureIndex - 2 + 48]; } tmobj = GameWorldController.instance.MaterialMasterList[TextureIndex]; } 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++) { 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> /// <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; //Now create the mesh GameObject Tile = new GameObject(TileName); if (t.isWater==false) { if (t.isLava) { Tile.layer=LayerMask.NameToLayer("Lava"); } else { Tile.layer=LayerMask.NameToLayer("MapMesh"); } } else { Tile.layer=LayerMask.NameToLayer("Water"); } Tile.transform.parent=parent.transform; Tile.transform.position = new Vector3(x*1.2f,0.0f, y*1.2f); { 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++) mc.sharedMesh=null; 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 float AdjustUpperNorth = 0f; float AdjustUpperSouth = 0f; float AdjustUpperEast = 0f; float AdjustUpperWest = 0f; float AdjustLowerNorth = 0f; float AdjustLowerSouth = 0f; float AdjustLowerEast = 0f; float AdjustLowerWest = 0f; if (Floor == 1) { switch (SlopeDir) { case TILE_SLOPE_N: AdjustUpperNorth = (float)Steepness*0.15f; break; case TILE_SLOPE_S: AdjustUpperSouth = (float)Steepness*0.15f; break; case TILE_SLOPE_E: AdjustUpperEast =(float)Steepness*0.15f; break; case TILE_SLOPE_W: AdjustUpperWest = (float)Steepness*0.15f; break; } } if (Floor == 0) { switch (SlopeDir) { case TILE_SLOPE_N: AdjustLowerNorth = -(float)Steepness*0.15f; break; case TILE_SLOPE_S: AdjustLowerSouth = -(float)Steepness*0.15f; break; case TILE_SLOPE_E: AdjustLowerEast =-(float)Steepness*0.15f; break; case TILE_SLOPE_W: AdjustLowerWest = -(float)Steepness*0.15f; break; } } //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]==1) { NumberOfVisibleFaces++; } } //Allocate enough verticea and UVs for the faces Material[] MatsToUse=new Material[NumberOfVisibleFaces]; Vector3[] verts =new Vector3[NumberOfVisibleFaces*4]; Vector2[] uvs =new Vector2[NumberOfVisibleFaces*4]; float offset=0f; 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); if (t.isWater==false) { if (t.isLava) { Tile.layer=LayerMask.NameToLayer("Lava"); } else { Tile.layer=LayerMask.NameToLayer("MapMesh"); } } else { Tile.layer=LayerMask.NameToLayer("Water"); } 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>(); MeshCollider mc = Tile.AddComponent<MeshCollider>(); mc.sharedMesh=null; Mesh mesh = new Mesh(); mesh.subMeshCount=NumberOfVisibleFaces;//Should be no of visible faces //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); for (int i=0;i<6;i++) { if (t.VisibleFaces[i]==1) { 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+AdjustUpperWest+AdjustUpperSouth); verts[1+ (4*FaceCounter)]= new Vector3(0.0f, 1.2f*dimY, floorHeight+AdjustUpperWest+AdjustUpperNorth); verts[2+ (4*FaceCounter)]= new Vector3(-1.2f*dimX,1.2f*dimY, floorHeight+AdjustUpperNorth+AdjustUpperEast); verts[3+ (4*FaceCounter)]= new Vector3(-1.2f*dimX,0.0f, floorHeight+AdjustUpperSouth+AdjustUpperEast); //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: { float uv0InUse=0f; float uv1InUse=0f; float uv2InUse=0f; float uv3InUse=0f; //CalcUVsForSlopedTiles(t,SlopeDir, fNORTH, Steepness,Floor,uv0,uv1, out uv0InUse, out uv1InUse,out uv2InUse, out uv3InUse); // CalcUVsForSlopedTiles(t,SlopeDir,fNORTH,Steepness,Floor,uv0,uv1, out uv0InUse, out uv1InUse,out uv2InUse, out uv3InUse); CalcUVsForSlopedTiles(t,SlopeDir, fNORTH, Steepness,Floor,Top,Bottom,uv0,uv1, out uv0InUse, out uv1InUse,out uv2InUse, out uv3InUse); //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 +AdjustLowerSouth+AdjustLowerWest); verts[1+ (4*FaceCounter)]= new Vector3(-1.2f*dimX,1.2f*dimY, floorHeight+AdjustUpperNorth+AdjustUpperEast); verts[2+ (4*FaceCounter)]= new Vector3(0f,1.2f*dimY, floorHeight+AdjustUpperNorth+AdjustUpperWest); verts[3+ (4*FaceCounter)]= new Vector3(0f,1.2f*dimY, baseHeight+AdjustLowerSouth+AdjustLowerEast); uvs[0+ (4*FaceCounter)]=new Vector2(0.0f,uv0InUse-offset);//bottom uv uvs[1 +(4*FaceCounter)]=new Vector2(0.0f,uv1InUse-offset);//top uv uvs[2+ (4*FaceCounter)]=new Vector2(dimX,uv2InUse-offset);//top uv uvs[3+ (4*FaceCounter)]=new Vector2(dimX,uv3InUse-offset);//bottom uv break; } case vWEST: { //west wall vertices //float uv0InUse=0f; float uv1InUse=0f; float uv0InUse=0f; float uv1InUse=0f; float uv2InUse=0f; float uv3InUse=0f; //CalcUVsForSlopedTiles(t,SlopeDir, fWEST, Steepness,Floor,uv0,uv1, out uv0InUse, out uv1InUse,out uv2InUse, out uv3InUse); CalcUVsForSlopedTiles(t,SlopeDir, fWEST, Steepness,Floor,Top,Bottom,uv0,uv1, out uv0InUse, out uv1InUse,out uv2InUse, out uv3InUse); offset = CalcCeilOffset(fWEST, t); MatsToUse[FaceCounter]=GameWorldController.instance.MaterialMasterList[WallTexture(fWEST, t)]; verts[0+ (4*FaceCounter)]= new Vector3(0f,1.2f*dimY, baseHeight+AdjustLowerEast+AdjustLowerSouth); verts[1+ (4*FaceCounter)]= new Vector3(0f,1.2f*dimY, floorHeight+AdjustUpperWest+AdjustUpperNorth); verts[2+ (4*FaceCounter)]= new Vector3(0f,0f, floorHeight+AdjustUpperWest+AdjustUpperSouth); verts[3+ (4*FaceCounter)]= new Vector3(0f,0f, baseHeight+AdjustLowerEast+AdjustLowerNorth); uvs[0+ (4*FaceCounter)]=new Vector2(0.0f,uv0InUse-offset); uvs[1 +(4*FaceCounter)]=new Vector2(0.0f,uv1InUse-offset); uvs[2+ (4*FaceCounter)]=new Vector2(dimY,uv2InUse-offset); uvs[3+ (4*FaceCounter)]=new Vector2(dimY,uv3InUse-offset); break; } case vEAST: { //static void CalcUVsForSlopedTiles(TileInfo t, int SlopeDir , int face, int Steepness, int Floor, int uv0_default, int uv1_default, out int UV0_OUT, out int UV1_OUT) float uv0InUse=0f; float uv1InUse=0f; float uv2InUse=0f; float uv3InUse=0f; CalcUVsForSlopedTiles(t,SlopeDir, fEAST, Steepness,Floor,Top,Bottom,uv0,uv1, out uv0InUse, out uv1InUse,out uv2InUse, out uv3InUse); //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+AdjustLowerWest+AdjustLowerNorth); verts[1+ (4*FaceCounter)]= new Vector3(-1.2f*dimX,0f, floorHeight+AdjustUpperEast+AdjustUpperSouth); verts[2+ (4*FaceCounter)]= new Vector3(-1.2f*dimX,1.2f*dimY, floorHeight+AdjustUpperEast+AdjustUpperNorth); verts[3+ (4*FaceCounter)]= new Vector3(-1.2f*dimX,1.2f*dimY, baseHeight+AdjustLowerWest+AdjustLowerSouth); uvs[0+ (4*FaceCounter)]=new Vector2(0.0f,uv0InUse-offset);//0 uvs[1 +(4*FaceCounter)]=new Vector2(0.0f,uv1InUse-offset);//1 uvs[2+ (4*FaceCounter)]=new Vector2(dimY,uv2InUse-offset);//1 uvs[3+ (4*FaceCounter)]=new Vector2(dimY,uv3InUse-offset);//0 break; } case vSOUTH: { float uv0InUse=0f; float uv1InUse=0f; float uv2InUse=0f; float uv3InUse=0f; //CalcUVsForSlopedTiles(t,SlopeDir, fSOUTH, Steepness,Floor,uv0,uv1, out uv0InUse, out uv1InUse,out uv2InUse, out uv3InUse); CalcUVsForSlopedTiles(t,SlopeDir, fSOUTH, Steepness,Floor,Top,Bottom,uv0,uv1, out uv0InUse, out uv1InUse,out uv2InUse, out uv3InUse); //south wall vertices offset = CalcCeilOffset(fSOUTH, t); MatsToUse[FaceCounter]=GameWorldController.instance.MaterialMasterList[WallTexture(fSOUTH, t)]; verts[0+ (4*FaceCounter)]= new Vector3(0f,0f, baseHeight+AdjustLowerNorth+AdjustLowerEast); verts[1+ (4*FaceCounter)]= new Vector3(0f,0f, floorHeight+AdjustUpperSouth+AdjustUpperWest); verts[2+ (4*FaceCounter)]= new Vector3(-1.2f*dimX,0f, floorHeight+AdjustUpperSouth+AdjustUpperEast); verts[3+ (4*FaceCounter)]= new Vector3(-1.2f*dimX,0f, baseHeight+AdjustLowerNorth+AdjustLowerWest); uvs[0+ (4*FaceCounter)]=new Vector2(0.0f,uv0InUse-offset); uvs[1 +(4*FaceCounter)]=new Vector2(0.0f,uv1InUse-offset); uvs[2+ (4*FaceCounter)]=new Vector2(dimX,uv2InUse-offset); uvs[3+ (4*FaceCounter)]=new Vector2(dimX,uv3InUse-offset); break; } case vBOTTOM: { //bottom wall vertices MatsToUse[FaceCounter]=GameWorldController.instance.MaterialMasterList[FloorTexture(fCEIL, t)]; //TODO:Get the lower face adjustments for this (shock only) verts[0+ (4*FaceCounter)]= new Vector3(0f,1.2f*dimY, baseHeight+AdjustLowerSouth+AdjustLowerEast); verts[1+ (4*FaceCounter)]= new Vector3(0f,0f, baseHeight+AdjustLowerEast+AdjustLowerNorth); verts[2+ (4*FaceCounter)]= new Vector3(-1.2f*dimX,0f, baseHeight+AdjustLowerNorth+AdjustLowerWest); verts[3+ (4*FaceCounter)]= new Vector3(-1.2f*dimX,1.2f*dimY, baseHeight+AdjustLowerSouth+AdjustLowerWest); //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]==1) { 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; mc.sharedMesh=mesh; }*/ /// <summary> /// Renders the cuboid from an arbitary set of vertices and uvs 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 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; } 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
Save games now have an automatic name based on date and level The top level player container will not show arrows. Objects dropped by NPCs in conversations will appear at their impact point rather than at their feet. Endgame cutscene returns to main menu on completion Fixed some combat behaviour for the slasher of veils so it will attack the player in the final level. Slasher will now always roll a 30 in combat.  Fixes to LinkContainerContents. The Nothing texture now has it's own layer so it will not generate a nav-mesh.