当前位置:网站首页>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
垂直布局组,将子元素按照垂直方向自动排列
边栏推荐
- 占位占位1
- StringUtils的具体操作
- Based on STC8G2K64S4 single-chip microcomputer to display analog photosensitive analog value through OLED screen
- phpstudy starts automatically
- VS2013-debug assembly code-generate asm file-structure memory layout-function parameter stack-calling convention
- 自动化测试框架Pytest(一)——入门
- 神经网络的三种训练方法,神经网络训练全过程
- Add spark related dependencies and packaging plugins (sixth bullet)
- 如何远程调试对方的H5页面
- day16--The use of the packet capture tool Charles
猜你喜欢

NPU架构与算力分析

ATH10传感器读取温湿度

Relaxation class: the boss will martial arts, who also can not hold up against!The charm of six sigma training

VS2013-调试汇编代码-生成asm文件-结构体内存布局-函数参数压栈-调用约定

2022-08-01 网工进阶(二十三) VLAN高级技术-VLAN聚合、MUX VLAN

ATH10 sensor reads temperature and humidity

每日一题,二叉树中增加一行

明明加了唯一索引,为什么还是产生重复数据?

Delphi实现的一个文件在线查询显示下载功能

【MySQL】使用MySQL Workbench软件新建表
随机推荐
Power function Exponential function Logarithmic function
大体来讲,网站会被攻击分为几种原因
NaiveUI中看起来没啥用的组件(文字渐变)实现原来这么简单
张驰课堂:老板会武术,谁也挡不住!六西格玛培训的魅力
Unity—UGUI控件
初使jest 单元测试
TensorFlow 2.9的零零碎碎(一)
winget包管理器
详解构建mock服务最方便的神器——Moco
关于数据中心的设计方案,数据中心网络规划设计
Class Notes (7) (1) - #647. Find the root and the child (root)
PLSQL学习第二天
预测股票涨跌看什么指标,如何预测明天股票走势
每日一题,数组字符串的匹配问题
Big guy, when Oracle single-table incremental synchronization, the source database server takes up nearly 2g of memory. This is not normal, right?
Rust learning: 6.4_ enumeration of composite types
如何设计神经网络结构,神经网络设计与实现
【Unity入门计划】制作RubyAdventure03-使用碰撞体&触发器实现世界交互
StringUtils的具体操作
PHP笔记 28 29 30 31