Unity Boot Event-listener: Initializeonload

Source: Internet
Author: User

[initializeonload]: Run the editor script official case when you start unity:
  
 
  1. using UnityEngine;
  2. using UnityEditor;
  3. [InitializeOnLoad]
  4. public class Startup {
  5. static Startup()
  6. {
  7. Debug.Log("Up and running");
  8. }
  9. }
Print a word when you start Unity.
e.g. Siki:
  
 
  1. using UnityEditor;
  2. using UnityEngine;
  3. [InitializeOnLoad]
  4. public class Appload
  5. {
  6. static Appload()
  7. {
  8. bool hasKey = PlayerPrefs.HasKey("sikiwelcomescreen");
  9. if (hasKey==false)
  10. {
  11. //EditorApplication.update += Update;
  12. PlayerPrefs.SetInt("sikiwelcomescreen", 1);
  13. WelcomeScreen.ShowWindow();
  14. }
  15. }
  16. //static void Update()
  17. //{
  18. // bool isSuccess = EditorApplication.ExecuteMenuItem("Welcome Screen");
  19. // if (isSuccess) EditorApplication.update -= Update;
  20. //}
  21. }
  22. public class WelcomeScreen : EditorWindow
  23. {
  24. private Texture mSamplesImage;
  25. private Rect imageRect = new Rect(30f, 90f, 350f, 350f);
  26. private Rect textRect = new Rect(15f, 15f, 380f, 100f);
  27. public void OnEnable()
  28. {
  29. //this.mWelcomeScreenImage = EditorGUIUtility.Load("WelcomeScreenHeader.png") as Texture;
  30. //BehaviorDesignerUtility.LoadTexture("WelcomeScreenHeader.png", false, this);
  31. this.mSamplesImage = LoadTexture("wechat.jpg");
  32. }
  33. Texture LoadTexture(string name)
  34. {
  35. string path = "Assets/PlayMaker/Editor/";
  36. return (Texture)AssetDatabase.LoadAssetAtPath(path + name, typeof(Texture));
  37. }
  38. public void OnGUI()
  39. {
  40. //GUI.DrawTexture(this.mWelcomeScreenImageRect, this.mWelcomeScreenImage);
  41. GUIStyle style = new GUIStyle();
  42. style.fontSize = 14;
  43. style.normal.textColor = Color.white;
  44. GUI.Label(this.textRect, "欢迎扫一扫siki的,关注号\n我会在上面推送一套关于独立游戏开发者的游戏视频教程 免费的!\n时刻更新中!\n这个页面只会显示一次",style);
  45. GUI.DrawTexture(this.imageRect, this.mSamplesImage);
  46. }
  47. public static void ShowWindow()
  48. {
  49. welcomescreen window = editorwindow getwindow < welcomescreen > ( true Hello hi, I'm Your dearest siki teacher.
  50. window.minSize = window.maxSize = new Vector2(410f, 470f);
  51. UnityEngine.Object.DontDestroyOnLoad(window);
  52. }
  53. }



From for Notes (Wiz)

Unity Boot Event-listener: Initializeonload

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.