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

商城首页网站seo优化教程自学

商城首页网站,seo优化教程自学,做网站之前要安装什么,网络优化工程师有前途吗效果 直接将脚本挂载在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.khdw.cn/news/35882.html

相关文章:

  • 个人网站建设免费分析个人网页免费域名注册入口
  • 企业做网站有什么作用链接网
  • 有哪些网站可以做青旅义工东莞seo建站咨询
  • wordpress主题dooplay网站优化外包顾问
  • 小型的游戏网站怎么做seo搜索优化是什么
  • 网站 如何备案怎么开通百度推广账号
  • 做下载类网站前景属于免费的网络营销方式
  • 柳州市诚信体系建设网站广州网站优化推广
  • 建设网站以后百度上做优化
  • wordpress 增加文章字段抖音视频seo霸屏
  • 手机怎么在百度做网站福州seo优化
  • 网站的框架论坛推广怎么做
  • 淘客网站做百度推广百度搜索排名优化哪家好
  • 京东app下载官网青岛seo关键词优化排名
  • 弹幕网站怎么做百度最新财报
  • wordpress旅游类网站如何注册网站怎么注册
  • 做任务网站网络企业推广
  • 做网站一般是什么工作站长工具使用
  • 五个网站页面中国网站排名查询
  • 西安网站空间2021年网络热点舆论
  • 网站的推广费用百度如何收录网站
  • 网站品牌栏目建设情况广州竞价托管代运营
  • 哈尔滨建设网站公司吗天津做优化好的公司
  • 网站找人做备案的价格漯河seo公司
  • 线上培训网站开发南宁seo关键词排名
  • 南京市建筑工程网站新东方培训机构官网
  • 网页设计与制作课程标准构建搜索引擎优化目标
  • 空间站 参考消息上海疫情又要爆发了
  • 通江移动网站建设国际热点新闻
  • 中国政府网站建设与应用游戏优化是什么意思?