示例#1
0
    //TODO Create a User Control Script that delegates button/mouseclick/key presses

    // Waits for left click mouse on a Terrain Object to try to select a target
    void Update()
    {
        if (CrossPlatformInputManager.GetButtonDown("pointer1"))
        {
            if (Input.mousePosition.y > CardAreaRect.position.y + (CardAreaRect.sizeDelta.y / 2))
            {
                var hit = cameraRaycaster.RaycastForLayer(Layer.LevelTerrain);
                if (hit.HasValue)
                {
                    m_hit = hit.Value;
                    OnItemSelect(m_hit.transform);
                    return;
                }
            }
            else
            {
                //Unselect if click in the card area
                if (gameController.getSelectedObject != null)
                {
                    gameController.deSelectObject();
                }
            }
        }
    }
    void OnCurrentObjectStateChange(CardState state)
    {
        ResetTiles();
        var hit = cameraRaycaster.RaycastForLayer(Layer.LevelTerrain);

        switch (selectedCardObject.cardState)
        {
        case CardState.Move:
            selectedCardObject.GetCurrentTile.ChangeColor(Color.blue);
            Range = selectedCardObject.FindMoveRange();
            foreach (EnviromentTile tile in Range)
            {
                tile.ChangeColor(Color.cyan);
            }

            if (hit.HasValue)
            {
                RaycastHit m_hit;
                m_hit = hit.Value;
                // Check if their is another object on the tile/ if the tile is open
                if (m_hit.transform.GetComponent <EnviromentTile>().cardType == CardType.Open)
                {
                    if (Path != null)
                    {
                        foreach (EnviromentTile tile in Path)
                        {
                            if (Range.Contains(tile))
                            {
                                tile.ChangeColor(Color.cyan);
                            }
                            else
                            {
                                tile.ChangeColor(tile.MatColorOriginal);
                            }
                        }
                    }
                    Path = selectedCardObject.MakePath(m_hit.transform.GetComponent <EnviromentTile>());
                    foreach (EnviromentTile tile in Path)
                    {
                        tile.ChangeColor(Color.blue);
                    }
                }
            }


            break;

        case CardState.Attack:
            selectedCardObject.GetCurrentTile.ChangeColor(Color.red);
            Range = selectedCardObject.FindAttackRange();
            foreach (EnviromentTile tile in Range)
            {
                tile.ChangeColor(Orange);
            }
            if (hit.HasValue)
            {
                RaycastHit m_hit;
                m_hit = hit.Value;
                // Check if their is another object on the tile/ if the tile is open
                if (m_hit.transform.GetComponent <EnviromentTile>().cardType == CardType.Open || m_hit.transform.GetComponent <EnviromentTile>().cardType == CardType.Enemy)
                {
                    //  Debug.Log("Looking");
                    if (selectedCardObject.CheckAttackInRange(m_hit.transform.GetComponent <EnviromentTile>(), Range))
                    {
                        m_hit.transform.GetComponent <EnviromentTile>().ChangeColor(Color.red);
                    }
                }
            }

            break;

        default:
            return;
        }
    }