Example #1
0
    private void MainMenu()
    {
        GUI.Label(new Rect(0, 0, 100, 20), "New Board");
        if (GUI.Button(new Rect(110, 0, 100, 20), "Build"))
        {
            _state      = State.New;
            _boardModel = new HexBoardModel();
            return;
        }

        GUI.Label(new Rect(0, 25, 100, 20), "Load Board");
        int selected = EditorGUI.Popup(new Rect(110, 25, 100, 20), _fileToLoadIndex, _hexBoardFiles.ToArray());

        if (selected != _fileToLoadIndex)
        {
            _fileToLoadIndex = selected;
            if (_fileToLoadIndex != 0)
            {
                string fileName = _hexBoardFiles[_fileToLoadIndex].text;
                _boardModel = LoadHexBoard(fileName);
            }
        }

        if (_fileToLoadIndex != 0)
        {
            if (GUI.Button(new Rect(220, 25, 100, 20), "Load"))
            {
                _fileToLoadIndex = 0;
                _state           = State.Edit;
                return;
            }
        }
    }
Example #2
0
    //---- Public
    //-----------
    public void BuildHexBoardFromModel(HexBoardModel model)
    {
        if (_tiles != null && _tiles.Count > 0)
        {
            Clean();
        }

        _boardModel = model;
        _tiles      = new List <HexTile>(model.HexTileModels.Count);
        for (int i = 0; i < _boardModel.HexTileModels.Count; i++)
        {
            HexTileModel modelData = _boardModel.HexTileModels[i];
            Texture      texture   = Preferences.Textures[modelData.TextureName];
            Material     material  = Preferences.Materials[modelData.MaterialName];
            HexTile      hex       = Instantiate <HexTile>(Preferences.Prefab, Board.transform);
            hex.name  = "Tile_" + i;
            hex.Model = modelData;
            hex.View.SetMaterial(material);
            hex.View.SetTexture(texture);
            hex.transform.localPosition = modelData.Position.Convert();
            hex.transform.localRotation = Quaternion.Euler(modelData.Rotation.Convert());
            hex.transform.localScale    = modelData.Scale.Convert();
            _tiles.Add(hex);
        }

        CenterCamera();
    }
Example #3
0
 private void ExitEdit()
 {
     _boardTool.Clean();
     _initBoard       = false;
     _isEdit          = false;
     _boardModel      = null;
     _orginalFileName = string.Empty;
 }
Example #4
0
    private void Start()
    {
        _preferences = _hexBoard.Preferences;
        HexBoardModel hexBoardModel = JsonLoader.Parse <HexBoardModel>(Application.dataPath + _preferences.HexBoardPath + FileToLoad);

        _hexBoard.Model = hexBoardModel;
        _hexBoard.Controller.CreateBoard();
    }
Example #5
0
    //---- Private
    //------------
    private void LoadBoard()
    {
        HexBoardModel hexBoardModel = JsonLoader.Parse <HexBoardModel>(Application.dataPath + HexPreferences.HexBoardPath + BoardToLoad);

        if (hexBoardModel == null)
        {
            Debug.LogError("Unable to load HexBoard at " + Application.dataPath + HexPreferences.HexBoardPath + BoardToLoad);
        }
        _hexBoard.Model = hexBoardModel;
        _hexBoard.Controller.CreateBoard();
    }
Example #6
0
    private void BuildPointy(HexBoardModel model, HexTileModel tile, float width, float height, int index, ref int col, ref int row, ref float offset)
    {
        if (col >= model.Size.X)
        {
            offset += height;
            col     = 0;
            ++row;
        }

        tile          = model.HexTileModels[index];
        tile.Position = (row & 1) == 1 ? new Point3((col * width * 2) + width, 0, offset) :
                        new Point3(col * width * 2, 0, offset);
        Point3 rotation = new Point3(0, 30, 0);

        tile.Rotation = rotation;
        ++col;
    }
Example #7
0
    private void BuildHexBoard(HexBoardModel model)
    {
        if (_hexTilePreferences == null)
        {
            LoadPreference();
        }
        int   size = (int)(model.Size.X * model.Size.Y);
        float w, h;

        if (model.Layout == HexLayout.Flat)
        {
            w = _hexTilePreferences.SizeX * model.Scale.X;
            h = _hexTilePreferences.SizeY * model.Scale.Z;
        }
        else
        {
            w = _hexTilePreferences.SizeY * model.Scale.X;
            h = _hexTilePreferences.SizeX * model.Scale.Z;
        }
        int   col    = 0;
        int   row    = 0;
        float offset = 0;

        for (int i = 0; i < size; i++)
        {
            HexTileModel tile = model.HexTileModels[i];
            if (model.Layout == HexLayout.Flat)
            {
                BuildFlat(model, tile, w, h, i, ref col, ref row, ref offset);
            }
            else
            {
                BuildPointy(model, tile, w, h, i, ref col, ref row, ref offset);
            }
        }
    }
Example #8
0
    private void NewBoard()
    {
        GUI.Label(new Rect(0, 0, 300, 20), "New Board", EditorStyles.boldLabel);

        // Name
        GUI.Label(new Rect(0, 25, 100, 20), "Board ID");
        string name = EditorGUI.DelayedTextField(new Rect(100, 25, 100, 20), _boardModel.ID);

        if (name != _boardModel.ID)
        {
            _boardModel.ID = name;
        }

        // Size
        GUI.Label(new Rect(0, 50, 100, 20), "Size");
        GUI.Label(new Rect(0, 75, 50, 20), "Width:");
        float w = EditorGUI.DelayedFloatField(new Rect(55, 75, 50, 20), _boardModel.Size.X);

        if (w != _boardModel.Size.X)
        {
            _boardModel.Size.X = w;
        }
        GUI.Label(new Rect(110, 75, 50, 20), "Height:");
        float h = EditorGUI.DelayedFloatField(new Rect(165, 75, 50, 20), _boardModel.Size.Y);

        if (h != _boardModel.Size.Y)
        {
            _boardModel.Size.Y = h;
        }

        // Scale
        GUI.Label(new Rect(0, 100, 100, 20), "Hex Scale");
        GUI.Label(new Rect(0, 125, 20, 20), "X:");
        float x = EditorGUI.DelayedFloatField(new Rect(21, 125, 50, 20), _boardModel.Scale.X);

        if (x != _boardModel.Scale.X)
        {
            _boardModel.Scale.X = x;
        }
        GUI.Label(new Rect(80, 125, 20, 20), "Y:");
        float y = EditorGUI.DelayedFloatField(new Rect(101, 125, 50, 20), _boardModel.Scale.Y);

        if (y != _boardModel.Scale.Y)
        {
            _boardModel.Scale.Y = y;
        }
        GUI.Label(new Rect(160, 125, 20, 20), "Z:");
        float z = EditorGUI.DelayedFloatField(new Rect(181, 125, 50, 20), _boardModel.Scale.Z);

        if (z != _boardModel.Scale.Z)
        {
            _boardModel.Scale.Z = z;
        }

        // Layout
        GUI.Label(new Rect(0, 150, 100, 20), "Hex Layout", EditorStyles.boldLabel);
        System.Enum selected = EditorGUI.EnumPopup(new Rect(105, 150, 100, 20), _boardModel.Layout);
        if ((HexLayout)selected != _boardModel.Layout)
        {
            _boardModel.Layout = (HexLayout)selected;
        }

        // Edit Button
        if (ValidateModel())
        {
            if (GUI.Button(new Rect(0, 175, 100, 20), "Edit Board"))
            {
                _state = State.Edit;
            }

            if (GUI.Button(new Rect(105, 175, 100, 20), "Return"))
            {
                _boardModel = null;
                _state      = State.MainMenu;
            }
        }
        else
        {
            if (GUI.Button(new Rect(0, 175, 100, 20), "Return"))
            {
                _boardModel = null;
                _state      = State.MainMenu;
            }
        }
    }