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.

66 lines
1.9KB

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