中文字幕av专区_日韩电影在线播放_精品国产精品久久一区免费式_av在线免费观看网站

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

Unity3D UGUI實現翻書特效

發布時間:2020-08-19 13:42:48 來源:腳本之家 閱讀:190 作者:碼農小飛飛 欄目:編程語言

本文實例為大家分享了Unity3D UGUI翻書展示的具體代碼,供大家參考,具體內容如下

參考大佬的,鏈接找不到了,找到了再加在這。

下邊是Shader代碼:

// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
 
Shader "Personal/PageTurning" {
 Properties 
 {
 _Color ("Color", Color) = (1,1,1,1)
 _MainTex("MainTex",2D)="White"{}
 _SecTex("SecTex",2D)="White"{}
 _Angle("Angle",Range(0,180))=0
 _Warp("Warp",Range(0,10))=0
 _WarpPos("WarpPos",Range(0,1))=0
 _Downward("Downward",Range(0,1))=0
 }
 SubShader
 {
 pass
 {
  Cull Back
 
  CGPROGRAM
  #pragma vertex vert 
  #pragma fragment frag 
  #include "UnityCG.cginc"
 
  struct v2f 
  {
  float4 pos : POSITION;
  float2 uv : TEXCOORD0;
  };
  fixed4 _Color;
  float _Angle;
  float _Warp;
  float _Downward;
  float _WarpPos;
  sampler2D _MainTex;
  float4 _MainTex_ST;
 
  v2f vert(appdata_base v)
  {
  v2f o;
  v.vertex += float4(5,0,0,0);
  float s;
  float c;
  sincos(radians(-_Angle),s,c);
  float4x4 rotate={  
  c,s,0,0,
  -s,c,0,0,
  0,0,1,0,
  0,0,0,1};
  float rangeF=saturate(1 - abs(90-_Angle)/90);
  v.vertex.y += -_Warp*sin(v.vertex.x*0.4-_WarpPos* v.vertex.x)*rangeF;
  v.vertex.x -= rangeF * v.vertex.x*_Downward;
  v.vertex = mul(rotate,v.vertex);
  
  v.vertex += float4(-5,0,0,0);
  o.pos = UnityObjectToClipPos(v.vertex);
  o.uv = TRANSFORM_TEX(v.texcoord,_MainTex);
  return o;
  }
 
  fixed4 frag(v2f i):COLOR
  {
  fixed4 color = tex2D(_MainTex,-i.uv);
  return _Color * color;
  }
 
 
  ENDCG
 }
 
 pass
 {
  Cull Front
 
  CGPROGRAM
  #pragma vertex vert 
  #pragma fragment frag 
  #include "UnityCG.cginc"
 
  struct v2f 
  {
  float4 pos : POSITION;
  float2 uv : TEXCOORD0;
  };
  fixed4 _Color;
  float _Angle;
  float _Warp;
  float _Downward;
  float _WarpPos;
  sampler2D _SecTex;
  float4 _MainTex_ST;
 
  v2f vert(appdata_base v)
  {
  v2f o;
  v.vertex += float4(5,0,0,0);
  float s;
  float c;
  sincos(radians(-_Angle),s,c);
  float4x4 rotate={  
  c,s,0,0,
  -s,c,0,0,
  0,0,1,0,
  0,0,0,1};
  float rangeF=saturate(1 - abs(90-_Angle)/90);
  v.vertex.y += -_Warp*sin(v.vertex.x*0.4-_WarpPos* v.vertex.x)*rangeF;
  v.vertex.x -= rangeF * v.vertex.x*_Downward;
  v.vertex = mul(rotate,v.vertex);
  
  v.vertex += float4(-5,0,0,0);
  o.pos = UnityObjectToClipPos(v.vertex);
  o.uv = TRANSFORM_TEX(v.texcoord,_MainTex);
  return o;
  }
 
  fixed4 frag(v2f i):COLOR
  {
  float2 uv = i.uv;
  uv.x = -uv.x;
  fixed4 color = tex2D(_SecTex,-uv);
  return _Color * color;
  }
  ENDCG
 }
 }
}

下面是UI代碼:

using System.Collections;
using UnityEngine;
using UnityEngine.UI;
 
public class FanShuUI : UIBase
{
  private GameObject Plane;
  private Material m_Material;
  private Coroutine effect;
  private Image LeftPage;
  private Image RightPage;
  private void Awake()
  {
    InitUI();
  }
  public override void InitUI()
  {
    Plane = GetGameObject("Plane");
    LeftPage = GetComp<Image>("LeftPage");
    RightPage = GetComp<Image>("RightPage");
    Plane.SetActive(false);
    m_Material = Plane.GetComponent<MeshRenderer>().material;
  }
  public void PlayPageTurnEffect(bool isLeft = true)
  {
    if (!gameObject.activeSelf)
    {
      return;
    }
    if (effect != null)
    {
      StopCoroutine(effect);
    }
    effect = StartCoroutine(FanShuEffect(0.5f, isLeft));
  }
  public void ShowRightImage(string right)
  {
    RightPage.gameObject.SetActive(true);
    RightPage.sprite = ResourcesMgr.Instance.LoadObj<Sprite>(right);
  }
  public void ShowLeftImage(string left)
  {
    LeftPage.gameObject.SetActive(true);
    LeftPage.sprite = ResourcesMgr.Instance.LoadObj<Sprite>(left);
  }
  private IEnumerator FanShuEffect(float time, bool isLeft)
  {
    LeftPage.gameObject.SetActive(false);
    RightPage.gameObject.SetActive(false);
    Plane.SetActive(true);
    int angle = (int)(180 * 0.1f);
    for (int i = 0; i < 10; i++)
    {
      if (isLeft)
      {
        m_Material.SetFloat("_Angle", angle * i);
      }
      else
      {
        m_Material.SetFloat("_Angle", 180 - angle * i);
      }
      yield return new WaitForSeconds(time * 0.1f);
    }
    if (isLeft)
    {
      m_Material.SetFloat("_Angle", 180);
    }
    else
    {
      m_Material.SetFloat("_Angle", 0);
    }
    Plane.SetActive(false);
    OnEffectOver();
  }
  private void OnEffectOver()
  {
    //--callback
  }
}

左右兩頁紙可以在翻書結束動態加載圖片。

下邊是Plane的面板信息:

Unity3D UGUI實現翻書特效

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持億速云。

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

新源县| 海淀区| 临湘市| 定西市| 静海县| 定州市| 屏东市| 大同县| 扶绥县| 沙河市| 察雅县| 高密市| 江北区| 兴义市| 平顶山市| 房产| 桃园县| 长垣县| 商丘市| 连城县| 扎赉特旗| 察雅县| 神农架林区| 广丰县| 东乡族自治县| 丹东市| 麻江县| 河源市| 资讯| 朝阳县| 旬邑县| 库伦旗| 万宁市| 西青区| 江孜县| 郎溪县| 石屏县| 云龙县| 镇安县| 阜城县| 湾仔区|