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

知名的网站开发公司seo优化的价格

知名的网站开发公司,seo优化的价格,宏福建设集团有限公司网站,微信小程序一键生成链接展示效果 原理: 当停止滑动时 判断Contet的horizontalNormalizedPosition 与子Item的缓存值 相减,并得到最小值,然后将Content horizontalNormalizedPosition滚动过去 使用方式: 直接将脚本挂到ScrollRect上 注意:在创建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 的位置应该滚到什么/// </summary>public float target = 1;/// <summary>/// 回滚的速度 0-1 越小越快/// </summary>public float smooting = 0.25f;public float currentVelocity;public float horizontalNormalizedPosition;public List<float> values = new List<float>();public List<float> distances = new List<float>();public List<RectTransform> items = new List<RectTransform>();/// <summary>/// 是否拖拽中/// </summary>public bool isDrag = false;/// <summary>/// 到最近item的距离/// </summary>public float distanceMin;/// <summary>/// 到最近item的索引/// </summary>public int selectIndex;/// <summary>/// 是否匹配滑动中/// </summary>public bool Snaping = false;/// <summary>/// 回滚完毕后调用/// </summary>public UnityEvent<int> OnSnap;void Start(){rect = GetComponent<ScrollRect>();content = rect.content;}/// <summary>/// 刷新数据,content的子物体数量变更时需要调用此函数/// </summary>public 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).GetComponent<RectTransform>());}}//累加的变量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 name="index"></param>public void SnapToIndex(int index){Snaping = true;selectIndex = index;target = values[selectIndex];}}
}

http://www.15wanjia.com/news/54761.html

相关文章:

  • 哪个工业园区信息化网站做的好全网优化推广
  • 聊城大型门户网站建设哪里可以接广告
  • 做汽车保养的网站上百度q3财报2022
  • 五百亿网站建设网站开发公司
  • 电商网站开发文档网站推广引流
  • 北京公司网站建设费用产品seo怎么优化
  • 泰州网站建设服务好360免费建站系统
  • 做网站怎么注册域名网络服务商电话
  • 网站建设和app哪个好百度联盟广告点击一次收益
  • 武汉建设工程价格信息网搜索引擎优化的具体操作
  • 网站 如何备案百度收录怎么做
  • 北京网站开发怎么做郑州网站建设专业乐云seo
  • W做网站怎么建立企业网站免费的
  • 外贸网站推广教程微信运营方案
  • 策划网站做营销推广山东今日热搜
  • 燕郊做网站找谁成都网站制作费用
  • 建站宝盒下载湖南seo推广多少钱
  • 门户网站推荐企业网站营销的优缺点
  • 深圳餐饮公司网站制作设计素材网站
  • 怎么制作属于自己的网站设计网站都有哪些
  • ipad怎么制作网站免费舆情监测平台
  • 简单大气网站模板百度提交入口网址是什么
  • 招聘网站开发需要多长时间seo网站培训班
  • app下载地址优化百度seo技术搜索引擎
  • 建设网站编程语言培训学校机构有哪些
  • 优秀设计师的个人网站网络营销培训机构
  • 网站ftp密码怎么修改cps广告是什么意思
  • 南宁网站建设哪家公体验营销是什么
  • C语言做网站需要创建窗口吗厦门seo顾问
  • 专业的中小型网站建设网络热词缩写