コード例 #1
0
        private void LoadGrid()
        {
            string[] hexDescriptions = System.IO.File.ReadAllLines(MEConfig.mapLocation + MEConfig.mapName + MEConfig.mapFileType);

            foreach (string description in hexDescriptions)
            {
                //Parse file input
                string desc;
                string q = description.Substring(0, description.IndexOf(','));
                desc = description.Substring(description.IndexOf(',') + 1, description.Length - description.IndexOf(',') - 1);
                string r = desc.Substring(0, desc.IndexOf(','));
                desc = desc.Substring(desc.IndexOf(',') + 1, desc.Length - desc.IndexOf(',') - 1);
                string t = desc;

                int qVal;
                int rVal;
                if (int.TryParse(q, out qVal) && int.TryParse(r, out rVal))
                {
                    try {
                        Deft.Terrain terrain = (Deft.Terrain)Enum.Parse(typeof(Deft.Terrain), t);

                        //Instantiate in-game hexes
                        Vector2    hexCoords   = new Vector2(qVal, rVal);
                        Vector2    worldCoords = HexVectorUtil.worldPositionOfHexCoord(hexCoords);
                        GameObject hex         = (GameObject)Instantiate(meHex, new Vector3(worldCoords.x, worldCoords.y, 1), Quaternion.identity);
                        hex.transform.SetParent(transform);

                        HexGrid.Add(hexCoords, new MEHexEntry(hex, hexCoords, terrain));
                    } catch { }
                }
            }
        }
コード例 #2
0
ファイル: WSController.cs プロジェクト: GBudee/deft-Sample
        private void LoadGrid()
        {
            string mapName;

            if (Vaults.mapName != null)
            {
                mapName = Vaults.mapName;
            }
            else
            {
                mapName = Config.defaultMapName;
            }

            TextAsset map = (TextAsset)Resources.Load(Config.mapLocation + mapName, typeof(TextAsset));

            string[] hexDescriptions = map.text.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);

            foreach (string description in hexDescriptions)
            {
                try {
                    //Parse file input
                    string desc;
                    string q = description.Substring(0, description.IndexOf(','));
                    desc = description.Substring(description.IndexOf(',') + 1, description.Length - description.IndexOf(',') - 1);
                    string r = desc.Substring(0, desc.IndexOf(','));
                    desc = desc.Substring(desc.IndexOf(',') + 1, desc.Length - desc.IndexOf(',') - 1);
                    string t = desc;

                    int qVal;
                    int rVal;
                    qVal = int.Parse(q);
                    rVal = int.Parse(r);
                    Deft.Terrain terrain = (Deft.Terrain)Enum.Parse(typeof(Deft.Terrain), t);

                    //Instantiate in-game hexes
                    Vector2    hexCoords   = new Vector2(qVal, rVal);
                    Vector2    worldCoords = HexVectorUtil.worldPositionOfHexCoord(hexCoords);
                    GameObject hex         = Instantiate(hexPrefab, new Vector3(worldCoords.x, worldCoords.y, 1), Quaternion.identity);
                    hex.transform.SetParent(hexContainer);
                    WSHexManager hexManager = hex.GetComponent <WSHexManager>();
                    hexManager.TerrainSprite = terrain;

                    _hexGrid.Add(hexCoords, hexManager);
                } catch { }
            }
        }
コード例 #3
0
 public void SetExtensionTerrain(MEHexEntry hex)
 {
     extensionTerrainType = hex.Terrain;
 }