unity滚动层dotween移动到指定索引
来源:互联网 发布:linux运维基础知识 编辑:程序博客网 时间:2024/06/04 19:16
using UnityEngine;using System.Collections;using UnityEngine.UI;using DG.Tweening;public enum ScrollLayoutType{ Grid, Vertical}public class ScrollToItem : MonoBehaviour { public ScrollLayoutType m_type = ScrollLayoutType.Grid; public RectTransform m_content; public RectTransform m_view; [SerializeField] float m_cellY; // Use this for initialization void Start() { NotificationCenter.Get().ObjAddEventListener(KEventKey.m_evScrollToItem, gameObject, OnEventScroll); } private void OnDestroy() { NotificationCenter.Get().ObjRemoveEventListener(KEventKey.m_evScrollToItem, gameObject); } void OnEventScroll(Notification noti) { int idx = (int)noti.param; switch (m_type) { case ScrollLayoutType.Grid: ScrolllToIdx(idx); break; case ScrollLayoutType.Vertical: ScrollToIdxVertical(idx); break; default: break; } } void ScrolllToIdx(int idx) { float length = idx * (m_content.GetComponent<GridLayoutGroup>().cellSize.y + m_content.GetComponent<GridLayoutGroup>().spacing.y); float ViewProtH = m_content.childCount * (m_content.GetComponent<GridLayoutGroup>().cellSize.y + m_content.GetComponent<GridLayoutGroup>().spacing.y) - m_view.sizeDelta.y - m_content.GetComponent<GridLayoutGroup>().spacing.y; if (length > ViewProtH) { length = ViewProtH; } DOTween.To(() => m_content.offsetMax, x => m_content.offsetMax = x, new Vector2(0, length), 0.5f); } void ScrollToIdxVertical(int idx) { float length = idx * (m_cellY + m_content.GetComponent<VerticalLayoutGroup>().spacing); float ViewProtH = m_content.childCount * (m_cellY + m_content.GetComponent<VerticalLayoutGroup>().spacing) - m_view.sizeDelta.y - m_content.GetComponent<VerticalLayoutGroup>().spacing ; if (length > ViewProtH) { length = ViewProtH; } DOTween.To(() => m_content.localPosition, x => m_content.localPosition = x, new Vector3(0,length,0), 0.5f); }}
阅读全文
0 0
- unity滚动层dotween移动到指定索引
- 鼠标移动到指定位置,弹出层
- 11.8移动弹出层到指定位置
- unity 移动物体到指定位置的四种方法
- AutoCAD.NET移动选定对象到指定图层
- 层随滚动条移动
- 【代码笔记】【c#】将数组的某一索引位置的元素移动到指定索引位置
- [Unity插件]DOTween基础
- Unity插件 DOTween基础
- Unity插件DOTween教程
- Unity插件 DOTween基础
- [Unity插件]DOTween基础
- [Unity插件]DOTween(2)
- [Unity插件]DOTween(3)
- Unity 使用DoTween
- [Unity插件]DOTween基础
- Unity DoTween插件说明
- [Unity插件]DOTween基础
- ConcurrentHashMap 1.8源码解析
- Java Web 项目配置 环境搭建 从零到HelloWorld
- PAT 1069. 微博转发抽奖(20)
- 阿里云服务器Java+Mysql+Tomcat环境搭建(Mac OS下配置)
- 远程桌面无法使用剪切板的解决方法
- unity滚动层dotween移动到指定索引
- leetcode解题方案--062--Unique Paths
- 实验三 二进制补码加法器
- kmeans++
- 笔试题(一)—— java基础
- 【笔记】AOE网与关键路径
- ThinkPHP5.1 不需要控制器的路由 \类的命名空间\类名@方法名
- C 标准库
- 浅谈Spring中的IOC和AOP概念