- Home /
Making a tile editor
Hello everyone!
i'm wondering about how do you make a tile editor. i've stumbled on a plugin in the Assets store. and i wanna develop my own, to use in the game. it's better than paying 25$
http://u3d.as/content/doppler-interactive/tidy-tile-mapper/2AF http://www.youtube.com/watch?v=Oh1AH9N1-9E
Thanks!
Answer by ashique · Feb 07, 2014 at 11:18 AM
Hi I have created one Tile manager as given below, you can edit it depending upon your requirement..
using UnityEngine; using System.Collections;
// This class will provide tiles position, status, type public class TilesManager : MonoBehaviour
{ float mfXRatio; float mfYRatio;
public int _iNoOfRows;
public int _iNoOfCols;
public float _LeftMargin;
public float _DownMargin;
public float _XSpace;
public float _YSpace;
Vector3 [,]_VectDotsPosition;
public static TilesManager _tilesManager;
TileType[,] meTilesType;
// Use this for initialization
void Start ()
{
_tilesManager = this;
mfXRatio = Screen.width/768f;
mfYRatio = Screen.height/1024f;
createTiles(_iNoOfRows, _iNoOfCols, _LeftMargin, _DownMargin, _XSpace, _YSpace);
}
// To create Tiles
public void createTiles(int piNoOfRows, int piNoOfCols, float pfLeftMargin, float pfDownMargin, float pfXSpace, float pfYSpace)
{
_VectDotsPosition = new Vector3[piNoOfRows, piNoOfCols];
InitializeTileType();
for(int i = 0; i < piNoOfRows; i++)
{
for(int j = 0; j < piNoOfCols; j++)
{
_VectDotsPosition[i,j] = new Vector3((pfLeftMargin + pfXSpace * i) * mfXRatio, (pfDownMargin + pfYSpace * j) * mfYRatio, 0);
}
}
}
void InitializeTileType()
{
meTilesType = new TileType[_iNoOfRows, _iNoOfCols];
for(int i = 0; i < _iNoOfRows; i++)
{
for(int j = 0; j < _iNoOfCols; j++)
{
meTilesType[i, j] = TileType.BREAKABLE_TILE;
}
}
// meTilesType[3, 6] = TileType.UNBREAKABLE_TILE; // meTilesType[0, 6] = TileType.EMPTY_TILE; // meTilesType[7, 7] = TileType.EMPTY_TILE; // meTilesType[4, 3] = TileType.UNBREAKABLE_TILE; // meTilesType[4, 2] = TileType.UNBREAKABLE_TILE; }
// Returns tile position
public Vector3 GetTilePosition(int piIndexX, int piIndexY)
{
if(piIndexX >= _iNoOfCols || piIndexX < 0 || piIndexY >= _iNoOfRows || piIndexY < 0)
return Vector3.zero;
return _VectDotsPosition[piIndexX, piIndexY];
}
public void SetTileType(int piIndexX, int piIndexY, TileType peType)
{
meTilesType[piIndexX, piIndexY] = peType;
}
public TileType GetTileType(int piIndexX, int piIndexY)
{
return meTilesType[piIndexX, piIndexY];
}
}
public enum TileType { BREAKABLE_TILE, // A dot can move to this tile UNBREAKABLE_TILE, // A dot cant move to this tile, the dot will pass through beside tiles EMPTY_TILE, // A dot will pass through this tile if next to this empty tile is breakable BLOCKED_TILE, BLOCKED_TILE_TYPE1, BLOCKED_TILE_TYPE2, BLOCKED_TILE_TYPE3, BLOCKED_TILE_TYPE4, };