Beispiel #1
0
    private void ClickHex() // checks if a valid hex was clicked
    {
        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        HexCell h;

        if (Physics.Raycast(ray, out rayHit))
        {
            h = rayHit.transform.gameObject.GetComponent <HexCell>();
            if (h != null) // it might be tempting to put this and the nested if statment together with an &&, but that'll throw an error if h is null when it check h.Unit
            {
                if (h.Unit == null && h.Passable)
                {
                    //code to place current terrain object.
                    Unit u = MapMaster.MakeTerrain(terrainArray[(int)currTerrain]);
                    u.CurrentHex = h;
                    h.Unit       = u;
                    ITerrain uIT = u.GetComponent <ITerrain>();
                    uIT.SetTiles();
                    uIT.SetPosition();
                    uIT.SetCollider();
                }
            }
        }
    }
Beispiel #2
0
    private void LoadMap(string [] lines)
    {
        string rawData; // the entire line of text read from the file

        string[] dData; // the data after being split up based on the given delim above.

        string data = lines[0];

        int rad = System.Int32.Parse(data);

        MapMaster.SetMap(rad);

        for (int i = 1; i < lines.Length - 1; i++)
        {
            rawData = lines[i];
            dData   = rawData.Split(DELIM);

            if (dData.Length >= 5)
            {
                int  q = int.Parse(dData[(int)CellData.q]);
                int  r = int.Parse(dData[(int)CellData.r]);
                Unit u = ((dData[(int)CellData.unit] == "null") ? null : MapMaster.MakeTerrain(dData[(int)CellData.unit])); // if the hex has any terrain, the Get Terrain method returns the related type after spawning it.
                if (u != null)
                {
                    u.UDirection = int.Parse(dData[(int)CellData.unitRotation]); // rotation of the unit
                }
                HexSize  s = (HexSize)int.Parse((dData[(int)CellData.size]));
                TileType type;

                if (dData.Length <= (int)CellData.type)
                {
                    type = 0;
                }
                else
                {
                    type = (TileType)int.Parse((dData[(int)CellData.type]));
                }

                MapMaster.MakeTile(q, r);

                if (u != null) // depending on the natue of how we handle loading terrain, we might be checking for the string "null" here instead and not loading the object itself until we get to TerranPass
                {
                    MapMaster.Map[r, q].Unit            = u;
                    MapMaster.Map[r, q].Unit.CurrentHex = MapMaster.Map[r, q];
                    toBuild.Add(MapMaster.Map[r, q]);
                }

                if ((int)s != 0)
                {
                    MapMaster.Map[r, q].Size = s;
                    toSize.Add(MapMaster.Map[r, q]);
                }

                if ((int)type != 0)
                {
                    MapMaster.Map[r, q].Type = type;
                    toType.Add(MapMaster.Map[r, q]);
                }
            }
        }

        SizePass();    // any cells needing to have their scale changed are handled here.
        TerrainPass(); // any cells that are to have terrain is handled here.
        TypePass();    //any cells that need to have their cost and matieral changed are handled here.

        ViewMaster.PlaceCubes();
    }