InspectorUtility.cs 2.7 KB

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