public void SetImageTexture(string filename, Texture2D texture, TextureValidationResult result)
    {
        SelectedFilenameField.text = filename;

        _hasLoadedValidHeightmap = (result == TextureValidationResult.Ok) && (texture != null);

        switch (result)
        {
        case TextureValidationResult.Ok:
            break;

        case TextureValidationResult.NotMinimumRequiredDimensions:
            InvalidImageText.text = "Loaded image doesn't met minimum dimensions...";
            break;

        case TextureValidationResult.InvalidColorPallete:
            InvalidImageText.text = "Loaded image is not grayscale...";
            break;

        case TextureValidationResult.Unknown:
            InvalidImageText.text = "Unknown error trying to load image...";
            break;

        default:
            throw new System.Exception("Unhandled Texture Validation Result: " + result);
        }

        if (_hasLoadedValidHeightmap)
        {
            Sprite sprite = Sprite.Create(
                texture,
                new Rect(0, 0, texture.width, texture.height),
                new Vector2(0.5f, 0.5f));

            HeightmapImage.sprite = sprite;
        }
        else
        {
            HeightmapImage.sprite = null;
        }

        InvalidImageText.gameObject.SetActive(!_hasLoadedValidHeightmap);
        GenerateButton.interactable = _hasLoadedValidHeightmap;
    }
示例#2
0
    /// <summary>Loads the heightmap.</summary>
    private void LoadHeightmapAction()
    {
        string    path    = LoadFileDialogPanelScript.GetPathToLoad();
        Texture2D texture = Manager.LoadTexture(path);

        if (texture == null)
        {
            SetSeedDialogPanelScript.SetImageTexture(Path.GetFileName(path), null, TextureValidationResult.Unknown);
        }
        else
        {
            TextureValidationResult result = Manager.ValidateTexture(texture);

            SetSeedDialogPanelScript.SetImageTexture(Path.GetFileName(path), texture, result);
        }

        _heightmap = texture;

        SetSeedDialogPanelScript.SetVisible(true);
    }