当前位置:
首页 > Python基础教程 >
-
C#教程之UGUI_关卡选项界面
1.Image组件—“Source Image”,Set Native Size.
2.Image组件—“Image Type”——Sliced
编辑要放大缩小的图片,Sprite Editor,采用九宫格切图。
3.创建空物体(作为父物体),添加Componment—Layout—Grid Layout Group(是下面的子物体自动排列)
创建空物体和创建Panel作为父物体是由区别的!
4.锚点问题,是GUI中容易忽视但却十分重要的点。
5.Prefabs的有效使用,后期通过更改Prefabs来进行完整的映射修改。
6.滚动图片列表的制作
(1)选项卡图标排列整齐
(2)创建一个Image组件—“背景图”,命名为ScrollPanel(作为父物体,作为Mask),此时将选项卡托至此背景图下作为子物体。
(3)在“背景图”上添加“Scroll Rect”滑动组建,Content对象为选项卡图标集合,来控制子物体。
(4)在“背景图”上添加"Mask"组建。
(5)按页数进行滑动(分页)脚本
(6)单选按钮,进入制定页面,并与鼠标滑动脚本相关联。
1 using System.Collections; 2 using System.Collections.Generic; 3 using UnityEngine; 4 using UnityEngine.EventSystems; 5 using UnityEngine.UI; 6 7 public class LevelButtonScrollRect : MonoBehaviour ,IBeginDragHandler,IEndDragHandler{ 8 9 // Use this for initialization 10 private ScrollRect scrollRect; 11 private float[] pageArrayFloats = new[] {0, 0.33333f, 0.66666f, 1}; 12 void Start () 13 { 14 scrollRect = GetComponent<ScrollRect>(); 15 } 16 17 // Update is called once per frame 18 void Update () { 19 20 } 22 public void OnBeginDrag(PointerEventData eventData) 23 { 24 25 } 27 public void OnEndDrag(PointerEventData eventData) 28 { 29 //Vector2 offsetTemp = scrollRect.normalizedPosition; 30 float offsetTemp = scrollRect.horizontalNormalizedPosition; 31 print(offsetTemp); 33 } 34 }
父物体添加过"ToggleGroup"组件
1 using System.Collections; 2 using System.Collections.Generic; 3 using UnityEditor; 4 using UnityEngine; 5 using UnityEngine.EventSystems; 6 using UnityEngine.UI; 7 8 public class LevelButtonScrollRect : MonoBehaviour ,IBeginDragHandler,IEndDragHandler{ 9 10 // Use this for initialization 11 private ScrollRect scrollRect; 12 private float[] pageArrayFloats = new[] {0, 0.33333f, 0.66666f, 1}; 13 private float targetHorizontalPosition = 0; //默认为第一页 14 private bool isDrag = false; 15 public float speed = 5f; 16 void Start () 17 { 18 scrollRect = GetComponent<ScrollRect>(); //寻找组件,物体间的通信 19 } 20 21 // Update is called once per frame 22 void Update () { 23 if (isDrag==false) 24 { 25 scrollRect.horizontalNormalizedPosition = Mathf.Lerp(scrollRect.horizontalNormalizedPosition, 26 targetHorizontalPosition, speed * Time.deltaTime); 27 } 28 } 29 30 public void OnBeginDrag(PointerEventData eventData) 31 { 32 isDrag = true; 33 } 34 35 public void OnEndDrag(PointerEventData eventData) 36 { 37 isDrag = false; 38 float posX = scrollRect.horizontalNormalizedPosition; 39 int index = 0; 40 float offset = Mathf.Abs(pageArrayFloats[index] - posX); 41 for (int i = 0; i < pageArrayFloats.Length; i++) 42 { 43 float offsetTemp = Mathf.Abs(pageArrayFloats[i] - posX); 44 if (offsetTemp < offset) 45 { 46 index = i; 47 offset = offsetTemp; 48 } 49 } //哪一页的位置与当前页的位置差最小,就定在哪一页上 50 //scrollRect.horizontalNormalizedPosition = pageArrayFloats[index]; 51 targetHorizontalPosition = pageArrayFloats[index]; 52 } 53 } 54 //注:最后一次鼠标滑动的位置是确定的,让这个位置与每一页的位置(4页的位置)比较,差值最小的,则固定在(4页位置)中的哪一页上 55 //多次判断语句,用到for循环(特别是for{if(){}})
栏目列表
最新更新
nodejs爬虫
Python正则表达式完全指南
爬取豆瓣Top250图书数据
shp 地图文件批量添加字段
爬虫小试牛刀(爬取学校通知公告)
【python基础】函数-初识函数
【python基础】函数-返回值
HTTP请求:requests模块基础使用必知必会
Python初学者友好丨详解参数传递类型
如何有效管理爬虫流量?
SQL SERVER中递归
2个场景实例讲解GaussDB(DWS)基表统计信息估
常用的 SQL Server 关键字及其含义
动手分析SQL Server中的事务中使用的锁
openGauss内核分析:SQL by pass & 经典执行
一招教你如何高效批量导入与更新数据
天天写SQL,这些神奇的特性你知道吗?
openGauss内核分析:执行计划生成
[IM002]Navicat ODBC驱动器管理器 未发现数据
初入Sql Server 之 存储过程的简单使用
这是目前我见过最好的跨域解决方案!
减少回流与重绘
减少回流与重绘
如何使用KrpanoToolJS在浏览器切图
performance.now() 与 Date.now() 对比
一款纯 JS 实现的轻量化图片编辑器
关于开发 VS Code 插件遇到的 workbench.scm.
前端设计模式——观察者模式
前端设计模式——中介者模式
创建型-原型模式