查看: 704|回复: 0
打印 上一主题 下一主题

[其他] 开发技巧-携程方法库

[复制链接]
may    

8830

主题

80

听众

7万

积分

首席设计师

Rank: 8Rank: 8

纳金币
52304
精华
343

最佳新人 热心会员 灌水之王 活跃会员 突出贡献 荣誉管理 论坛元老

跳转到指定楼层
楼主
发表于 2018-8-23 21:14:17 |只看该作者 |倒序浏览

来自:UnityTerminator
  1. using UnityEngine;
  2. using System.Collections;

  3. public static class FunctionLibrary : object
  4. {
  5.     public delegate void myDelegate();
  6.     public delegate void myDelegateInt(int i);

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

  13.         Vector2 startPos = element.position;
  14.         Vector2 endPos = element.position;
  15.         endPos += ammount;

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

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

  29.         Vector2 startScale = element.localScale;

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

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

  43.         while (i < 1.0)
  44.         {
  45.             i += Time.deltaTime * rate;
  46.             yield return 0;
  47.         }

  48.         go.SetActive(state);
  49.     }
  50.     //Calls the passed void function with no arguments after delay
  51.     //调用传递的void函数,在延迟之后没有参数
  52.     public static IEnumerator CallWithDelay(myDelegate del, float delay)
  53.     {
  54.         yield return new WaitForSeconds(delay);
  55.         del();
  56.     }
  57.     //Calls the passed void function with  arguments after delay
  58.     //在延迟之后调用传递的void函数
  59.     public static IEnumerator CallWithDelay(myDelegateInt del, int num, float delay)
  60.     {
  61.         yield return new WaitForSeconds(delay);
  62.         del(num);
  63.     }
  64.     //Fade overlay opacity
  65.     //褪色覆盖不透明度
  66.     public static IEnumerator FadeScreen(SpriteRenderer overlay, float time, float to)
  67.     {
  68.         //Set the screen fade's color to end in time
  69.         float i = 0.0f;
  70.         float rate = 1.0f / time;

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

  73.         while (i < 1.0)
  74.         {
  75.             i += Time.deltaTime * rate;
  76.             overlay.color = Color.Lerp(start, end, i);
  77.             yield return 0;
  78.         }
  79.     }
  80. }
复制代码
分享到: QQ好友和群QQ好友和群 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
转播转播0 分享淘帖0 收藏收藏0 支持支持0 反对反对0
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

关闭

站长推荐上一条 /1 下一条

手机版|纳金网 ( 闽ICP备08008928号

GMT+8, 2024-5-7 06:48 , Processed in 0.079484 second(s), 29 queries .

Powered by Discuz!-创意设计 X2.5

© 2008-2019 Narkii Inc.

回顶部