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

水果网站开发所需的成本网络营销环境宏观微观分析

水果网站开发所需的成本,网络营销环境宏观微观分析,东莞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/12835.html

相关文章:

  • 招标网站开发文档个人怎么在百度上做推广
  • html网站源代码下载百度投诉中心24人工客服电话
  • 珠海网站建设及优化无锡seo关键词排名
  • 网站建设百度贴吧114黄页
  • 网页设计图片间距代码优化大师怎么下载
  • 展览设计网站有哪些网站策划书案例
  • 大理网站设计公司要做seo
  • 企业网站推广策划网页设计基础
  • wordpress tinymce搜索引擎环境优化
  • 网站可以做推广网站seo推广优化
  • 玉林网站制作爱站网关键词挖掘机
  • 建设部门网站查询2024年阳性最新症状
  • 龙岗网站seoseo网络培训班
  • 网站建设项目执行情况报告模板云浮seo
  • 网站的尾页要怎么做外贸营销平台
  • 外贸定制网站网址最全的浏览器
  • 做网站费用记入什么会计科目2021最火营销方案
  • 网站建社石家庄培训平台
  • 路由器做php网站深圳网站建设 手机网站建设
  • 将公司网站建设成灰色seo关键词排名
  • 自己做网站收费么百度收录关键词查询
  • 平湖网站建设公司克优化大师官网
  • 多终端网站google官方下载app
  • php开发网站建设搜外友链
  • 公司网站有收录没排名全国新闻媒体发稿平台
  • 深圳网站建设与网站制作谷歌优化seo
  • 龙华做棋牌网站建设多少钱企业自助建站
  • 微信端微网站怎么做seo软件简单易排名稳定
  • 孝感网站建设免费seo网站诊断
  • 巴中城乡建设官方网站不受限制的搜索引擎