private void TempSpriteManager() { MeshRenderer mesh = this.GetComponent <MeshRenderer>(); /*Vector2 offset = Vector2.zero; * int frame = (int)(Time.time * 15); * frame = frame % 4; * if(frame > 2) frame = 0; * offset = new Vector2(frame*0.25f,0.75f - 0.25f*direction); * mesh.sharedMaterial.mainTextureOffset = offset;*/ BinManager.SprData sprBlock = (BinManager.SprData)(Main.binManager.sprData[(uint)this.sprNo]); int i = 0; for (i = 0; i < (int)sprBlock.animSize; i++) { if (sprBlock.ptAnimList[i].no == (ushort)this.action && sprBlock.ptAnimList[i].dir == (ushort)direction) { break; } } if (i >= (int)sprBlock.animSize) { i = 0; } BinManager.AnimList animList = sprBlock.ptAnimList[i]; BinManager.FrameList[] frameList = animList.ptFrameList; int frame = (int)(Time.time * animList.dtAnim); frame = frame % (int)animList.frameCnt; if (frame == lastframe) { return; } Texture2D texture = Main.binManager.GetTextureByBmpNo((int)frameList[frame].BmpNo); BinManager.AdrnData adrnBlock = Main.binManager.adrnData[(int)frameList[frame].BmpNo]; this.transform.localScale = new Vector3((float)texture.width, (float)texture.height, 1); mesh.material.mainTexture = texture; Vector3 offset = new Vector3((float)(frameList[frame].PosX + adrnBlock.X) + (float)(texture.width) / 2f, -(float)(frameList[frame].PosY + adrnBlock.Y) - (float)(texture.height) / 2f, 0); this.transform.position = transform.parent.transform.position + offset; // if( mesh.material.shader != Shader.Find ("Transparent/Diffuse") ) //smesh.material.shader = Shader.Find ("Transparent/Diffuse"); }
internal void DrawMap() { if (gPosNow == gPosOld) { return; } for (int i = 0; i < Consts.MAP_RENDERSIZE && i < width; i++) { for (int j = 0; j < Consts.MAP_RENDERSIZE && j < height; j++) { MeshRenderer mesh = MeshTiles[i, j]; GameObject go = Tiles[i, j]; if (go == null || mesh == null) { Debug.Log("Error finding tile"); return; } int x = (int)(gPosNow.x - Consts.MAP_DISPLAYSIZE + i); int y = (int)(gPosNow.y - Consts.MAP_DISPLAYSIZE + j); if (x < 0 || y < 0 || x >= width || y >= height || TileData[x, y] <= 99) { mesh.material.mainTexture = Main.binManager.GetTextureByMapBmpNo(0); continue; } int mapbmpno = (int)TileData[x, y]; mesh.material.mainTexture = Main.binManager.GetTextureByMapBmpNo(mapbmpno); } } for (int i = 0; i < Consts.MAP_RENDERSIZE && i < width; i++) { for (int j = 0; j < Consts.MAP_RENDERSIZE && j < height; j++) { MeshRenderer mesh = MeshObjects[i, j]; GameObject go = Objects[i, j]; if (go == null || mesh == null) { Debug.Log("Error finding object"); return; } int x = (int)(gPosNow.x - Consts.MAP_DISPLAYSIZE + i); int y = (int)(gPosNow.y - Consts.MAP_DISPLAYSIZE + j); if (x < 0 || y < 0 || x >= width || y >= height || ObjectData[x, y] <= 99) { mesh.material.mainTexture = Main.binManager.GetTextureByMapBmpNo(0); continue; } int mapbmpno = (int)ObjectData[x, y]; mesh.enabled = true; mesh.material.mainTexture = Main.binManager.GetTextureByMapBmpNo(mapbmpno); go.transform.localScale = new Vector3(mesh.material.mainTexture.width, mesh.material.mainTexture.height, 1); BinManager.AdrnData adrnBlock = Main.binManager.adrnData[(int)Main.binManager.bitmapTable[mapbmpno]]; // Split non-unit object into unit size if (adrnBlock.Map_X == 1 && adrnBlock.Map_Y == 1) { Vector2 gPos = new Vector2(i - Consts.MAP_DISPLAYSIZE + Consts.CENTEROFFSET, j - Consts.MAP_DISPLAYSIZE + Consts.CENTEROFFSET); Vector2 cPos = Utility.ConvertGamePosToCamPos(gPos); cPos.x = cPos.x + adrnBlock.X; cPos.y = cPos.y - adrnBlock.Y; Vector3 setPos = new Vector3(cPos.x, cPos.y, (gPos.y - gPos.x) / (Consts.MAP_RENDERSIZE + 1) + 1); go.transform.localPosition = setPos; } else { // Split here int mapx, mapy; mapx = Mathf.CeilToInt((float)adrnBlock.Width / Consts.TILE_WIDTH); mapy = Mathf.CeilToInt((float)adrnBlock.Height / Consts.TILE_HEIGHT); if (go.transform.childCount > 0) { foreach (Transform child in go.transform) { GameObject.Destroy(child.gameObject); } } for (int k = 0; k < mapx; k++) { for (int l = 0; l < mapy; l++) { // Create game objects here // Get mesh renderer // TBD } } // Disable parent renderer mesh.enabled = false; } } } gPosOld = gPosNow; }