BsScriptSerializableField.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsScriptEnginePrerequisites.h"
  5. #include "BsScriptObject.h"
  6. namespace bs
  7. {
  8. /** @addtogroup ScriptInteropEngine
  9. * @{
  10. */
  11. /** Contains information about a style of a serializable field. */
  12. struct SerializableMemberStyle // Note: Must match C# struct SerializableFieldStyle
  13. {
  14. bool hasRange; /**< True if the range of the field is limited, false if unlimited. */
  15. float rangeMin; /**< Returns the lower bound of the range. Only relevant if @see hasRange is true. */
  16. float rangeMax; /**< Returns the upper bound of the range. Only relevant if @see hasRange is true. */
  17. bool hasStep; /**< True if the field value can only be incremented in specific increments. */
  18. /** Minimum increment the field value can be increment/decremented by. Only relevant if @see hasStep is true. */
  19. float stepIncrement;
  20. bool displayAsSlider; /**< If true, number fields will be displayed as sliders instead of regular input boxes. */
  21. bool displayAsLayerMask; /**< If true, 64-bit fields will be displayed as a layer mask drop down menu. */
  22. };
  23. /** Interop class between C++ & CLR for ManagedSerializableFieldInfo. */
  24. class BS_SCR_BE_EXPORT ScriptSerializableField : public ScriptObject<ScriptSerializableField>
  25. {
  26. public:
  27. SCRIPT_OBJ(ENGINE_ASSEMBLY, "BansheeEngine", "SerializableField")
  28. /**
  29. * Creates a new serializable field interop object that references a specific field on a specific object.
  30. *
  31. * @param[in] parentObject Instance of the parent object the field belongs to.
  32. * @param[in] fieldInfo Information about the field. Caller must ensure the type matches the type of the
  33. * provided parent object.
  34. */
  35. static MonoObject* create(MonoObject* parentObject, const SPtr<ManagedSerializableMemberInfo>& fieldInfo);
  36. private:
  37. ScriptSerializableField(MonoObject* instance, const SPtr<ManagedSerializableMemberInfo>& fieldInfo);
  38. SPtr<ManagedSerializableMemberInfo> mFieldInfo;
  39. /************************************************************************/
  40. /* CLR HOOKS */
  41. /************************************************************************/
  42. static MonoObject* internal_createProperty(ScriptSerializableField* nativeInstance);
  43. static MonoObject* internal_getValue(ScriptSerializableField* nativeInstance, MonoObject* instance);
  44. static void internal_setValue(ScriptSerializableField* nativeInstance, MonoObject* instance, MonoObject* value);
  45. static void internal_getStyle(ScriptSerializableField* nativeInstance, SerializableMemberStyle* style);
  46. };
  47. /** @} */
  48. }