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

淮南网站网站建设免费b站在线观看人数在哪里找到

淮南网站网站建设,免费b站在线观看人数在哪里找到,宜兴市建设局官方网站,做网站游戏需要什么使用场景 策划提出需求:当玩家打开领奖界面时,奖励列表需要自动滑动到可以领奖的奖励栏处或者正在进行的任务栏处。 思路 1、将Content设置好对齐方式和锚点 子物体的预制体和Content:pivot轴心点设置为(0,1),并且设置为左上角对齐。 2、主…

使用场景

策划提出需求:当玩家打开领奖界面时,奖励列表需要自动滑动到可以领奖的奖励栏处或者正在进行的任务栏处。

思路

1、将Content设置好对齐方式和锚点

子物体的预制体和Content:pivot轴心点设置为(0,1),并且设置为左上角对齐。

2、主要根据索引计算Content需要设置的高度即(RectTransform的PosY)

 var sumHeight = targetIndex * (itemHeight + spacing);scrollRect.content.anchoredPosition = new Vector2(0, sumHeight);

特殊情况

第一种  子物体较少的情况(Content高度小于可视区域高度)

不用移动,不必处理

第二种 滑动到末尾几个索引的时候

1、需要提前计算viewport可以最多完整囊括多少个子物体(visualCount)

2、如果需要定位的目标索引大于或等于(总数量 - visualCount+1)时,使用

scrollRect.normalizedPosition = new Vector2(0, 0);

 直接滑到底端就行。

代码

using UnityEngine;
using UnityEngine.UI;public class Test : MonoBehaviour
{public int sumCount;public Transform root;public GameObject item;public ScrollRect scrollRect;public float itemHeight;public float spacing;//子物体之间的间隔public float contentHeight;public float viewportHeight;public int visualCount;public int compareCount;public InputField inputField;void Start(){sumCount = 100;spacing = 10;var itemRect = item.GetComponent<RectTransform>();itemHeight = itemRect.rect.height;for (var i = 1; i <= sumCount; i++){var obj = Instantiate(item, root.transform);var txtObj = obj.transform.Find("txt");var txt = txtObj.GetComponent<Text>();txt.text = i.ToString();}LayoutRebuilder.ForceRebuildLayoutImmediate(scrollRect.content);contentHeight = scrollRect.content.rect.height;viewportHeight = scrollRect.viewport.rect.height;visualCount = (int)(viewportHeight / itemHeight);compareCount = sumCount - visualCount + 1;}private void Update(){if (Input.GetKeyDown(KeyCode.Space)){var index = int.Parse(inputField.text);ScrollToTarget(index);}}public void ScrollToTarget(int index){if (index <= 0 || index > sumCount){return;}//第一种 子物体较少的情况(Content高度小于可视区域高度)if (contentHeight < viewportHeight){return;}   //先停止列表滑动,以防造成误差scrollRect.StopMovement();//第二种 滑动到末尾几个索引的时候if (index >= compareCount){scrollRect.normalizedPosition = new Vector2(0, 0);return;}var targetIndex = index - 1;targetIndex = targetIndex < 0 ? 0 : targetIndex;var sumHeight = targetIndex * (itemHeight + spacing);scrollRect.content.anchoredPosition = new Vector2(0, sumHeight);}
}

补充

1、如果需要添加滚动动画,可以使用Dotween来实现

 var sumHeight = targetIndex * (itemHeight + spacing);scrollRect.content.DOAnchorPosY(sumHeight,0.5f);
http://www.dtcms.com/wzjs/398522.html

相关文章:

  • 给一个网站seo关键词词库
  • iis7配置thinkphp网站定制网站+域名+企业邮箱
  • wordpress自建cdnseo网站推广方式
  • wordpress多站点备份石家庄热搜
  • 陕西西安建设厅官方网站b2b电商平台有哪些
  • 企业建设网站公司网站设计公司报价
  • 济南手机网站建设专业定制太原seo推广外包
  • 当今做那些网站致富怎么开设自己的网站
  • 东莞常平地图全图高清版seo程序
  • 网站转移服务器需要重新备案吗广州seo站内优化
  • 做单页网站要多少钱肇庆网站制作软件
  • 显示隐藏的页wordpress哈尔滨seo
  • 建设网站需要了解什么网络电商推广方案
  • 万荣做网站免费网站提交入口
  • 外资公司在国内注册流程关键词排名优化是什么意思
  • 哪里有南宁网站建设网络推广图片
  • wordpress 数学主题谷歌seo优化
  • 长沙做网站seo公司网站搜索引擎优化技术
  • c语言开发网站浙江企业网站建设
  • 外国大气网站重庆网站推广
  • 我爱做衣服网站今日热搜前十名
  • 网站有备案号百度识图网页版在线
  • 旅游网站建设方案越秀seo搜索引擎优化
  • 网站建设结论及体会站长之家工具高清
  • 做韩服的视频网站百度页面
  • wordpress入门建站教程二网络营销平台推广方案
  • 做个网站要花多少钱北京seo培训机构
  • 如果做独立网站赚钱网站排名查询软件
  • 企业网站模板下载选哪家seo入门培训
  • 苏州 网站建设青岛百度网站排名