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

seo小白入门教学windows优化大师是什么

seo小白入门教学,windows优化大师是什么,山东建设厅网站网址,美国做色情网站犯法吗通过上下滑动,实现带自动回正带阻尼感的转盘,上图所示的正方向在9点钟方向,即正西方向 实现过程,找到一个1:1的方形图片,制作一个圆环,我这里是将圆环分成了14份,代码里可以调整,添…

通过上下滑动,实现带自动回正带阻尼感的转盘,上图所示的正方向在9点钟方向,即正西方向

实现过程,找到一个1:1的方形图片,制作一个圆环,我这里是将圆环分成了14份,代码里可以调整,添加代码,手动调整动态参数即可。

直接上代码:

using UnityEngine;
using UnityEngine.EventSystems;public class LotteryWheel : MonoBehaviour, IPointerDownHandler, IDragHandler, IPointerUpHandler
{[Header("转盘")]public RectTransform wheel;[Header("旋转参数")][Tooltip("手势滑动灵敏度,值越大旋转越明显")]public float swipeSensitivity = 0.5f;[Tooltip("惯性减速速率(角度/秒²)")]public float deceleration = 500f;[Tooltip("回弹对齐的旋转速度(角度/秒)")]public float snapSpeed = 300f;[Header("分段设置")]public int segmentCount = 14; // 分成14份[Header("回正偏移设置")][Tooltip("回正时的目标偏移角度,此处为-90°表示最终使分段中心与-90°对齐")]public float snapOffsetAngle = -90f;public AudioClip audioClip;// 内部状态private float currentVelocity = 0f; // 当前旋转速度(角度/秒)private bool isDragging = false;    // 是否处于拖拽手势中private bool isSnapping = false;    // 是否正在自动回弹对齐private Vector2 lastPointerPosition; // 记录上一次手指位置// 用于记录上一次经过的分段中心,防止重复打印日志private int lastLoggedSegment = -1;void Start(){// 根据转盘初始角度计算当前分段中心索引float currentAngle = wheel.eulerAngles.z;float segmentAngle = 360f / segmentCount;float relativeAngle = (currentAngle - snapOffsetAngle + 360f) % 360f;lastLoggedSegment = Mathf.RoundToInt(relativeAngle / segmentAngle) % segmentCount;}void Update(){// 非拖拽且未处于回弹对齐状态时,利用惯性旋转并逐渐减速if (!isDragging && !isSnapping){if (Mathf.Abs(currentVelocity) > 0.01f){float deltaAngle = currentVelocity * Time.deltaTime;wheel.Rotate(0, 0, deltaAngle);currentVelocity = Mathf.MoveTowards(currentVelocity, 0, deceleration * Time.deltaTime);// 当速度足够小时,进入回弹对齐状态if (Mathf.Abs(currentVelocity) < 0.1f){currentVelocity = 0;isSnapping = true;}}}// 回弹对齐阶段:计算目标角度(基于偏移)if (isSnapping){float currentAngle = wheel.eulerAngles.z;float segmentAngle = 360f / segmentCount;// 以 snapOffsetAngle 为参考,计算最近的分段中心角度float targetAngle = Mathf.Round((currentAngle - snapOffsetAngle) / segmentAngle) * segmentAngle + snapOffsetAngle;float newAngle = Mathf.MoveTowardsAngle(currentAngle, targetAngle, snapSpeed * Time.deltaTime);wheel.eulerAngles = new Vector3(0, 0, newAngle);if (Mathf.Abs(Mathf.DeltaAngle(newAngle, targetAngle)) < 0.1f){isSnapping = false;// 计算当前分段编号,归一化取模,确保编号在0~segmentCount-1内int segmentIndex = Mathf.RoundToInt((targetAngle - snapOffsetAngle) / segmentAngle);segmentIndex = (segmentIndex % segmentCount + segmentCount) % segmentCount;int number = segmentIndex + 1;Debug.Log("当前编号: " + number);}}// Add detectionSlidingAreaDetection();}// Add detection: Print logs when the turntable turns over a new segment centerprivate void SlidingAreaDetection(){// 获取当前转盘角度(0~360°),计算相对于 snapOffsetAngle 的归一化角度float currentAngle = wheel.eulerAngles.z;float segmentAngle = 360f / segmentCount;float relativeAngle = (currentAngle - snapOffsetAngle + 360f) % 360f;// 通过四舍五入得到当前经过的分段中心索引int currentCenterIndex = Mathf.RoundToInt(relativeAngle / segmentAngle) % segmentCount;if (currentCenterIndex != lastLoggedSegment){// 此处打印日志,后续可在此处接入音效播放//Debug.Log("经过分段中心, 当前分段: " + (currentCenterIndex + 1));if (audioClip != null && audioClip.length > 0){GetComponent<AudioSource>().PlayOneShot(audioClip);}lastLoggedSegment = currentCenterIndex;}}public void OnPointerDown(PointerEventData eventData){isDragging = true;isSnapping = false; // 中断回弹对齐lastPointerPosition = eventData.position;currentVelocity = 0;}public void OnDrag(PointerEventData eventData){Vector2 pointerDelta = eventData.position - lastPointerPosition;// 根据手指垂直位移决定旋转方向:上滑(delta.y正)顺时针旋转,反之逆时针旋转float rotationDelta = -pointerDelta.y * swipeSensitivity;wheel.Rotate(0, 0, rotationDelta);currentVelocity = -pointerDelta.y * swipeSensitivity / Time.deltaTime;lastPointerPosition = eventData.position;}public void OnPointerUp(PointerEventData eventData){isDragging = false;if (Mathf.Abs(currentVelocity) < 10f){currentVelocity = 0;isSnapping = true;}}
}

 有点像手机闹钟,设置时间时的丝滑感觉。

下面的代码是将所划分的区域段数实时的展示在Scene界面,可用可不用,需要自取

using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class ShowRotaryWheel : MonoBehaviour
{public int sectorCount = 14; // 区域块数量#if UNITY_EDITOR// 在类末尾添加以下方法:private void OnDrawGizmos(){if (sectorCount < 1) return;RectTransform rt = GetComponent<RectTransform>();if (!rt) return;float radius = rt.rect.width / 2 * rt.lossyScale.x;Vector3 center = rt.position;float sectionAngle = 360f / sectorCount;Gizmos.color = Color.yellow;for (int i = 0; i < sectorCount; i++){float angle = i * sectionAngle;Vector3 direction = Quaternion.Euler(0, 0, angle) * Vector3.up;Gizmos.DrawLine(center, center + direction * radius);}}
#endif
}

如果有帮到你还望给个三连吧,感谢您的支持。

@Liam

http://www.dtcms.com/wzjs/246659.html

相关文章:

  • 怎样查看网站是用什么cms 做的福鼎网站优化公司
  • 做网站的研究生专业友链交换不限内容
  • 做电影下载网站需要什么百度网站建设
  • 贵阳网站建设设计公司公司网站建设方案
  • 做网站是怎么收费的是按点击率种子搜索神器在线搜
  • 宁波建设信息网优化 英语
  • WordPress 上传头像 前端seo百科大全
  • 拼多多标题优化软件安徽网络优化公司排名
  • 在一呼百应上做网站行吗长尾关键词是什么
  • 五大常用办公软件seo有些什么关键词
  • 做羞羞的事视频网站seo网站自动发布外链工具
  • 东莞高端做网站营销推广方案ppt案例
  • 南京网站建设网seo排名关键词
  • 旅游网站建设有哪些不足宣传推广方案模板
  • 网站空间在哪买好seo168小视频
  • 北京网站建设公司公司企业网络营销方案策划
  • 无锡网站营销公司5g站长工具查询
  • 美的公司网站建设的目的做抖音seo排名软件是否合法
  • 找人做网站网站如何优化排名
  • 800字以上网站设计方案百度信息流广告位置
  • 怎样做网站认证新闻头条今日新闻60条
  • 山西网站开发建设网站建设营销推广
  • 新昌做网站百度网站的域名地址
  • 国外一直小猫做图标的网站网站友情链接检测
  • 男人女人做性关系网站职业培训机构哪家最好
  • 手机门户网站建设网站管理
  • 口碑好的秦皇岛网站建设哪家好临沂seo推广外包
  • 企业建站网站建站系统衡阳有实力seo优化
  • 帮别的公司做网站违法吗中国大数据平台官网
  • 乐清网站定制公司哪家好西安seo外包服务