public static bool isNull(inTile tile) { if (tile.cover == null) { if (tile.character == null) { return(true); } } return(false); }
void Start() { Dictionary <string, inTile> refDic = new Dictionary <string, inTile>(); //Object Pooling inTile refInTile = new inTile(); refInTile.character = Instantiate((GameObject)Resources.Load <GameObject>("Karakterim")); CharacterValue asd = refInTile.character.GetComponent <CharacterValue>(); refDic.Add("5 5", refInTile); GameObject grid = Grid.gridStart(sizex, sizey, offsetX, offsetY, (float)scale, material, refDic); }
public static TileObject whatInIt(inTile referance) { if (referance.character != null) { return(TileObject.Character); } else if (referance.cover != null) { return(TileObject.Cover); } else { return(TileObject.Null); } }
public static GameObject gridStart(int matrisX, int matrisY, float offsetX, float offsetY, float scale, Material material, Dictionary <string, inTile> tile = null) { GameObject tmp = new GameObject("Grid"); tmp.AddComponent <Grid>(); tmp.GetComponent <Grid>().matrisSize = new Vector2(matrisX, matrisY); tmp.GetComponent <Grid>().tileMatris = new Dictionary <string, GameObject>(); tmp.GetComponent <Grid>().charPosition = new Dictionary <string, Vector2>(); bool isNull = (tile == null ? true : false); inTile refInTile; inTileTool itt = new inTileTool(); for (int X = 0; X < matrisX; X++) { for (int Y = 0; Y < matrisY; Y++) { refInTile = new inTile(); if (!isNull) { if (tile.ContainsKey(X.ToString() + " " + Y.ToString())) { refInTile = tile[X.ToString() + " " + Y.ToString()]; if (inTileTool.whatInIt(refInTile) == TileObject.Character) { tmp.GetComponent <Grid>().charPosition.Add(refInTile.character.name, new Vector2(X, Y)); } refInTile.character.GetComponent <Transform>().position = new Vector3(offsetX + X * scale, -(offsetY + Y * scale), -0.1f); refInTile.character.GetComponent <Transform>().localScale = new Vector2(scale, scale); } } tmp.GetComponent <Grid>().tileMatris.Add(X.ToString() + " " + Y.ToString(), Tile.TileAdder(new GameObject(X.ToString() + " " + Y.ToString()), tmp, false, refInTile, offsetX + X * scale, -(offsetY + Y * scale), scale, material)); } } return(tmp); }
public static GameObject TileAdder(GameObject tile, GameObject parent, bool isReachable, inTile intile = new inTile(), float offsetX = 0, float offsetY = 0, float size = 1, Material material = null) { GameObject tmpGO = GameObject.CreatePrimitive(PrimitiveType.Cube); tile.tag = "Tile"; tile.AddComponent <Tile>(); tile.GetComponent <Tile>().isReachable = isReachable; tile.GetComponent <Tile>().whatsInTile = intile; tile.GetComponent <Tile>().matrisCor = new Vector2(float.Parse(tile.name.Split(' ')[0]), float.Parse(tile.name.Split(' ')[1])); tile.transform.parent = parent.transform; tile.transform.position = new Vector2(offsetX, offsetY); tile.transform.localScale = new Vector2(size, size); tile.AddComponent <BoxCollider>(); tile.AddComponent <MeshRenderer>().sharedMaterial = material; tile.AddComponent <MeshFilter>().mesh = tmpGO.GetComponent <MeshFilter>().mesh; tile.GetComponent <Tile>().defaultColor = tile.GetComponent <MeshRenderer>().material.color; Destroy(tmpGO); return(tile); }