Beispiel #1
0
    public void AddUnit(HexUnit unit, HexCell location)
    {
        cellShaderData.ImmediateMode = true;
        units.Add(unit);
        unit.Grid = this;
        unit.transform.SetParent(transform, false);
        unit.Location                = location;
        unit.Orientation             = Random.Range(0f, 360f);
        cellShaderData.ImmediateMode = false;

        if (unit.Owned)
        {
            HexMapCamera.SetPosition(unit.Location);
        }
    }
    public void UseItem(HexItemType type)
    {
        switch (type)
        {
        case HexItemType.Poison:
            otherUnit.SpeedEffect(-20, 3);
            SendEffect(HexItemType.Poison);
            break;

        case HexItemType.FakeTreasureItem:
            AddItem(HexItemType.FakeTreasure, myUnit.Location);
            SendItem(HexItemType.FakeTreasure, myUnit);
            break;

        case HexItemType.Change:
            grid.changeUnits();
            HexMapCamera.SetPosition(myUnit.Location);
            SendEffect(HexItemType.Change);
            break;
        }
    }
    void DoTurn()
    {
        if (myTurn)
        {
            second += Time.deltaTime;

            if (endTurn || second > turnTime)
            {
                myTurn = false;
                SendTurn();
            }
            ui.StartCounting(second / turnTime);
            ui.EnergyCounting(myUnit.Speed);

            SendScore();
        }

        if (ItemInfo.Synced)
        {
            AddItem((HexItemType)ItemInfo.ItemType, grid.GetCell(ItemInfo.CellIndex));

            ItemInfo.Synced = false;
        }

        if (RemoveItemInfo.Synced)
        {
            Log.Dev(GetType(), "remove item at cell index: " + RemoveItemInfo.CellIndex.ToString());

            grid.RemoveItem(RemoveItemInfo.CellIndex);
            RemoveItemInfo.Synced = false;
        }

        if (EffectInfo.Synced)
        {
            switch ((HexItemType)EffectInfo.ItemIype)
            {
            case HexItemType.Poison:
                myUnit.SpeedEffect(-20, 3);
                break;

            case HexItemType.Change:
                grid.changeUnits();
                HexMapCamera.SetPosition(myUnit.Location);
                break;
            }

            EffectInfo.Synced = false;
        }

        if (ScoreInfo.Synced)
        {
            if (ScoreInfo.IsServer)
            {
                serverUnit.Score = ScoreInfo.Score;
            }
            else
            {
                clientUnit.Score = ScoreInfo.Score;
            }

            ScoreInfo.Synced = false;
        }

        ui.MyScore(myUnit.Score);
        ui.OtherScore(otherUnit.Score);
    }
    void Update()
    {
        if (!EventSystem.current.IsPointerOverGameObject())
        {
            if (HexGameController.myTurn && !myUnit.isTraveling)
            {
                DoPathfinding();
                if (Input.GetMouseButtonDown(1))
                {
                    DoMove();
                }
            }
            else
            {
                currentCell = null;
            }
        }

        if (Input.GetKeyDown("space"))
        {
            myUnit.Jump();
            photonView.RPC("GetJump", RpcTarget.Others, true);
        }

        // center camera to myUnit position
        if (Input.GetKeyDown(KeyCode.C))
        {
            HexMapCamera.SetPosition(myUnit.Location);
        }

        // toggle camera following
        if (Input.GetKeyDown(KeyCode.V))
        {
            following = !following;
            if (following)
            {
                HexMapCamera.SetPosition(myUnit.Location);
                switchToFollowing = true;
            }
        }

        // move camera
        if (switchToFollowing)
        {
            if (HexMapCamera.GetLocalPosition() == myUnit.transform.localPosition)
            {
                switchToFollowing = false;
            }
        }
        else if (following)
        {
            HexMapCamera.SetPosition(myUnit.transform.localPosition, true);
        }
        else
        {
            HexMapCamera.Move();
        }

        // networking
        if (otherUnit)
        {
            if (UnitInfo.newPath)
            {
                DoMove(UnitInfo.Path);
                UnitInfo.newPath = false;
            }

            if (UnitInfo.Jump)
            {
                otherUnit.Jump();
                UnitInfo.Jump = false;
            }
        }
    }
    public void SetCameraPosition(int cellIndex)
    {
        HexCell current = hexGrid.GetCell(cellIndex);

        hexCamera.SetPosition(current);
    }