当前位置:网站首页>Unity 可缩放地图的制作
Unity 可缩放地图的制作
2022-06-11 04:11:00 【海 月】
架构
使用Scroll View装载Image
Content与Image初始大小与Panel一致,后续通过代码进行缩放

代码

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;
}
}注:加载图片到Scroll View的Content中去显示,要实现拖拽查看的效果,首先要让Content的初始大小与图片一致,这样才能保证图片的每一个地方都可以在拖拽后被看到。这里通过代码自动设定Content大小。
效果

边栏推荐
- JVM(1):介绍、结构、运行和生命周期
- Guanghetong won the "science and Technology Collaboration Award" of Hello travel, driving two rounds of green industries to embrace digital intelligence transformation
- Feature selection algorithm based on bare bones particleswarm optimization
- 写给通信年轻人的27个忠告
- Code replicates CSRF attack and resolves it
- Feature selection algorithm based on bare bones particleswarm optimization
- Market prospect analysis and Research Report of programmable digital temperature regulator in 2022
- Unity prefab scene 冲突合并工具 UnityYAMLMerge
- [customview] glide+bitmaptransformation picture upper and lower border wave processing (wavetransformation)
- Market prospect analysis and Research Report of nitrogen liquefier in 2022
猜你喜欢
随机推荐
Watson K's Secret Diary
QT日志模块的个性化使用
PHP regular use case
MySql索引
【服务器数据恢复】同友存储raid5崩溃的数据恢复案例
L'avenir est venu, l'ère 5G - Advanced s'ouvre
Guanghetong LTE Cat4 module l716 is upgraded to provide affordable and universal wireless applications for the IOT industry
A - Eddy's AC puzzle (C language)
Pictures that make people feel calm and warm
JVM (6): slot variable slot, operand stack, code trace, stack top cache technology
Embedded basic interface-i2s
Image detection related model data format
Rational use of thread pool and thread variables
Guanghetong 5g module fg650-cn and fm650-cn series are produced in full scale, accelerating the efficient implementation of 5g UWB applications
MySQL stored procedure
JVM(4):类的主动使用与被动使用、运行时数据区域内部结构、JVM线程说明、PC寄存器
SSLStrip 终极版 —— location 劫持
Eth relay interface
检测php网站是否已经被攻破的方法
Eth Transfer





![[laser principle and application-2]: key domestic laser brands](/img/55/a87169bb75429f323159e3b8627cc6.jpg)



