SerializableField.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Runtime.CompilerServices;
  5. using System.Text;
  6. namespace BansheeEngine
  7. {
  8. public class SerializableField : ScriptObject
  9. {
  10. private SerializableObject parent;
  11. private SerializableProperty.FieldType type;
  12. private int flags;
  13. private Type internalType;
  14. private string name;
  15. // Only constructed from native code
  16. private SerializableField(SerializableObject parent, string name, int flags, Type internalType)
  17. {
  18. this.parent = parent;
  19. this.name = name;
  20. this.flags = flags;
  21. this.type = SerializableProperty.DetermineFieldType(internalType);
  22. this.internalType = internalType;
  23. }
  24. public SerializableProperty.FieldType Type
  25. {
  26. get { return type; }
  27. }
  28. public bool HasCustomInspector
  29. {
  30. get { return false; } // TODO - Add [UseCustomInspector(typeof(InspecableType))] attribute and parse it
  31. }
  32. public Type CustomInspectorType
  33. {
  34. get { return null; } // TODO - See above. Return type from UseCustomInspector attribute
  35. }
  36. public string Name
  37. {
  38. get { return name; }
  39. }
  40. public bool Inspectable
  41. {
  42. get { return (flags & 0x02) != 0; } // Flags as defined in native code in BsManagedSerializableObjectInfo.h
  43. }
  44. public bool Serializable
  45. {
  46. get { return (flags & 0x01) != 0; } // Flags as defined in native code in BsManagedSerializableObjectInfo.h
  47. }
  48. public SerializableProperty GetProperty()
  49. {
  50. SerializableProperty.Getter getter = () => Internal_GetValue(mCachedPtr, parent.referencedObject);
  51. SerializableProperty.Setter setter = (object value) => Internal_SetValue(mCachedPtr, parent.referencedObject, value);
  52. SerializableProperty newProperty = Internal_CreateProperty(mCachedPtr);
  53. newProperty.Construct(type, internalType, getter, setter);
  54. return newProperty;
  55. }
  56. [MethodImpl(MethodImplOptions.InternalCall)]
  57. private static extern SerializableProperty Internal_CreateProperty(IntPtr nativeInstance);
  58. [MethodImpl(MethodImplOptions.InternalCall)]
  59. private static extern object Internal_GetValue(IntPtr nativeInstance, object instance);
  60. [MethodImpl(MethodImplOptions.InternalCall)]
  61. private static extern void Internal_SetValue(IntPtr nativeInstance, object instance, object value);
  62. }
  63. }