PRParoxeBanner.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /*
  2. http://www.cgsoso.com/forum-211-1.html
  3. CG搜搜 Unity3d 每日Unity3d插件免费更新 更有VIP资源!
  4. CGSOSO 主打游戏开发,影视设计等CG资源素材。
  5. 插件如若商用,请务必官网购买!
  6. daily assets update for try.
  7. U should buy the asset from home store if u use it in your project!
  8. */
  9. using UnityEngine;
  10. using System.Collections;
  11. using UnityEditor;
  12. public class PRParoxeBanner
  13. {
  14. Texture2D m_ParoxeIcon;
  15. Texture2D m_TwitterIcon;
  16. Texture2D m_RatingIcon;
  17. Texture2D m_FacebookIcon;
  18. Texture2D m_OpenedIcon;
  19. Texture2D m_ClosedIcon;
  20. string m_Path;
  21. string ParoxePath
  22. {
  23. get { return Path("Paroxe32.png"); }
  24. }
  25. string TwitterPath
  26. {
  27. get { return Path("Twitter32.png"); }
  28. }
  29. string FacebookPath
  30. {
  31. get { return Path("Facebook32.png"); }
  32. }
  33. string RatingPath
  34. {
  35. get { return Path("Rating32.png"); }
  36. }
  37. string OpenedPath
  38. {
  39. get { return Path("Open32.png"); }
  40. }
  41. string ClosedPath
  42. {
  43. get { return Path("Close32.png"); }
  44. }
  45. public PRParoxeBanner(string path)
  46. {
  47. m_Path = path;
  48. Intilialize();
  49. }
  50. string Path(string rel)
  51. {
  52. return m_Path + "/" + rel;
  53. }
  54. Texture2D GetTexture(string path)
  55. {
  56. Texture2D tex = (Texture2D)AssetDatabase.LoadAssetAtPath(path, typeof(Texture2D));
  57. tex.hideFlags = HideFlags.HideAndDontSave;
  58. return tex;
  59. }
  60. void Intilialize()
  61. {
  62. m_ParoxeIcon = GetTexture(ParoxePath);
  63. m_TwitterIcon = GetTexture(TwitterPath);
  64. m_RatingIcon = GetTexture(RatingPath);
  65. m_FacebookIcon = GetTexture(FacebookPath);
  66. m_OpenedIcon = GetTexture(OpenedPath);
  67. m_ClosedIcon = GetTexture(ClosedPath);
  68. }
  69. void Space(float width, float height)
  70. {
  71. GUILayoutUtility.GetRect(width, height);
  72. }
  73. void Space()
  74. {
  75. float w = 4.0f;
  76. float h = 32 * 0.75f;
  77. Space(w,h);
  78. }
  79. bool OnCloseOpenGUI( bool isOpened)
  80. {
  81. Texture2D icon = isOpened ? m_ClosedIcon : m_OpenedIcon;
  82. Rect r = GUILayoutUtility.GetRect(icon.width * 0.3f, icon.height * 0.3f);
  83. GUI.DrawTexture(r, icon, ScaleMode.ScaleToFit);
  84. if (GUI.Button(r, "", new GUIStyle()))
  85. {
  86. return !isOpened;
  87. }
  88. return isOpened;
  89. }
  90. void OnInconGUI(Texture icon, string weblink)
  91. {
  92. Rect r = GUILayoutUtility.GetRect(icon.width*0.75f, icon.height*0.75f);
  93. GUI.DrawTexture(r, icon, ScaleMode.ScaleToFit);
  94. if (GUI.Button(r, "", new GUIStyle()))
  95. {
  96. Application.OpenURL(weblink);
  97. }
  98. }
  99. public bool DoOnGUI(bool isOpened)
  100. {
  101. EditorGUILayout.BeginHorizontal();
  102. GUILayout.FlexibleSpace();
  103. isOpened = OnCloseOpenGUI(isOpened);
  104. if (isOpened)
  105. {
  106. Space();
  107. OnInconGUI(m_ParoxeIcon, "http://paroxe.com/");
  108. Space();
  109. OnInconGUI(m_RatingIcon, "https://www.assetstore.unity3d.com/en/#!/content/32815");
  110. Space();
  111. OnInconGUI(m_TwitterIcon, "https://twitter.com/Paroxe_dev");
  112. Space();
  113. OnInconGUI(m_FacebookIcon, "https://www.facebook.com/paroxe.multimedia/");
  114. }
  115. EditorGUILayout.EndHorizontal();
  116. return isOpened;
  117. }
  118. }