InspectorUtility.cs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. using System;
  4. using System.Runtime.CompilerServices;
  5. using bs;
  6. namespace bs.Editor
  7. {
  8. /** @addtogroup Inspector
  9. * @{
  10. */
  11. /// <summary>
  12. /// Contains utility methods relating to inspector window.
  13. /// </summary>
  14. public class InspectorUtility
  15. {
  16. /// <summary>
  17. /// Creates an inspector capable of displaying GUI elements for an object of the provided type.
  18. /// </summary>
  19. /// <param name="type">Type of the object that will be displayed in the inspector.</param>
  20. /// <returns>Custom user defined inspector if it exists for the provided type, or the generic inspector.</returns>
  21. public static Inspector GetInspector(Type type)
  22. {
  23. Inspector customInspector = Internal_GetCustomInspector(type);
  24. if (customInspector != null)
  25. return customInspector;
  26. return new GenericInspector();
  27. }
  28. /// <summary>
  29. /// Gets an <see cref="InspectableField"/> implementation for the specified type. This only searches custom user
  30. /// defined implementations, not the built-in ones.
  31. /// </summary>
  32. /// <param name="type">Type of the object to find an <see cref="InspectableField"/> for.</param>
  33. /// <returns>Implementation of <see cref="InspectableField"/> capable of display contents of the provided type,
  34. /// or null if one wasn't found.</returns>
  35. public static Type GetCustomInspectable(Type type)
  36. {
  37. Type customInspectable = Internal_GetCustomInspectable(type);
  38. if (customInspectable != null)
  39. return customInspectable;
  40. return null;
  41. }
  42. [MethodImpl(MethodImplOptions.InternalCall)]
  43. private static extern Inspector Internal_GetCustomInspector(Type type);
  44. [MethodImpl(MethodImplOptions.InternalCall)]
  45. private static extern Type Internal_GetCustomInspectable(Type type);
  46. }
  47. /// <summary>
  48. /// States an inspectable object can be in. Higher states override lower states.
  49. /// </summary>
  50. [Flags]
  51. public enum InspectableState
  52. {
  53. /// <summary>Object was not modified this frame.</summary>
  54. NotModified,
  55. /// <summary>Object is currently being modified.</summary>
  56. ModifyInProgress = 1,
  57. /// <summary>Object was modified and modifications were confirmed.</summary>
  58. Modified = 3
  59. }
  60. /** @} */
  61. }