InspectorUtility.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Runtime.CompilerServices;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using BansheeEngine;
  8. namespace BansheeEditor
  9. {
  10. /// <summary>
  11. /// Contains utility methods relating to inspector window.
  12. /// </summary>
  13. public class InspectorUtility
  14. {
  15. /// <summary>
  16. /// Creates an inspector capable of displaying GUI elements for an object of the provided type.
  17. /// </summary>
  18. /// <param name="type">Type of the object that will be displayed in the inspector.</param>
  19. /// <returns>Custom user defined inspector if it exists for the provided type, or the generic inspector.</returns>
  20. public static Inspector GetInspector(Type type)
  21. {
  22. Inspector customInspector = Internal_GetCustomInspector(type);
  23. if (customInspector != null)
  24. return customInspector;
  25. return new GenericInspector();
  26. }
  27. /// <summary>
  28. /// Gets an <see cref="InspectableField"/> implementation for the specified type. This only searches custom user
  29. /// defined implementations, not the built-in ones.
  30. /// </summary>
  31. /// <param name="type">Type of the object to find an <see cref="InspectableField"/> for.</param>
  32. /// <returns>Implementation of <see cref="InspectableField"/> capable of display contents of the provided type,
  33. /// or null if one wasn't found.</returns>
  34. public static Type GetCustomInspectable(Type type)
  35. {
  36. Type customInspectable = Internal_GetCustomInspectable(type);
  37. if (customInspectable != null)
  38. return customInspectable;
  39. return null;
  40. }
  41. [MethodImpl(MethodImplOptions.InternalCall)]
  42. private static extern Inspector Internal_GetCustomInspector(Type type);
  43. [MethodImpl(MethodImplOptions.InternalCall)]
  44. private static extern Type Internal_GetCustomInspectable(Type type);
  45. }
  46. }