游戏蛮牛学习群(纯技术交流,不闲聊):159852603
游戏蛮牛 手机端
开启辅助访问
 找回密码
 注册帐号

扫一扫,访问微社区

首页   >   博客   >   UnityTerminator

开发技巧-携程方法库 热度 1

个人分类: Unity-开发技巧 | 2018-7-18 11:02
0 个评论 | 阅读 162 | 收藏 | 举报

[code]csharpcode:

using UnityEngine;
using System.Collections;

public static class FunctionLibrary : object
{
    public delegate void myDelegate();
    public delegate void myDelegateInt(int i);

    //Moves a menu element by the received ammount in time
    //通过接收到的文件来移动菜单元素
    public static IEnumerator MoveElementBy(Transform element, Vector2 ammount, float time)
    {
        float i = 0.0f;
        float rate = 1.0f / time;

        Vector2 startPos = element.position;
        Vector2 endPos = element.position;
        endPos += ammount;

        while (i < 1.0)
        {
            i += Time.deltaTime * rate;
            element.localPosition = Vector3.Lerp(startPos, endPos, i);

            yield return 0;
        }
    }
    //Rescales the given element to the given scale in time
    //将给定的元素重新调整到给定的时间尺度
    public static IEnumerator ScaleTo(Transform element, Vector2 endScale, float time)
    {
        float i = 0.0f;
        float rate = 1.0f / time;

        Vector2 startScale = element.localScale;

        while (i < 1.0)
        {
            i += Time.deltaTime * rate;
            element.localScale = Vector3.Lerp(startScale, endScale, i);

            yield return 0;
        }
    }
    //Sets the active state of the go to state, after time
    //将状态的活动状态设置为状态
    public static IEnumerator ChangeEnabledState(GameObject go, bool state, float time)
    {
        float i = 0.0f;
        float rate = 1.0f / time;

        while (i < 1.0)
        {
            i += Time.deltaTime * rate;
            yield return 0;
        }

        go.SetActive(state);
    }
    //Calls the passed void function with no arguments after delay
    //调用传递的void函数,在延迟之后没有参数
    public static IEnumerator CallWithDelay(myDelegate del, float delay)
    {
        yield return new WaitForSeconds(delay);
        del();
    }
    //Calls the passed void function with  arguments after delay
    //在延迟之后调用传递的void函数
    public static IEnumerator CallWithDelay(myDelegateInt del, int num, float delay)
    {
        yield return new WaitForSeconds(delay);
        del(num);
    }
    //Fade overlay opacity
    //褪色覆盖不透明度
    public static IEnumerator FadeScreen(SpriteRenderer overlay, float time, float to)
    {
        //Set the screen fade's color to end in time
        float i = 0.0f;
        float rate = 1.0f / time;

        Color start = overlay.color;
        Color end = new Color(start.r, start.g, start.b, to);

        while (i < 1.0)
        {
            i += Time.deltaTime * rate;
            overlay.color = Color.Lerp(start, end, i);
            yield return 0;
        }
    }
}

1 0

评论 (0 个评论)

facelist doodle 涂鸦板

您需要登录后才可以评论 登录 | 注册帐号

个人分类

标签

阅读排行

评论排行

推荐博客

最新博客

返回顶部