查看: 1322|回复: 3
打印 上一主题 下一主题

[其他] Unity3d中渐隐检出代码

[复制链接]

2722

主题

42

听众

3万

积分

资深设计师

Rank: 7Rank: 7Rank: 7

纳金币
38268
精华
111

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

跳转到指定楼层
楼主
发表于 2014-6-26 20:02:54 |只看该作者 |倒序浏览
  1. using UnityEngine;
  2. using System.Collections;
  3. public class SplashScreen : MonoBehaviour
  4. {
  5. public string levelToLoad = ""; // this has to correspond to a level (file>build settings) public Texture2D splashLogo; // the logo to splash;
  6. public float fadeSpeed = 0.3f;
  7. public float waitTime = 0.5f; // seconds to wait before fading out
  8. public bool waitForInput = false; // if true, this acts as a "press any key to continue" private float timeFadingInFinished = 0.0f;
  9. public enum SplashType
  10. {
  11. LoadNextLevelThenFadeOut,
  12. FadeOutThenLoadNextLevel
  13. }
  14. public SplashType splashType;
  15. private float alpha = 0.0f;
  16. private enum FadeStatus
  17. {
  18. FadeIn,
  19. FadeWaiting,
  20. FadeOut
  21. }
  22. private FadeStatus status = FadeStatus.FadeIn;
  23. private Camera oldCam;
  24. private GameObject oldCamGO;

  25.         private Rect splashLogoPos = new Rect();



  26.         public enum LogoPositioning



  27.         {



  28.         Centered,



  29.         Stretched



  30.         }



  31.         public LogoPositioning logoPositioning;



  32.         private bool loadingNextLevel = false;



  33.         void Start()



  34.         {



  35.         oldCam = Camera.main;



  36.         oldCamGO = Camera.main.gameObject;



  37.         if (logoPositioning == LogoPositioning.Centered)



  38.         {



  39.         splashLogoPos.x = (Screen.width * 0.5f) - (splashLogo.width * 0.5f); splashLogoPos.y = (Screen.height * 0.5f) - (splashLogo.height * 0.5f);



  40.         splashLogoPos.width = splashLogo.width;



  41.         splashLogoPos.height = splashLogo.height;



  42.         }



  43.         else



  44.         {



  45.         splashLogoPos.x = 0;



  46.         splashLogoPos.y = 0;



  47.         splashLogoPos.width = Screen.width;



  48.         splashLogoPos.height = Screen.height;



  49.         }


  50.         if (splashType == SplashType.LoadNextLevelThenFadeOut)



  51.         {



  52.         DontDestroyOnLoad(this);



  53.         DontDestroyOnLoad(Camera.main);



  54.         }



  55.         if ((Application.levelCount <= 1) || (levelToLoad == ""))



  56.         {



  57.         Debug.Log("I need to have a level to load or the value of level To load is wrong!"); return;



  58.         }



  59.         }



  60.         void Update()



  61.         {



  62.         switch(status)



  63.         {



  64.         case FadeStatus.FadeIn:



  65.         alpha += fadeSpeed * Time.deltaTime;



  66.         break;



  67.         case FadeStatus.FadeWaiting:



  68.         if ((!waitForInput && Time.time >= timeFadingInFinished + waitTime) || (waitForInput && Input.anyKey))



  69.         {



  70.         status = FadeStatus.FadeOut;



  71.         }



  72.         break;



  73.         case FadeStatus.FadeOut:



  74.         alpha += -fadeSpeed * Time.deltaTime;



  75.         break;




  76.         }


  77.         }


  78.         void OnGUI()


  79.         {


  80.         if (splashLogo != null)


  81.         {


  82.         GUI.color = new Color(GUI.color.r, GUI.color.g, GUI.color.b, Mathf.Clamp01(alpha)); GUI.DrawTexture(splashLogoPos, splashLogo);


  83.         if (alpha > 1.0f)


  84.         {


  85.         status = FadeStatus.FadeWaiting;


  86.         timeFadingInFinished = Time.time;


  87.         alpha = 1.0f;


  88.         if (splashType == SplashType.LoadNextLevelThenFadeOut)


  89.         {


  90.         oldCam.depth = -1000;


  91.         loadingNextLevel = true;


  92.         Application.LoadLevel(levelToLoad);


  93.         }


  94.         }


  95.         if (alpha < 0.0f)


  96.         {


  97.         if (splashType == SplashType.FadeOutThenLoadNextLevel)


  98.         {


  99.         Application.LoadLevel(levelToLoad);


  100.         }


  101.         else


  102.         {


  103.         Destroy(oldCamGO); // somehow this doesn't work


  104.         Destroy(this);



  105.         }


  106.         }


  107.         }


  108.         }


  109.         void OnLevelWasLoaded(int lvlIdx)


  110.         {


  111.         if (loadingNextLevel)


  112.         {


  113.         Destroy(oldCam.GetComponent<AudioListener>()); Destroy(oldCam.GetComponent<GUILayer>()); }


  114.         }


  115.         void OnDrawGizmos()


  116.         {


  117.         Gizmos.color = new Color(1f, 0f, 0f, .5f);


  118.         Gizmos.DrawCube(transform.position, new Vector3(1, 1, 1)); }


  119.         }
复制代码
分享到: QQ好友和群QQ好友和群 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
转播转播0 分享淘帖0 收藏收藏0 支持支持0 反对反对0
回复

使用道具 举报

hyui    

1

主题

2

听众

6671

积分

高级设计师

Rank: 6Rank: 6

纳金币
2715
精华
0

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

沙发
发表于 2014-6-26 21:21:13 |只看该作者
感谢分享这个!
回复

使用道具 举报

115

主题

3

听众

5676

积分

高级设计师

Rank: 6Rank: 6

纳金币
7268
精华
0

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

板凳
发表于 2014-6-26 22:37:32 |只看该作者
Thanks for sharing !
回复

使用道具 举报

wucnj    

1

主题

1

听众

3160

积分

中级设计师

Rank: 5Rank: 5

纳金币
1065
精华
0

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

地板
发表于 2014-6-27 13:18:56 |只看该作者
感谢分享!!!
回复

使用道具 举报

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

手机版|纳金网 ( 闽ICP备2021016425号-2/3

GMT+8, 2024-9-22 15:28 , Processed in 0.209928 second(s), 32 queries .

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

© 2008-2019 Narkii Inc.

回顶部