예제 #1
0
    void Dragging()
    {
        Ray        cameraRay = _currentCamera.ScreenPointToRay(Input.mousePosition);
        RaycastHit hit;

        if (Physics.Raycast(cameraRay, out hit, float.PositiveInfinity, ~LayerMask.GetMask("Cube")))
        {
            transform.position = hit.point + Vector3.up * 0.5f;
            _currentOnCell     = BaseCellPlane.GetCell(BaseCellPlane.ToGridPosition(hit.point));
            if (!_currentOnCell)
            {
                return;
            }

            _highLightObj.gameObject.SetActive(true);
            _highLightObj.transform.position = _currentOnCell.WorldPosition + Vector3.up * 0.001f;

            _highLightObj.material.color =
                _currentOnCell.CanBuildBuilding && _currentOnCell.Building == null ?
                _buildableHighLightColor :
                _unbuildableHighLightColor;
        }
        else
        {
            transform.position = _currentCamera.ScreenToWorldPoint(Input.mousePosition + Vector3.forward);
            _highLightObj.gameObject.SetActive(false);
            _currentOnCell = null;
        }
    }
    bool outOfRange(Vector2Int position)
    {
        Vector3    leftBottomObjPos = BaseCellPlane.getLeftBottomCell().transform.position;
        Vector3    rightTopObjPos   = BaseCellPlane.getRightTopCell().transform.position;
        Vector3    gridSize         = (rightTopObjPos - leftBottomObjPos) / cellSize;
        Vector2Int gridSizeInt      = new Vector2Int(
            Mathf.RoundToInt(gridSize.x),
            Mathf.RoundToInt(gridSize.z));
        Vector2Int leftBottomObjGridPos = BaseCellPlane.ToGridPosition(leftBottomObjPos);
        Vector2Int rightTopObjGridPos   = BaseCellPlane.ToGridPosition(rightTopObjPos);

        if ((position.x - leftBottomObjGridPos.x) > gridSizeInt.x || (position.y - leftBottomObjGridPos.y) > gridSizeInt.y ||
            Mathf.Abs((position.x - rightTopObjGridPos.x)) > gridSizeInt.x || Mathf.Abs((position.y - rightTopObjGridPos.y)) > gridSizeInt.y)
        {
            return(true);
        }

        return(false);
    }
예제 #3
0
    public static float Calculate(Building building)
    {
        float            score       = 0;
        Vector2Int       position    = BaseCellPlane.ToGridPosition(building.transform.position);
        List <Component> checkedList = new List <Component>();

        checkedList.Add(building);
        checkedList.Add(BaseCellPlane.GetCell(position));

        for (int i = 0; i < Instance.isCellTypeChecked.Length; i++)
        {
            Instance.isCellTypeChecked[i] = false;
        }

        Instance.GetScores(position, building, 0, checkedList, ref score);
        Instance.totalScore    += score;
        Instance.scoreText.text = Instance.totalScore.ToString();

        print(Instance.totalScore);
        return(score);
    }
 private void Update()
 {
     position = BaseCellPlane.ToGridPosition(GetComponent <Building>().transform.position);
     InstanceHighLightObjs(0, rangeBuildingSet, position, highLightObj);
 }