// Try to select a shovel at mouse postions.
    // If will return true and the shovel as a parameter is a shovel is found
    // it will return false otherwise
    public bool TrySelectShovelAtMousePosition(out ShovelVisual shovelVisual)
    {
        Ray pickRay = _camera.ScreenPointToRay(Input.mousePosition);

        RaycastHit hit;

        if (Physics.Raycast(pickRay, out hit))
        {
            shovelVisual = hit.transform.gameObject.GetComponent <ShovelVisual>();

            return(shovelVisual != null);
        }

        shovelVisual = null;
        return(false);
    }
Esempio n. 2
0
    private void Update()
    {
        if (_applicationFailed)
        {
            return;
        }

        if (!_applicationStarted)
        {
            if (_dataRetrievingFuture != null && _dataRetrievingFuture.Completed)
            {
                if (_dataRetrievingFuture.Success)
                {
                    // If the application finished all the web request tasks start the application.
                    BeginApplication();
                }
                else
                {
                    _uiManager.ShowLoadingPanel(false);

                    // In case that something went wrong in the initialization show all the errors in the logs and stop the application.

                    Debug.LogError("Initialization Failed!");
                    Debug.LogError("Failure Actions:");
                    foreach (var reason in _dataRetrievingFuture.FailureReasons)
                    {
                        Debug.LogError("-> " + reason);
                    }

                    Debug.LogWarning("Success Actions:");
                    foreach (var action in _dataRetrievingFuture.CompletedActions)
                    {
                        Debug.LogWarning("-> " + action);
                    }
                    _applicationFailed = true;
                }
            }
        }
        else
        {
            // Try to select a shovel when mouse button is donw.
            if (Input.GetMouseButtonDown(0))
            {
                // Do not consider click in UI
                if (!EventSystem.current.IsPointerOverGameObject())
                {
                    // Select a shovel and unselect the last selected shovel.
                    if (_cameraController.TrySelectShovelAtMousePosition(out ShovelVisual shovel))
                    {
                        if (_selectedShovel != null)
                        {
                            _selectedShovel.SetSelected(false);
                            _selectedShovel = null;
                        }

                        _uiManager.ShowInfoPanel(true, shovel.ShovelData);

                        _selectedShovel = shovel;
                        _selectedShovel.SetSelected(true);
                    }
                    else
                    {
                        if (_selectedShovel != null)
                        {
                            _selectedShovel.SetSelected(false);
                            _selectedShovel = null;
                        }
                        _uiManager.ShowInfoPanel(false);
                    }
                }
            }
        }
    }