Forum rules - please read before posting.

Pan/Zoom of Menu Element graphics

Hi,

Sorry for this maybe complicated post that may be more Unity than AC, and that has connections with both https://adventurecreator.org/forum/discussion/7014/best-way-to-update-inventory-item-main-graphic
and
https://adventurecreator.org/forum/discussion/14517/pinch-zoom-and-panning-on-mobiles/p1

In Summary

  • I take screenshots that are saved as runtime textures for photos in Inventory items in a category "Photos"
  • The photos are viewed in an inventory box, and when clicked on, opens a new menu "PhotosNEW" that displays the clicked photo texture in a bigger format
  • The PhotosNEW panel where the large photo texture is displayed is done through
    Option 1: An inventory box that displays "last selected item"
    Option 2: A Graphic

Option 1 works great, until I zoom (i.e. Interact) with the Photo display Inventory box. It seems the Zoomed picture (now selected), although visually contained in the PhotosNEW panel, expands the screen and I cannot click on new pictures in the PictureInventory until I have zoomed back the picure to a smaller size as the zoomed picture is still the selected one. The PhotosNEW Canvas layer is set to 10, whereas the Picture Inventory Canvas layer is set to 100.

I can circumvent this by disabling interaction on the Button in a Start method, but when turning off/on the menu, interaction is back to enabled again. I've tried various codes to disable it, (OnEnable) of the menu UI etc., but it insists on being enabled.

Is there any way to have the Inventory Box element to link only to an image and not an interactable button or does it have to be a button to be able to zoom and pan?
Or is there a way to keep the zoomed image below the InventoryPhotos menu so that the InventoryItem from InventoryPhotos becomes the selected one when clicked on?
Or a way to deselect whichever item/photo is currently selected when ending a zoom/pan move?
Or a better solution for this?

I have tried to use Option 2, a graphic instead of an Inventory box, and set the graphics to the texture of the lastSelected item in the photo inventory, but I haven't got it to work.

Screenshots:
https://imgur.com/a/IZ9KYNB

The Zoom script is:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PhotoZoom : MonoBehaviour
{
    Vector3 touchStart;
    public float zoomOutMin = 1;
    public float zoomOutMax = 8;
    public float zoomSpeed = 0.001f;
    public RectTransform myPanel;

    // Update is called once per frame
    void Update()
    {
        Vector2 mousePosition = Input.mousePosition;
        if (RectTransformUtility.RectangleContainsScreenPoint(myPanel, mousePosition))
        {
            DoZoom();
        }
    }


    void DoZoom() 
    { 

            if (Input.GetMouseButtonDown(0))
        {
            touchStart = Camera.main.ScreenToWorldPoint(Input.mousePosition);
        }
        if (Input.touchCount == 2)
        {
            Touch touchZero = Input.GetTouch(0);
            Touch touchOne = Input.GetTouch(1);

            Vector2 touchZeroPrevPos = touchZero.position - touchZero.deltaPosition;
            Vector2 touchOnePrevPos = touchOne.position - touchOne.deltaPosition;

            float prevMagnitude = (touchZeroPrevPos - touchOnePrevPos).magnitude;
            float currentMagnitude = (touchZero.position - touchOne.position).magnitude;

            float difference = currentMagnitude - prevMagnitude;

            zoom(difference * zoomSpeed);
        }
        else if (Input.GetMouseButton(0))
        {
            Vector3 direction = touchStart - Camera.main.ScreenToWorldPoint(Input.mousePosition);
            gameObject.transform.position -= direction;
        }
        zoom(Input.GetAxis("Mouse ScrollWheel"));
    }

    void zoom(float increment)
    {
        float factor = Mathf.Clamp(gameObject.transform.localScale.x + increment, zoomOutMin, zoomOutMax);
        gameObject.transform.localScale = new Vector3(factor, factor, 0);
    }
}

Comments

  • Update:
    I added

                InvInstance myItem = KickStarter.runtimeInventory.SelectedInstance;
                myItem.Deselect();
    

    to the Zoomscript so at least it seems like I can select a new item from InventoryPhotos, but it is still as if the zoomed image is covering InventoryPhotos menu

  • Update:
    I managed to solve the above by a Send Message directly to the Photo Game Object Button to disable interaction. Before I tried to send the message to the UI Parent with the photo object as a public GameObject, but didn't work. Sending it directly to the game object works though... Not sure why, but all's well that end well!

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.