Mirror of Svelto.ECS because we're a fan of it
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
1.9KB

  1. #if UNITY_EDITOR
  2. using UnityEditor;
  3. using UnityEngine;
  4. //This profiler is based on the Entitas Visual Debugging tool
  5. //https://github.com/sschmid/Entitas-CSharp
  6. namespace Svelto.ECS.Profiler
  7. {
  8. public static class ProfilerEditorLayout
  9. {
  10. public static void ShowWindow<T>(string title) where T : EditorWindow
  11. {
  12. var window = EditorWindow.GetWindow<T>(true, title);
  13. window.minSize = window.maxSize = new Vector2(415f, 520f);
  14. window.Show();
  15. }
  16. public static Texture2D LoadTexture(string label)
  17. {
  18. var guid = AssetDatabase.FindAssets(label)[0];
  19. if (guid != null)
  20. {
  21. var path = AssetDatabase.GUIDToAssetPath(guid);
  22. return AssetDatabase.LoadAssetAtPath<Texture2D>(path);
  23. }
  24. return null;
  25. }
  26. public static float DrawHeaderTexture(EditorWindow window, Texture2D texture)
  27. {
  28. const int scollBarWidth = 15;
  29. var ratio = texture.width/texture.height;
  30. var width = window.position.width - 8 - scollBarWidth;
  31. var height = width/ratio;
  32. GUI.DrawTexture(new Rect(4, 2, width, height), texture, ScaleMode.ScaleToFit);
  33. return height;
  34. }
  35. public static Rect BeginVertical()
  36. {
  37. return EditorGUILayout.BeginVertical();
  38. }
  39. public static Rect BeginVerticalBox(GUIStyle style = null)
  40. {
  41. return EditorGUILayout.BeginVertical(style ?? GUI.skin.box);
  42. }
  43. public static void EndVertical()
  44. {
  45. EditorGUILayout.EndVertical();
  46. }
  47. public static Rect BeginHorizontal()
  48. {
  49. return EditorGUILayout.BeginHorizontal();
  50. }
  51. public static void EndHorizontal()
  52. {
  53. EditorGUILayout.EndHorizontal();
  54. }
  55. }
  56. }
  57. #endif