InspectorUtility.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. /// <summary>
  47. /// States an inspectable object can be in. Higher states override lower states.
  48. /// </summary>
  49. [Flags]
  50. public enum InspectableState
  51. {
  52. /// <summary>Object was not modified this frame.</summary>
  53. NotModified,
  54. /// <summary>Object is currently being modified.</summary>
  55. ModifyInProgress = 1,
  56. /// <summary>Object was modified and modifications were confirmed.</summary>
  57. Modified = 3
  58. }
  59. }