当前位置:网站首页>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
垂直布局组,将子元素按照垂直方向自动排列
边栏推荐
猜你喜欢
随机推荐
Rust learning: 6.4_ enumeration of composite types
VMware ESX Server常用命令行
The probability distribution and its application
winget包管理器
NPU architecture and force analysis
2022-08-01 网工进阶(二十四) STP进阶知识
phpstudy starts automatically
CV+Deep Learning——网络架构Pytorch复现系列——classification(三:MobileNet,ShuffleNet)
探索神经网络架构教程视频,设计神经网络的步骤
神经网络样本太少怎么办,神经网络训练样本太少
AFNetworking概述和4.0的实践
物联网时代下的网络整合推广外包精准化效果-深圳双赢世讯
LaTeX出现错误代码Command \algorithmic already defined
【Unity入门计划】制作RubyAdventure03-使用碰撞体&触发器实现世界交互
进程管理(动态的)
Rust学习:6.2_复合类型之元组
明明加了唯一索引,为什么还是产生重复数据?
WooCommerce 安装和 rest api 使用
.NET-8. My Thought Notes
foreach遍历删除元素问题总结








