123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine.UI;
- using UnityEngine;
- using System;
- using Sirenix.OdinInspector;
- using UnityEngine.EventSystems;
- public class ScrollInformation : MonoBehaviour,IPointerEnterHandler,IPointerExitHandler
- {
- [LabelText("速度")]
- public float Speed;
- [LabelText("要滚动的目标")]
- public RectTransform Information;
- //移动物体与父物体宽度差值
- float tmpWidth = 0;
- /// <summary>
- /// 开启移动
- /// </summary>
- bool openMove;
-
- void Start()
- {
- RectTransform tmpParentRectTransform = transform.GetComponent<RectTransform>();
- tmpWidth = Information.rect.width - tmpParentRectTransform.rect.width;
- }
- void FixedUpdate()
- {
- ScrollResult();
- }
- void ScrollResult()
- {
- if (!openMove) return;
- if (tmpWidth > 0)
- {
- float tmpX = Information.anchoredPosition.x - Time.fixedDeltaTime * Speed;
-
- Information.SetLocalPositionX(tmpX);
- if (Information.anchoredPosition.x < -tmpWidth)
- {
- Information.SetLocalPositionX(0);
- }
- }
- }
- public void OnPointerEnter(PointerEventData eventData)
- {
- openMove = true;
- }
- public void OnPointerExit(PointerEventData eventData)
- {
- openMove = false;
- Information.SetLocalPositionX(0);
- }
- }
|