LightningBoltEditor.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using System;
  2. using UnityEngine;
  3. using UnityEditor;
  4. namespace DigitalRuby.LightningBolt
  5. {
  6. [CustomEditor(typeof(LightningBoltScript))]
  7. public class LightningBoltEditor : Editor
  8. {
  9. private Texture2D logo;
  10. public override void OnInspectorGUI()
  11. {
  12. if (logo == null)
  13. {
  14. string[] guids = AssetDatabase.FindAssets("LightningBoltLogo");
  15. foreach (string guid in guids)
  16. {
  17. string path = AssetDatabase.GUIDToAssetPath(guid);
  18. logo = AssetDatabase.LoadMainAssetAtPath(path) as Texture2D;
  19. if (logo != null)
  20. {
  21. break;
  22. }
  23. }
  24. }
  25. if (logo != null)
  26. {
  27. const float maxLogoWidth = 430.0f;
  28. EditorGUILayout.Separator();
  29. float w = EditorGUIUtility.currentViewWidth;
  30. Rect r = new Rect();
  31. r.width = Math.Min(w - 40.0f, maxLogoWidth);
  32. r.height = r.width / 2.7f;
  33. Rect r2 = GUILayoutUtility.GetRect(r.width, r.height);
  34. r.x = ((EditorGUIUtility.currentViewWidth - r.width) * 0.5f) - 4.0f;
  35. r.y = r2.y;
  36. GUI.DrawTexture(r, logo, ScaleMode.StretchToFill);
  37. if (GUI.Button(r, "", new GUIStyle()))
  38. {
  39. Application.OpenURL("https://www.assetstore.unity3d.com/en/#!/content/34217?aid=1011lGnL");
  40. }
  41. EditorGUILayout.Separator();
  42. }
  43. DrawDefaultInspector();
  44. }
  45. }
  46. }