当前位置:网站首页>UGUI - Events, iTween Plugin
UGUI - Events, iTween Plugin
2022-08-10 08:13:00 【small digital media member】
Expected within two or three days,做2048game and a small block game written by yourself~look forward to it!
每日一句:Game production is a gentle ideal that I want to hide under the publicity
目录
UGUI Draw Calls优化精灵图集 - Unity 手册
UGUI事件
事件注册:
·通过编辑器绑定方法
·AddListener
void Start()
{ Button btn=this.transform.Find(“Button”).GetComponent<Button>();
btn.onClick.AddListener(方法名);//无参数、返回值的方法
//public delegate void UnityAction();}
·实现接口
拖拽类:
IBeginDragHandlerThe first frame of dragging is executed
IDragHandlerExecuted every frame of the drag
IEndDragHandler(先)End drag and drop execution
IDropHandler(后)
鼠标指针类
IPointerEnterHandler
IPointerExitHandlerThe cursor leaves the execution
IPointerDownHandler
IPointerUpHandler
IPointerClickHandler
点选类
IUpdateSelectedHanderClick to select Execute every frame
ISelectHanderSelect a frame to execute
IDeselectHanderThe frame that is not selected is executed
输入类 Based on point and click
IScrollHandler 选中UI,在UICalled when the mouse wheel is scrolled up
IMoveHandler 移动
ISubmitHandler 敲回车
ICancelHandler 按Esc
public class NewBehaviourScript : MonoBehaviour,IDragHandler
{
//当拖拽时执行
public void OnDrag(PointerEventData eventData)
{
//eventData.position:光标位置(屏幕坐标)
//仅仅适用于overlay模式
//his.transform.position = eventData.position;
//Canvas Render ModeAny mode is used——>
//Convert screen coordinates to object world coordinates
RectTransform parentRTF = this.transform.parent as RectTransform;
Vector3 worldPos;
//(Transform component of the parent object,屏幕坐标,摄像机,out 世界坐标)
RectTransformUtility.ScreenPointToWorldPointInRectangle
(parentRTF, eventData.position, eventData.pressEventCamera, out worldPos);
this.transform.position = worldPos;
}
}
要求:Where is the point and where is the coordinate to move
using UnityEngine;
using UnityEngine.EventSystems;
public class NewBehaviourScript : MonoBehaviour,IPointerDownHandler,IDragHandler
{
Vector3 offset;//记录从按下点到中心点偏移量(坐标)
Vector3 worldPos;
public void OnPointerDown(PointerEventData eventData)
{
RectTransform parentRTF = this.transform.parent as RectTransform;
//(Transform component of the parent object,屏幕坐标,摄像机,out 世界坐标)
RectTransformUtility.ScreenPointToWorldPointInRectangle
(parentRTF, eventData.position, eventData.pressEventCamera, out worldPos);
offset = this.transform.position - worldPos;
}
//当拖拽时执行
public void OnDrag(PointerEventData eventData)
{
RectTransform parentRTF = this.transform.parent as RectTransform;
Vector3 worldPos;
//(Transform component of the parent object,屏幕坐标,摄像机,out 世界坐标)
RectTransformUtility.ScreenPointToWorldPointInRectangle
(parentRTF, eventData.position, eventData.pressEventCamera, out worldPos);
this.transform.position = worldPos+offset;
}
}
·自定义框架
iTween动画库
目的:以最小的投入实现最大的产出,Easily achieve various animation shakes、旋转、movement and fading
物体移动 MoveTo 颜色渐变ColorTo
物体淡入淡出FadeTo
摄像机淡入淡出CameraFadeAdd CameraFadeTo
注视旋转LookTo 物体旋转RotateTo
物体缩放 ScaleTo
晃动 PunchPosition PunchRotation PunchScale
震动 ShakePosition ShakeRotation ShakeScale
//缓动曲线
public Transform imgTF, btnTF;
public iTween.EaseType type;
private void Start()
{
//iTween.MoveTo(imgTF.gameObject, btnTF.position, 3);
//(谁移,移到哪里,移动时间)
iTween.MoveTo(imgTF.gameObject, iTween.Hash(
"position",btnTF.position,
"speed",50,
"easetype",type
));
}
iTween for Unity by Bob Berkebile (pixelplacement)
自动布局组控件
Grid Layout Group
网格布局组,将子元素以表格形式自动排列
属性:
Start Corner开始角度 Start Axis开始轴向
Constraint 约束
Flexible 灵活的 Fixed Column Count 固定列数
Fixed Row Count固定行数
Horizontal Layout Group
水平布局组,将子元素按照水平方向自动排列
属性:
Padding填充
Left 左边距 Right 右边距
Top上边距 Botton下边距
Spacing间隔
Child Alignment 元素的对齐方式
Child Force Expand 元素展开
Vertical Layout Group
垂直布局组,将子元素按照垂直方向自动排列
边栏推荐
- 数据库公共字段自动填充
- 人工神经网络模型的特点,人工神经网络模型定义
- Solve the problem that the win10win7win8 system cannot find the specified module and cannot register the desert plug-in
- 时序动作定位 | ACGNet:弱监督时序动作定位的动作补充图网络(AAAI 2022)
- 关于数据中心的设计方案,数据中心网络规划设计
- 神经网络的三种训练方法,神经网络训练全过程
- Rust学习:6.4_复合类型之枚举
- 【NeRF】原始论文解读
- 明明加了唯一索引,为什么还是产生重复数据?
- Day36 LeetCode
猜你喜欢
PHP笔记 28 29 30 31
90.(cesium之家)cesium高度监听事件
进程管理(动态的)
什么是长轮询
张驰课堂:老板会武术,谁也挡不住!六西格玛培训的魅力
物联网时代下的网络整合推广外包精准化效果-深圳双赢世讯
iwemeta metaverse: a doll sells for 9999 yuan, and Bubble Mart thinks it is not expensive at all
Rust learning: 6.3_ Tuples of composite types
CV+Deep Learning - network architecture Pytorch recurrence series - classification (3: MobileNet, ShuffleNet)
Introduction to C integer data storage
随机推荐
LaTeX出现错误代码Command \algorithmic already defined
速卖通卖家如何抓住产品搜索权重
raid5的写性能,是不的比raid10快一些?
神经网络的三种训练方法,神经网络训练全过程
2022-08-01 网工进阶(二十三) VLAN高级技术-VLAN聚合、MUX VLAN
【Unity入门计划】2D游戏实现敌人来回移动控制脚本
阿里云数据库 RDS SQL Server 版的服务器绑定域名www.cxsdkt.cn.的呢?
2022-08-01 网工进阶(二十四) STP进阶知识
Based on STC8G2K64S4 single-chip microcomputer to display analog photosensitive analog value through OLED screen
Uni-app开发微信小程序使用本地图片做背景图
Rust learning: 6.3_ Tuples of composite types
Using the color picker
自动化测试框架Pytest(一)——入门
FFT模板
占位占位1
搭建 risc-v 编译环境
StringUtils的具体操作
11111
CV-人脸识别-2018:ArcFace
Add spark related dependencies and packaging plugins (sixth bullet)