zoukankan      html  css  js  c++  java
  • unity3d中使用Ngui实现幻灯片效果

    首先添加一个Simple Texture用来当做幻灯片的对象。
     
     
    新建一个材质,着色器选择如图
     
    在Simple Texture上选择我们刚刚建立的材质
     
    最后上代码
    using UnityEngine;
    using System.Collections;

    public class SlideShow : MonoBehaviour
    {

        public float waitTime;
        float tm;
        //TweenColor tc;
        bool isshow = false;
        TweenColor[] tcs;
        public string url;
        public int count;
        int index=0;
        void Start ()
        {
            this.gameObject.AddComponent<TweenColor> ();    
            this.gameObject.AddComponent<TweenColor> ();
            tcs = GetComponents<TweenColor> ();
            tcs [0].enabled = false;
            tcs [1].enabled = false;
            tcs [0].from = new Color (1, 1, 1, 1);
            tcs [0].to = new Color (1, 1, 1, 0);
            tcs [1].from = new Color (1, 1, 1, 0);
            tcs [1].to = new Color (1, 1, 1, 1);
            tcs [0].eventReceiver = this.gameObject;
            tcs [0].callWhenFinished = "endChange";
            tcs [0].duration = 1;
            tcs [1].duration = 1;
        }
        // Update is called once per frame
        void Update ()
        {
            tm += Time.deltaTime;
            if (tm > waitTime) {
                if(index<count-1)
                {
                    index++;
                }
                else
                {
                    index=0;
                }
                startChange ();
                tm = 0;
            }
        }

        void startChange ()
        {

            tcs [0].Reset ();
            tcs [0].enabled = true;
            Debug.Log ("Start");        
        }

        void endChange ()
        {
            UITexture ut=GetComponent<UITexture>();
            ut.material.mainTexture=Resources.Load(url+index.ToString()) as Texture;
            tcs [1].Reset ();
            tcs [1].enabled = true;
        }
    }
    填写参数,完成!~
     





  • 相关阅读:
    二进制兼容
    non-fragile:oc2.0特性--继承结构的父类内存布局变化时子类是否需要重新编译的问题
    [objc explain]: Non-fragile ivars
    函数响应式编程(FRP)思想-Callback风格
    FRP-Functional Reactive Programming-函数响应式编程
    AWESOME SWIFT-swift.libhunt.com-swift类库网站
    iOS
    视图逻辑、应用逻辑、业务逻辑
    laravel微信自定义分享
    实现手机网页调起原生微信朋友圈分享的工具nativeShare.js
  • 原文地址:https://www.cnblogs.com/leestar54/p/3013296.html
Copyright © 2011-2022 走看看