欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Unity實現(xiàn)跑馬燈效果的示例代碼

 更新時間:2022年05月06日 16:48:13   作者:龍胖胖的博客  
這篇文章主要為大家詳細介紹了如何利用Unity實現(xiàn)跑馬燈效果,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

一、效果

二、需要動畫插件DOTween

下載地址

三、腳本

1.每個格子上的腳本文件

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using DG.Tweening;
public class MarqueeUIItem : MonoBehaviour
{
    private RawImage m_RawImage;
    private string thisIndex;
    private Coroutine m_coroutine;
    private void Start()
    {
        m_RawImage = GetComponent<RawImage>();

        thisIndex = transform.GetSiblingIndex().ToString();
    }
    public void UpdateImageColorA()
    {
        KillDOTween();
        m_RawImage.color = Color.white;
        m_coroutine= StartCoroutine(ShowUI());
    }
    private IEnumerator ShowUI()
    {
        yield return new WaitForSeconds(0.1F);
        m_RawImage.DOColor(Color.clear, 1.5f).SetId(thisIndex);
    }
    public void KillDOTween()
    {
        if (DOTween.IsTweening(thisIndex))
        {
            if (m_coroutine != null)
            {
                StopCoroutine(m_coroutine);
            }
            DOTween.Kill(thisIndex);      
        }
    }
}

2.管理腳本文件

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class MarqueeUIManager : MonoBehaviour
{
    [Header("時間間隔")]
    public float time_interval=0.05f;
    public RawImage m_firstImage; 
    public RawImage[] m_allImage;
 
    private Coroutine m_LeftCor;
    private Coroutine m_RightCor;
    private void Start()
    {
        m_firstImage.color=Color.clear;
        for (int i = 0; i < m_allImage.Length; i++)
        {
            m_allImage[i].color=Color.clear;
        }               
    }
        private void Update()
    {
        if (Input.GetKeyDown(KeyCode.L))
        {
            LeftRotationUI();
        }
        if (Input.GetKeyDown(KeyCode.R))
        {
            RightRotationUI();
        }
    }
    private void LeftRotationUI()
    {
        if (m_RightCor != null)
        {
            StopCoroutine(m_RightCor);
        }
          if(m_LeftCor!=null)
        {
            StopCoroutine(m_LeftCor);
        }
        m_LeftCor = StartCoroutine(LeftRoatation());
    }
    private void RightRotationUI()
    {
        if (m_LeftCor != null)
        {
            StopCoroutine(m_LeftCor);
        }
           if (m_RightCor != null)
        {
            StopCoroutine(m_RightCor);
        }
        m_RightCor = StartCoroutine(RightRoatation());
    }


    private IEnumerator LeftRoatation()
    {
        KillAllDOTween();
        yield return new WaitForSeconds(0.01f);
        m_firstImage.GetComponent<MarqueeUIItem>().UpdateImageColorA();
        yield return new WaitForSeconds(time_interval);
        for (int i = m_allImage.Length-1; i > -1; i--)
        {
            m_allImage[i].GetComponent<MarqueeUIItem>().UpdateImageColorA();
            yield return new WaitForSeconds(time_interval);
        }
        yield return new WaitForSeconds(time_interval);
        m_firstImage.GetComponent<MarqueeUIItem>().UpdateImageColorA();

    }
    private IEnumerator RightRoatation()
    {
        KillAllDOTween();
        yield return new WaitForSeconds(0.01f);
        m_firstImage.GetComponent<MarqueeUIItem>().UpdateImageColorA();
        yield return new WaitForSeconds(time_interval);
        for (int i = 0; i < m_allImage.Length; i++)
        {
            m_allImage[i].GetComponent<MarqueeUIItem>().UpdateImageColorA();
            yield return new WaitForSeconds(time_interval);
        }
        yield return new WaitForSeconds(time_interval);
        m_firstImage.GetComponent<MarqueeUIItem>().UpdateImageColorA();
    }
    private void KillAllDOTween()
    {
        m_firstImage.GetComponent<MarqueeUIItem>().KillDOTween();
        m_firstImage.color = Color.clear;
        for (int i = 0; i < m_allImage.Length; i++)
        {
            m_allImage[i].GetComponent<MarqueeUIItem>().KillDOTween();
            m_allImage[i].color = Color.clear;
        }
    }
}

設(shè)置

到此這篇關(guān)于Unity實現(xiàn)跑馬燈效果的示例代碼的文章就介紹到這了,更多相關(guān)Unity跑馬燈效果內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • C#檢測DataSet是否為空的方法

    C#檢測DataSet是否為空的方法

    這篇文章主要介紹了C#檢測DataSet是否為空的方法,涉及C#操作DataSet的技巧,非常簡單實用,需要的朋友可以參考下
    2015-04-04
  • C#偽彩色處理的具體方法

    C#偽彩色處理的具體方法

    這篇文章主要介紹了C#偽彩色處理的具體方法,需要的朋友可以參考下
    2014-02-02
  • C#利用接口實現(xiàn)多語種選擇功能

    C#利用接口實現(xiàn)多語種選擇功能

    這篇文章主要為大家詳細介紹了如何C#利用接口實現(xiàn)多語種選擇功能,即多語言切換的功能,文中的示例代碼講解詳細,感興趣的小伙伴可以了解下
    2024-02-02
  • 淺談c# 浮點數(shù)計算

    淺談c# 浮點數(shù)計算

    本文通過具體的示例給大家演示了下C#中浮點數(shù)運算所遇到的問題及解決方法,有需要的小伙伴可以參考下
    2017-09-09
  • C# InitializeComponent()方法案例詳解

    C# InitializeComponent()方法案例詳解

    這篇文章主要介紹了C# InitializeComponent()方法案例詳解,本篇文章通過簡要的案例,講解了該項技術(shù)的了解與使用,以下就是詳細內(nèi)容,需要的朋友可以參考下
    2021-08-08
  • unity實現(xiàn)弧形移動 可角度自定

    unity實現(xiàn)弧形移動 可角度自定

    這篇文章主要為大家詳細介紹了unity實現(xiàn)弧形移動,可角度自定,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2020-06-06
  • C#并查集(union-find)算法詳解

    C#并查集(union-find)算法詳解

    本文詳細講解了C#并查集(union-find)算法,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2022-04-04
  • C#判斷語句的表達式樹實現(xiàn)

    C#判斷語句的表達式樹實現(xiàn)

    這篇文章介紹了C#判斷語句的表達式樹實現(xiàn),文中通過示例代碼介紹的非常詳細。對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-01-01
  • C#連接MySQL數(shù)據(jù)庫的方法步驟

    C#連接MySQL數(shù)據(jù)庫的方法步驟

    最近兩天在解決C#連接MySql數(shù)據(jù)庫的問題,通過不同的從網(wǎng)上學(xué)習(xí),最終找到了解決的辦法,下面這篇文章主要給大家介紹了關(guān)于C#連接MySQL數(shù)據(jù)庫的方法步驟,需要的朋友可以參考下
    2023-01-01
  • C#簡單獲取全屏中鼠標焦點位置坐標的方法示例

    C#簡單獲取全屏中鼠標焦點位置坐標的方法示例

    這篇文章主要介紹了C#簡單獲取全屏中鼠標焦點位置坐標的方法,涉及C#針對鼠標位置Position屬性的簡單操作技巧,需要的朋友可以參考下
    2017-07-07

最新評論