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

哪有宝安网站推广为什么不用h5做网站

哪有宝安网站推广,为什么不用h5做网站,徐州做网站哪个好,qq登录账号在线登录入口效果 直接将脚本挂载在Text Mesh Pro上,但是需要滚动的文本必须在Scroll View中,否侧会定位错误,还需要给Scroll View中看需求添加垂直或者水平布局的组件 代码 using System.Collections; using System.Collections.Generic; using UnityE…

效果

请添加图片描述
直接将脚本挂载在Text Mesh Pro上,但是需要滚动的文本必须在Scroll View中,否侧会定位错误,还需要给Scroll View中看需求添加垂直或者水平布局的组件

代码

using System.Collections;
using System.Collections.Generic;
using UnityEngine;using TMPro;
using UnityEngine.EventSystems;public class TextScroll : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler {// TextMeshPro的文本框private TextMeshProUGUI text;private string saveStr; // 保存文本内容,可以保存,但是没有必要,需要实现动态文本private Vector3 savePostion; // 保存文本位置private Vector2 savesizeDelta; // 保存尺寸private float saveMoveWeight;private RectTransform rect; // 文本的方形转换器[Tooltip("开启自动权重")]public bool AutoMoveWeight = true;// 如果开启自动权重那么对该变量修改不在起作用[Tooltip("溢出文本移动的权重,会根据权重的值,来对溢出内容的多少进行加速")]public float moveWeight = 3;private void OnEnable() {text = GetComponent<TextMeshProUGUI>();rect = text.gameObject.GetComponent<RectTransform>();Init();}/// <summary>/// 初始化文本内容/// </summary>public void Init() {saveStr = text.text;savePostion = rect.position;savesizeDelta = rect.sizeDelta;saveMoveWeight = moveWeight;}private Coroutine coroutine; // 接收协程/// <summary>/// 鼠标进入/// </summary>/// <param name="eventData">传入事件数据,鼠标位置等</param>public void OnPointerEnter(PointerEventData eventData) {// Debug.Log("鼠标进入开始文本滚动");// saveStr = text.text;// 是否存在截断float fontsLenght = CalculateTextWidth(text);if (fontsLenght < rect.sizeDelta.x ) return;// 处理上一次退出后未完成恢复完成就再次进入if (coroutine != null) {StopCoroutine(coroutine);Reset();}// 是否启动自动更新if (AutoMoveWeight) {moveWeight = (fontsLenght - rect.sizeDelta.x) / 100;}// 计算所需时间float sumTime = (fontsLenght - rect.sizeDelta.x) / text.fontSize / moveWeight;rect.sizeDelta = new Vector2(fontsLenght + 100, rect.sizeDelta.y);coroutine = StartCoroutine(IETextScroll(sumTime, false));}/// <summary>/// 鼠标移出/// </summary>/// <param name="eventData"></param>public void OnPointerExit(PointerEventData eventData) {// Debug.Log("text begine reset");// 过滤if (text == null || (coroutine == null && CalculateTextWidth(text) < rect.sizeDelta.x) || totalDistance == 0) return;if (coroutine != null) { // 文本正在向左滚动StopCoroutine(coroutine);} coroutine = StartCoroutine(IETextScroll(totalTime / 3, true));// Reset();}/// <summary>/// 计算文本内容宽度/// </summary>/// <param name="text"></param>/// <returns></returns>private float CalculateTextWidth(TextMeshProUGUI text) {float width = text.preferredWidth;return width;}private float totalDistance = 0;private float totalTime = 0;/// <summary>/// 文本滚动的协程/// </summary>/// <param name="time">协程运行时间</param>/// <param name="isReset">是否是恢复时启动的协程</param>/// <returns></returns>private IEnumerator IETextScroll(float time, bool isReset) {// float moveSpeed = 0;float perDistance = 0;if (!isReset) {while (time > 0) {// Time.deltaTime 是一个不确定的量,需要每帧更新。perDistance = moveWeight * text.fontSize * Time.deltaTime;rect.position = new Vector3(rect.position.x - perDistance, rect.position.y);time -= Time.deltaTime;totalDistance += perDistance;totalTime += Time.deltaTime;yield return null;}} else { // 恢复//moveSpeed = totalDistance / time;//while (time > 0) {//    perDistance = moveSpeed * Time.deltaTime;//    rect.position = new Vector3(rect.position.x + perDistance, rect.position.y);//    time -= Time.deltaTime;//    yield return null;//}Reset();}// Debug.Log("移动权重: " + moveWeight + " 每次距离: " + totalDistance + " 花费时间: " + totalTime);yield return null;}/// <summary>/// 恢复/// </summary>private void Reset() {if (text == null) return;// text.text = saveStr;rect.position = savePostion;rect.sizeDelta = savesizeDelta;moveWeight = saveMoveWeight; // 采用自动权重时会再次自动计算权重totalDistance = 0;totalTime = 0;}
}
http://www.yayakq.cn/news/389802/

相关文章:

  • 网站用什么构建wordpress游客登录
  • 便宜网站建设模板网站wordpress客户端linux
  • 什么网站可以做旅行行程心悦免做卡领取网站
  • 外贸电商平台哪个网站最好宁波市城乡和建设网站
  • 用什么软件来做网站网业版浏览器
  • 个人博客网站注册南开网站建设优化seo
  • 网站怎么销售天津做网站好的公司
  • 中小企业建站服务wordpress网上在线插件
  • 深圳做网站龙华信科vi手册模板60页
  • 网页设计国外设计欣赏网站如何做收机微网站
  • 青海建设网站价格低群晖nas可以做网站服务器
  • 高效网站推广网站建设推广销售话术
  • 遵义网站开发培训门户网站建设考核总结
  • 杭州企业网站制作哪个好罗定市住房和城乡建设局网站
  • 青海公司网站建设哪家好龙岗区住房建设局网站
  • 云数据库可以做网站吗郴州网站seo
  • 网站域名注册证明软件著作权登记
  • 上海 网站公司男朋友抱着我在教室做网站
  • 网站制作软件都是什么常州网络优化排名
  • 医院网站建设需求分析调研表百度下载并安装最新版
  • 网站建设礼品韩国风网站
  • 站酷网app网站利用e4a做app
  • 怎样建立营销网站软件怎么做出来的
  • 网站登录 退出怎么做有没有专门做外包销售的公司
  • 海口网站建设好地推团队如何收费
  • php网站开发是学什么的建设网站用什么语言比较好
  • 答建设网站厦门同安网站建设
  • 美容美发化妆品培训企业网站源码带后台php织梦dede5.7网络推广培训前景如何
  • 做网站卖东西最好看的中文字幕国语电影有哪些
  • 网站上的文章用秀米可以做吗网站建设的分工的论文