コード例 #1
0
ファイル: CurrentTile.cs プロジェクト: imaqtpony/RTS_Proto
 //Send tile pos when triggered
 protected void OnTriggerEnter(Collider p_other)
 {
     if (p_other.CompareTag("Tile"))
     {
         m_onFetchTileEvnt.Raise(p_other.gameObject.transform.position);
     }
 }
コード例 #2
0
    //private void OnEnable()
    //{
    //    // set to ignore raycast (2)
    //    //m_ignoreRaycastMask = 2;
    //    //invert bitmask to hit anything but ignoreraycastmask
    //    m_ignoreRaycastMask = ~m_ignoreRaycastMask;

    //    if (m_onReturnTile != null)
    //        m_onReturnTile.Register(HandleGetTile);
    //}

    //private void OnDisable()
    //{
    //    if (m_onReturnTile != null)
    //        m_onReturnTile.Unregister(HandleGetTile);
    //}


    /// <summary>
    /// updates the m_nextTile var, called when the unit is checking the next tile to move in
    /// </summary>
    /// <param name="index"> send in index </param>
    protected void UpdateNextTile(int index)
    {
        m_onFetchFromIndex.Raise(index, TileType.ADJACENT);
    }
コード例 #3
0
    /// <summary>
    /// If the mouse hovers the game zone collider, a clic enters the onmousedown
    /// </summary>
    private void OnMouseOver()
    {
        //bool pressed = Input.GetMouseButtonUp(1);

        if (Input.GetMouseButtonDown(0) || Input.GetMouseButtonDown(1))
        {
            //Debug.Log(m_currentSelectedUnit.obj);
            gameObject.layer = 2;

            Ray castPoint = Camera.main.ScreenPointToRay(Input.mousePosition);

            if (Physics.Raycast(castPoint, out RaycastHit hit, Mathf.Infinity, m_ignoreRaycastMask))
            {
                //Debug.Log(hit.collider.gameObject.transform.position);
                //Debug.Log(hit.collider.gameObject.name);


                //Whichever clic = raise
                if (hit.collider.gameObject.CompareTag("Tile"))
                {
                    // raise the pos of the tile being hit to determine clicked tile
                    m_onFetchTileEvnt.Raise(hit.collider.gameObject.transform.position, TileType.CLICKED, string.Empty);

                    //if its a tile, current unit moves to this on rightclic
                    if (Input.GetMouseButtonDown(1))
                    {
                        m_onMoveUnit.Raise(TileType.CLICKED);
                    }
                }
                else if (hit.collider.gameObject.CompareTag("Player"))
                {
                    // else, update the selected unit
                    for (int i = 0; i < m_nbUnits; i++)
                    {
                        if (hit.collider.gameObject == m_unitsList[i].obj)
                        {
                            if (m_currentSelectedUnit.unitScript != null)
                            {
                                m_currentSelectedUnit.unitScript.m_isSelected = false;
                            }
                            m_unitsList[i].unitScript.m_isSelected = true;
                            m_currentSelectedUnit = m_unitsList[i];
                        }
                    }
                }
                else if (hit.collider.gameObject.CompareTag("Opponent"))
                {
                    // attack opponent
                    //move until range
                    //resolve attack
                    if (Input.GetMouseButtonDown(1))
                    {
                        //still raise as if it was a tile because in this case the unit will move to the nearest tile to attack this
                        m_onFetchTileEvnt.Raise(hit.collider.gameObject.transform.position, TileType.ATTACKED, string.Empty);

                        m_onMoveUnit.Raise(TileType.ATTACKED);
                    }
                }
            }
        }
    }