Exemple #1
0
    /* --------------------------------------------------------------------- */

    #region Construction

    #endregion

    /* --------------------------------------------------------------------- */

    #region Unity Methods

    /// <summary>
    /// Unity Start event handler.
    /// </summary>
    void Start()
    {
        this._distanceFromPivot = Vector3.Distance(Vector3.up * Camera.main.transform.position.y, Camera.main.transform.position);
        Debug.Log(_distanceFromPivot);

        this._hexes = new List <BattleHex>();

        this._battleMouse    = GetComponent <BattleMouse>();
        this._battleKeyboard = GetComponent <BattleKeyboard>();

        float halfLength = 1;// / (float)Math.Cos( 30 * Math.PI / 180d );
        float fullLength = 2 * halfLength;

        Point2D gridSize = new Point2D(12, 9);
        Dictionary <Point2D, BattleHex> hexGrid = new Dictionary <Point2D, BattleHex>();

        this._turnManager = FindObjectOfType <TurnManager>();

        this._units        = FindObjectsOfType <ControllableUnit>().ToList();
        this._player2Units = FindObjectsOfType <AIControlledUnit>().ToList();

        for (int y = 0; y < gridSize.Y; y++)
        {
            int sizeX = gridSize.X;

            if (y % 2 != 0 && (gridSize.X + 0.5f) * fullLength > 10f)
            {
                --sizeX;
            }

            for (int x = 0; x < sizeX; x++)
            {
                GameObject hex          = (GameObject)Instantiate(this._hexTemplate);
                BattleHex  hexComponent = hex.GetComponent <BattleHex>();
                hexComponent.Configure(x, y, gridSize, fullLength, transform.gameObject);

                hexGrid.Add(new Point2D(x, y), hexComponent);
                this._hexes.Add(hexComponent);
            }
        }

        foreach (var hexItem in hexGrid)
        {
            hexItem.Value.FindNeighbours(hexGrid);
        }

        int index = 0;

        for (int i = 0; i < this._units.Count; i++)
        {
            ControllableUnit unit = _units[i];

            unit.InitialiseWithTile(this, _hexes[index], 90f);

            index += gridSize.X - i % 2;
        }

        for (int i = 0; i < this._player2Units.Count; i++)
        {
            this._player2Units[i].InitialiseWithTile(this, this._hexes[this._hexes.Count - i - 1], 270f);
        }

        this._turnManager.FinishTurn();
    }