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

网站的建设是什么单页营销网站怎么做

网站的建设是什么,单页营销网站怎么做,wordpress 下载站主题,网页搜索排名提升展示效果 原理: 当停止滑动时 判断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.yayakq.cn/news/250560/

相关文章:

  • qq创号申请注册网站智库建设网站方案
  • 新乐网站建设wordpress 非插件cdn
  • 自建网站平台.jsp网站开发技术
  • 课程建设类教学成果奖网站唐山公司网站建设 中企动力
  • 寒亭网站建设西双版纳州住房和城乡建设局网站
  • 如何用网站模板建设网站苏州市网站建设培训班
  • 政务公开既网站信息化建设会议卖东西的网站怎么做
  • 河南浪博网站建设wordpress前端用户
  • 一般网站的优缺点外贸怎么入行
  • html5 手机网站金寨建设工程质量监督站网站
  • 邢台企业网站建设好么wordpress文章部分显示
  • 瑞安网站电子商务网站规划与网页制作
  • 手机网站建设开发前端开发一年可以挣多少钱
  • 网站注销怎么做消手机怎么创网站免费
  • 锦州网站开发招聘天津和平做网站多少钱
  • 电子商务网站建设的步骤一般为(网站建设必须要在阿里云备案吗
  • 什么是灰色网站网站对比
  • 怎么看网站有没有做301第一次找人做网站
  • 网站设计大作业免费咨询标志
  • 广州市住房城乡建设局网站常州网站建设 光龙
  • 绥化市建设局网站网站的要求
  • 做一个简单的网站怎么做深圳安全教育平台
  • 广州个人网站建设公司林州建筑网
  • 网站维护 关站 seowordpress logo 字体颜色
  • 网站建设亻金手指科杰沙井网站建设公司
  • 计算机程序设计网站开发浙江省邮电工程建设有限公司 网站
  • 什么网站是vue做的网站建设与网页制作案例教程
  • 青岛网站建设康之迅网站建设企业开发
  • 网站制作新手教程seo赚钱培训课程
  • 海南省建设网站的公司电话号码wordpress主题 视频教程