コード例 #1
0
    public void Hide()
    {
        gameObject.SetActive(false);

        m_orientedImage.texture = null;
        cropCallback            = null;
        imageResizePolicy       = null;
    }
コード例 #2
0
    public void Show(Texture image, CropResult onCrop, Settings settings = null, ImageResizePolicy croppedImageResizePolicy = null)
    {
        if (image == null)
        {
            Debug.LogError("Image is null!");
            return;
        }

        if (!gameObject.activeSelf)
        {
            gameObject.SetActive(true);
        }

        cropCallback      = onCrop;
        imageResizePolicy = croppedImageResizePolicy;

        if (settings == null)
        {
            settings = DefaultSettings;
        }

        m_orientedImage.texture = image;

        m_originalImageSize = new Vector2(image.width, image.height);
        orientedImageTransform.sizeDelta = m_originalImageSize;

        MarkTextureNonReadable = settings.markTextureNonReadable;
        OvalSelection          = settings.ovalSelection;
        GuidelinesVisibility   = settings.guidelinesVisibility;
        ImageBackground        = settings.imageBackground;

        minAspectRatio = settings.selectionMinAspectRatio;
        maxAspectRatio = settings.selectionMaxAspectRatio;

        if (minAspectRatio <= 0f)
        {
            minAspectRatio = 1E-6f;
        }
        if (maxAspectRatio <= 0f)
        {
            maxAspectRatio = 1E6f;
        }

        if (minAspectRatio > maxAspectRatio)
        {
            float temp = minAspectRatio;
            minAspectRatio = maxAspectRatio;
            maxAspectRatio = temp;
        }

        minSize = settings.selectionMinSize;
        maxSize = settings.selectionMaxSize;

        Vector2 maxSizeDefault = new Vector2(2f, 2f) * Mathf.Max(m_originalImageSize.x, m_originalImageSize.y);

        if (minSize.x < 1f || minSize.y < 1f)
        {
            minSize = new Vector2(0.1f, 0.1f) * Mathf.Min(m_originalImageSize.x, m_originalImageSize.y);
        }
        if (maxSize.x < 1f || maxSize.y < 1f)
        {
            maxSize = maxSizeDefault;
        }

        minSize = minSize.ClampBetween(Vector2.one, Vector2.one * Mathf.Max(m_originalImageSize.x, m_originalImageSize.y));
        maxSize = maxSize.ClampBetween(minSize, maxSizeDefault);

        m_autoZoomEnabled = false;
        SetOrientation(settings.initialOrientation);

        m_autoZoomEnabled       = settings.autoZoomEnabled;
        m_pixelPerfectSelection = settings.pixelPerfectSelection;

        flipHorizontalButton.SetActive((settings.visibleButtons & Button.FlipHorizontal) == Button.FlipHorizontal);
        flipVerticalButton.SetActive((settings.visibleButtons & Button.FlipVertical) == Button.FlipVertical);
        rotate90DegreesButton.SetActive((settings.visibleButtons & Button.Rotate90Degrees) == Button.Rotate90Degrees);

        Vector2 paddingMax = new Vector2(1f - Mathf.Clamp01(settings.selectionInitialPaddingRight), 1f - Mathf.Clamp01(settings.selectionInitialPaddingTop));
        Vector2 paddingMin = new Vector2(Mathf.Clamp(settings.selectionInitialPaddingLeft, 0f, paddingMax.x), Mathf.Clamp(settings.selectionInitialPaddingBottom, 0f, paddingMax.y));

        UpdateSelection(Vector2.zero, m_orientedImageSize.ScaleWith(paddingMax - paddingMin));
        m_selection.anchoredPosition = (m_orientedImageSize - m_selection.sizeDelta) * 0.5f;
        if (m_pixelPerfectSelection)
        {
            MakePixelPerfectSelection();
        }

        ResetView(false);
    }