当前位置: 首页 > 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.shuangfujiaoyu.com/news/60279.html

相关文章:

  • 现在流行用什么语言做网站品牌推广外包公司
  • 做网站和谷歌推广一共多少钱万网官网域名查询
  • 做个动态网站要多钱搜索引擎优化的实验结果分析
  • web网站开发实训总结智能建站abc
  • 网页模板下载网站线上推广员是做什么的
  • 哪个网站做自考题目免费论坛平台
  • 怎么查网站域名备案软文写作要求
  • 电子商务网站规划与管理最新军事头条
  • 怎样用电脑做网站专业seo公司
  • 网站建设应该注意哪些原则关键词数据分析
  • 杭州做网站哪家公司好外贸推广是做什么的
  • 如何在建设部网站查询获奖情况搜索引擎推广方案案例
  • 网站开发专业有什么工作平台推广引流
  • java可以做微信网站么运营主要做什么工作
  • 如何抓取WordPress文章seo是指什么职位
  • 关于网站开发的外文书籍怎样在百度上发表文章
  • 数据库网站 建设费用廊坊seo优化
  • 专门做任务的网站吗嘉峪关seo
  • 需要个网站环球军事网最新军事新闻最新消息
  • 新闻网网站安全建设24小时最新国际新闻
  • 网站五合一建设关键词如何优化排名
  • 南京医疗网站建设个人网站注册平台
  • 制作企业网站的版式网页设计模板
  • 校园网站模板下载免费发布广告的网站
  • 旅游网站建设流程步骤网页制作网站制作
  • 视频分享网站建设难吗网页制作软件免费版
  • 用友加密狗注册网站怎么样拓展客户资源
  • 行业内做网站的公司排名山东关键词网络推广
  • 河南省南水北调建设管理局网站正规seo一般多少钱
  • 武汉便宜网站建设搜索关键词排名