亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Unity3D實(shí)現(xiàn)扭動(dòng)擠壓瀏覽效果

 更新時(shí)間:2020年04月15日 10:07:18   作者:即步  
這篇文章主要為大家詳細(xì)介紹了Unity3D實(shí)現(xiàn)扭動(dòng)擠壓瀏覽效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

最近的項(xiàng)目中,想做到一種能夠吸引眼球的一種角色選擇瀏覽效果

Demo源碼:點(diǎn)擊打開(kāi)鏈接

最終實(shí)現(xiàn)了下按如下圖這么一種瀏覽效果:

效果圖一

效果圖二

可能要實(shí)現(xiàn)這么一種效果用動(dòng)畫插件會(huì)很快,但總感覺(jué)有點(diǎn)大材小用
這里我向大家分享一個(gè)極簡(jiǎn)方式來(lái)實(shí)現(xiàn)這么一種效果

目錄結(jié)構(gòu)如下

其中Items有4個(gè)Image子節(jié)點(diǎn)

在父節(jié)點(diǎn)Items下添加如下圖橫向布局組件

在其4個(gè)Image子節(jié)點(diǎn)下添加如下圖布局元素組件

完成這些步驟后接下來(lái)就是代碼實(shí)現(xiàn)了
在Items添加如下腳本組件

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
 
public class Items : MonoBehaviour
{
 public List<GameObject> items = new List<GameObject>();
 
 //縮放時(shí)間
 public float time = 1.3f;
 
 //原先大小
 public Vector2 oldSize;
 
 //放大縮小速度
 public float speed;
 
 private void Start()
 {
 for (int i = 0; i < items.Count; i++)
 {
 EventTriggerListener.GetComponent(items[i]).onEnter = OnMouseEnter;
 EventTriggerListener.GetComponent(items[i]).onExit = OnMouseExit;
 }
 }
 
 
 void OnMouseEnter(GameObject go)
 {
 EventTriggerListener.GetComponent(go).UpdateSize(oldSize * time, speed);
 }
 
 void OnMouseExit(GameObject go)
 {
 EventTriggerListener.GetComponent(go).UpdateSize(oldSize, speed);
 }
}

在其4個(gè)子節(jié)點(diǎn)下添加如下腳本組件

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
 
[RequireComponent(typeof(LayoutElement))]
public class EventTriggerListener : EventTrigger
{
 public delegate void VoidDelegate(GameObject obj);
 //點(diǎn)擊
 public VoidDelegate onClick;
 //鼠標(biāo)按下
 public VoidDelegate onDown;
 //鼠標(biāo)抬起
 public VoidDelegate onUp;
 //鼠標(biāo)移入
 public VoidDelegate onEnter;
 //鼠標(biāo)移出
 public VoidDelegate onExit;
 
 private Vector2 currentSize;
 private Vector2 targetSize;
 private float speed = 4.0f;
 
 public static EventTriggerListener GetComponent(GameObject obj)
 {
 EventTriggerListener listener = obj.GetComponent<EventTriggerListener>();
 if (listener == null)
 {
 listener = obj.AddComponent<EventTriggerListener>();
 }
 
 return listener;
 }
 
 
 public override void OnPointerClick(PointerEventData eventData)
 {
 if (onClick != null)
 {
 onClick(gameObject);
 }
 }
 public override void OnPointerDown(PointerEventData eventData)
 {
 if (onDown != null) onDown(gameObject);
 }
 public override void OnPointerUp(PointerEventData eventData)
 {
 if (onUp != null) onUp(gameObject);
 }
 public override void OnPointerEnter(PointerEventData eventData)
 {
 if (onEnter != null) onEnter(gameObject);
 }
 public override void OnPointerExit(PointerEventData eventData)
 {
 if (onExit != null) onExit(gameObject);
 }
 
 
 
 private void Start()
 {
 targetSize = currentSize = new Vector2(this.GetComponent<LayoutElement>().preferredWidth, this.GetComponent<LayoutElement>().preferredHeight);
 }
 
 private void Update()
 {
 if (currentSize != targetSize)
 {
 currentSize = Vector2.Lerp(currentSize, targetSize, Time.deltaTime * speed);
 if (Vector2.Distance(currentSize, targetSize) <= 0.01)
 {
 currentSize = targetSize;
 }
 
 this.GetComponent<LayoutElement>().preferredWidth = currentSize.x;
 this.GetComponent<LayoutElement>().preferredHeight = currentSize.y;
 }
 }
 
 public void UpdateSize(Vector2 size,float speed)
 {
 this.targetSize = size;
 this.speed = speed;
 }
}

腳本掛載上去后,在Item下按如下圖方式設(shè)值

可以按自己喜好調(diào)整數(shù)值。

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • .NET中的Timer類型用法詳解

    .NET中的Timer類型用法詳解

    這篇文章主要介紹了.NET中的Timer類型用法,較為詳細(xì)的分析了Timer類型在各種環(huán)境下的用法,需要的朋友可以參考下
    2014-08-08
  • c# 獲取網(wǎng)頁(yè)中指定的字符串信息的實(shí)例代碼

    c# 獲取網(wǎng)頁(yè)中指定的字符串信息的實(shí)例代碼

    c# 獲取網(wǎng)頁(yè)中指定的字符串信息的實(shí)例代碼,需要的朋友可以參考一下
    2013-04-04
  • C#中免費(fèi)密碼庫(kù)BouncyCastle的使用詳解

    C#中免費(fèi)密碼庫(kù)BouncyCastle的使用詳解

    這篇文章主要來(lái)和大家分享一個(gè)C#版開(kāi)源、免費(fèi)的Bouncy?Castle密碼庫(kù):BouncyCastle,文中介紹了BouncyCastle的具體使用,需要的可以參考下
    2024-03-03
  • C#枚舉類型與位域枚舉Enum

    C#枚舉類型與位域枚舉Enum

    這篇文章介紹了C#中的枚舉類型與位域枚舉Enum,文中通過(guò)示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2022-05-05
  • 快速學(xué)習(xí)C# 設(shè)計(jì)模式之職責(zé)鏈模式

    快速學(xué)習(xí)C# 設(shè)計(jì)模式之職責(zé)鏈模式

    這篇文章主要介紹了C# 設(shè)計(jì)模式之職責(zé)鏈模式的的相關(guān)資料,文中代碼非常細(xì)致,幫助大家更好的理解和學(xué)習(xí),感興趣的朋友可以了解下
    2020-06-06
  • c#基礎(chǔ)系列之值類型和引用類型的深入理解

    c#基礎(chǔ)系列之值類型和引用類型的深入理解

    這篇文章主要給大家介紹了關(guān)于c#基礎(chǔ)系列之值類型和引用類型的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2018-09-09
  • c#匹配整數(shù)和小數(shù)的正則表達(dá)式

    c#匹配整數(shù)和小數(shù)的正則表達(dá)式

    c#中使用正則表達(dá)式需要加入using System.Text.RegularExpressions的引用
    2010-12-12
  • C#讀取word中表格數(shù)據(jù)的方法實(shí)現(xiàn)

    C#讀取word中表格數(shù)據(jù)的方法實(shí)現(xiàn)

    本文主要介紹了C#讀取word中表格數(shù)據(jù)的方法實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2022-06-06
  • C# 中this關(guān)鍵字的主要作用

    C# 中this關(guān)鍵字的主要作用

    this 關(guān)鍵字在C#中主要用于引用當(dāng)前對(duì)象,區(qū)分字段與局部變量,調(diào)用其他構(gòu)造函數(shù)以及傳遞當(dāng)前對(duì)象給其他方法或構(gòu)造函數(shù),本文重點(diǎn)介紹C# this關(guān)鍵字的作用,感興趣的朋友一起看看吧
    2024-02-02
  • c# for循環(huán)中創(chuàng)建線程執(zhí)行問(wèn)題

    c# for循環(huán)中創(chuàng)建線程執(zhí)行問(wèn)題

    這篇文章主要介紹了有關(guān)c# for循環(huán)中創(chuàng)建線程執(zhí)行問(wèn)題,下面文章將將以舉例的方式展開(kāi)for循環(huán)中創(chuàng)建線程執(zhí)行問(wèn)題的內(nèi)容,需要的朋友可以參考一下,希望對(duì)你有所幫助
    2021-11-11

最新評(píng)論