BsScriptSerializableField.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. };
  22. /** Interop class between C++ & CLR for ManagedSerializableFieldInfo. */
  23. class BS_SCR_BE_EXPORT ScriptSerializableField : public ScriptObject<ScriptSerializableField>
  24. {
  25. public:
  26. SCRIPT_OBJ(ENGINE_ASSEMBLY, "BansheeEngine", "SerializableField")
  27. /**
  28. * Creates a new serializable field interop object that references a specific field on a specific object.
  29. *
  30. * @param[in] parentObject Instance of the parent object the field belongs to.
  31. * @param[in] fieldInfo Information about the field. Caller must ensure the type matches the type of the
  32. * provided parent object.
  33. */
  34. static MonoObject* create(MonoObject* parentObject, const SPtr<ManagedSerializableMemberInfo>& fieldInfo);
  35. private:
  36. ScriptSerializableField(MonoObject* instance, const SPtr<ManagedSerializableMemberInfo>& fieldInfo);
  37. SPtr<ManagedSerializableMemberInfo> mFieldInfo;
  38. /************************************************************************/
  39. /* CLR HOOKS */
  40. /************************************************************************/
  41. static MonoObject* internal_createProperty(ScriptSerializableField* nativeInstance);
  42. static MonoObject* internal_getValue(ScriptSerializableField* nativeInstance, MonoObject* instance);
  43. static void internal_setValue(ScriptSerializableField* nativeInstance, MonoObject* instance, MonoObject* value);
  44. static void internal_getStyle(ScriptSerializableField* nativeInstance, SerializableMemberStyle* style);
  45. };
  46. /** @} */
  47. }