当前位置:网站首页>Production of unity scalable map

Production of unity scalable map

2022-06-11 04:21:00 Sea moon

framework

Use Scroll View load Image

Content And Image Initial size vs Panel Agreement , Then zoom through the code

Code

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

public class MapPanelManager : MonoBehaviour
{
    public Slider scaleSlider;
    public RectTransform contentOfMap;

    public void SetMapScale(Slider slider)
    {
        float scaleFactor = slider.value;
        contentOfMap.localScale = new Vector3(scaleFactor, scaleFactor, 1);
    }

    public void OnEnable()
    {
        scaleSlider.value = contentOfMap.localScale.x;
        contentOfMap.sizeDelta = contentOfMap.transform.GetChild(0).GetComponent<RectTransform>().sizeDelta;
    }
}

notes : Load picture to Scroll View Of Content Medium to display , To achieve the effect of dragging and dropping , First of all, let Content The initial size of is the same as the picture , In this way, you can ensure that every part of the picture can be seen after dragging . Here, it is automatically set by code Content size .

  effect

原网站

版权声明
本文为[Sea moon]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/162/202206110411058313.html