当前位置: 首页 > news >正文

追波设计网站海西高端网站建设价格

追波设计网站,海西高端网站建设价格,wordpress完整教程,响应式网站的概念展示效果 原理: 当停止滑动时 判断Contet的horizontalNormalizedPosition 与子Item的缓存值 相减,并得到最小值#xff0c;然后将Content horizontalNormalizedPosition滚动过去 使用方式#xff1a; 直接将脚本挂到ScrollRect上 注意#xff1a;在创建Content子物体时…展示效果 原理: 当停止滑动时 判断Contet的horizontalNormalizedPosition 与子Item的缓存值 相减,并得到最小值然后将Content  horizontalNormalizedPosition滚动过去 使用方式 直接将脚本挂到ScrollRect上 注意在创建Content子物体时 或子物体数量变更需要调用Refresh 代码 namespace ShangShangQian.Component {using System.Collections;using System.Collections.Generic;using UnityEngine;using UnityEngine.UI;using UnityEngine.EventSystems;using System.Linq;using UnityEngine.Events;[RequireComponent(typeof(ScrollRect))]public class SnapScrollRect : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler{private RectTransform content;private ScrollRect rect;/// summary/// content 的位置应该滚到什么/// /summarypublic float target 1;/// summary/// 回滚的速度 0-1 越小越快/// /summarypublic float smooting 0.25f;public float currentVelocity;public float horizontalNormalizedPosition;public Listfloat values new Listfloat();public Listfloat distances new Listfloat();public ListRectTransform items new ListRectTransform();/// summary/// 是否拖拽中/// /summarypublic bool isDrag false;/// summary/// 到最近item的距离/// /summarypublic float distanceMin;/// summary/// 到最近item的索引/// /summarypublic int selectIndex;/// summary/// 是否匹配滑动中/// /summarypublic bool Snaping false;/// summary/// 回滚完毕后调用/// /summarypublic UnityEventint OnSnap;void Start(){rect GetComponentScrollRect();content rect.content;}/// summary/// 刷新数据content的子物体数量变更时需要调用此函数/// /summarypublic void Refresh(){items.Clear();values.Clear();for (int i 0; i content.childCount; i){if (content.GetChild(i).gameObject.activeInHierarchy){items.Add(content.GetChild(i).GetComponentRectTransform());}}//累加的变量values.Add(0);//每一个格子的所占比多少 float v 1f / (items.Count - 1);for (int i 1; i items.Count; i){values.Add(i * v);}//不同子元素数量 item 对应 的content horizontalNormalizedPosition 数值//1 0 //2 0 1 //3 0 0.5 1//4 0 0.33 0.66 1}void Update(){ #if UNITY_EDITORif (Input.GetKeyDown(KeyCode.A)){Refresh();} #endif}void FixedUpdate(){horizontalNormalizedPosition rect.horizontalNormalizedPosition;if (isDrag){return;}if (Snaping){rect.horizontalNormalizedPosition Mathf.SmoothDamp(rect.horizontalNormalizedPosition, target, ref currentVelocity, smooting);if (Mathf.Abs(rect.horizontalNormalizedPosition - values[selectIndex]) 0.001f){Snaping false;Debug.Log(回滚: selectIndex);OnSnap.Invoke(selectIndex);}}}public void OnBeginDrag(PointerEventData eventData){isDrag true;}public void OnDrag(PointerEventData eventData){isDrag true;}public void OnEndDrag(PointerEventData eventData){isDrag false;Snaping true;distances.Clear();//当松手后判断那个距离最近for (int i 0; i values.Count; i){distances.Add(Mathf.Abs(rect.horizontalNormalizedPosition - values[i]));}distanceMin distances.Min();selectIndex distances.FindIndex(b b distanceMin);target values[selectIndex];rect.StopMovement();}/// summary/// 滚到到指定位置/// /summary/// param nameindex/parampublic void SnapToIndex(int index){Snaping true;selectIndex index;target values[selectIndex];}} }
http://www.dnsts.com.cn/news/24003.html

相关文章:

  • 小说网站开发的看书软件杭州网站制作流程
  • 中国优秀设计网站有哪些创建快捷方式app下载
  • 无锡网络公司无锡网站推广登录建设银行网站打不开
  • 河南双师培训网站网店详情页模板
  • 做ppt高手_一定要常去这八个网站课程设计超市会员网站建设
  • rest api 做网站东莞大岭山电子厂
  • 深圳网站建设设公众号开发微商城
  • 绵阳住房和城乡建设厅官方网站邯郸市地图高清版最新
  • 网站设置多少个关键词怎么做足球网站
  • 西宁设计网站建设抖音官方推广平台
  • 远程管理wordpress站群wordpress和e
  • 天津房地产网站建设建筑施工安全员c证查询
  • 网站建设需求意见征求表暴雪安全令
  • 北京网站建设方案书绍兴网站建设方案书
  • 2003建立虚拟网站南京雨花台区做网站
  • 网站用的什么字体专业关键词排名优化软件
  • 昆明网站排名优化公司网站城市跳转怎么做
  • 成都络迈品牌网站建设网站架构师的工作内容
  • 爱网站最新发布址WordPress连接微信 微信机器人
  • 网站正在建设中 页面企业邮箱登录入口官网ww
  • 网站视频插件代码做外国订单有什么网站
  • 杭州市做外贸网站的公司一个人免费视频在线观看高清
  • 手机网站发布页电脑版平顶山 网站建设公司
  • 深圳最好的网站建设公司哪家好p2p贷款网站建设
  • 绵阳做公司网站wordpress制作在线云课堂
  • 专门做优选的网站vps搭建网站是什么意思
  • 淘宝网站怎么做适配互联网推广运营
  • 建设一个普通网站需要多少钱西安建设局官方网站
  • 用python做的网站模板怎样注册网站做销售
  • 做最最优秀的视频网站有哪些php成品网站源码