|
@@ -1,21 +1,44 @@
|
|
|
using System;
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
using System.Collections.Generic;
|
|
|
using System.Linq;
|
|
using System.Linq;
|
|
|
|
|
+using System.Runtime.CompilerServices;
|
|
|
using System.Text;
|
|
using System.Text;
|
|
|
|
|
|
|
|
namespace BansheeEngine
|
|
namespace BansheeEngine
|
|
|
{
|
|
{
|
|
|
- public sealed class SerializableProperty
|
|
|
|
|
|
|
+ public sealed class SerializableProperty : ScriptObject
|
|
|
{
|
|
{
|
|
|
|
|
+ public enum FieldType
|
|
|
|
|
+ {
|
|
|
|
|
+ Int,
|
|
|
|
|
+ Float,
|
|
|
|
|
+ Bool,
|
|
|
|
|
+ String,
|
|
|
|
|
+ Color,
|
|
|
|
|
+ Vector2,
|
|
|
|
|
+ Vector3,
|
|
|
|
|
+ Vector4,
|
|
|
|
|
+ GameObjectRef,
|
|
|
|
|
+ ResourceRef,
|
|
|
|
|
+ Object,
|
|
|
|
|
+ Array,
|
|
|
|
|
+ List,
|
|
|
|
|
+ Dictionary
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
internal delegate object Getter();
|
|
internal delegate object Getter();
|
|
|
internal delegate void Setter(object value);
|
|
internal delegate void Setter(object value);
|
|
|
|
|
|
|
|
- private SerializableField.FieldType type;
|
|
|
|
|
|
|
+ private FieldType type;
|
|
|
private Type internalType;
|
|
private Type internalType;
|
|
|
private Getter getter;
|
|
private Getter getter;
|
|
|
private Setter setter;
|
|
private Setter setter;
|
|
|
|
|
|
|
|
- internal SerializableProperty(SerializableField.FieldType type, Type internalType, Getter getter, Setter setter)
|
|
|
|
|
|
|
+ // Constructed from native code
|
|
|
|
|
+ private SerializableProperty()
|
|
|
|
|
+ { }
|
|
|
|
|
+
|
|
|
|
|
+ internal void Construct(FieldType type, Type internalType, Getter getter, Setter setter)
|
|
|
{
|
|
{
|
|
|
this.type = type;
|
|
this.type = type;
|
|
|
this.internalType = internalType;
|
|
this.internalType = internalType;
|
|
@@ -23,7 +46,7 @@ namespace BansheeEngine
|
|
|
this.setter = setter;
|
|
this.setter = setter;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public SerializableField.FieldType Type
|
|
|
|
|
|
|
+ public FieldType Type
|
|
|
{
|
|
{
|
|
|
get { return type; }
|
|
get { return type; }
|
|
|
}
|
|
}
|
|
@@ -46,18 +69,88 @@ namespace BansheeEngine
|
|
|
|
|
|
|
|
public SerializableObject GetObject()
|
|
public SerializableObject GetObject()
|
|
|
{
|
|
{
|
|
|
- if (type != SerializableField.FieldType.Object)
|
|
|
|
|
|
|
+ if (type != FieldType.Object)
|
|
|
throw new Exception("Attempting to retrieve object information from a field that doesn't contain an object.");
|
|
throw new Exception("Attempting to retrieve object information from a field that doesn't contain an object.");
|
|
|
|
|
|
|
|
- return new SerializableObject(GetValue<object>());
|
|
|
|
|
|
|
+ return Internal_CreateObject(mCachedPtr, GetValue<object>());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public SerializableArray GetArray()
|
|
public SerializableArray GetArray()
|
|
|
{
|
|
{
|
|
|
- if (type != SerializableField.FieldType.Array)
|
|
|
|
|
|
|
+ if (type != FieldType.Array)
|
|
|
throw new Exception("Attempting to retrieve array information from a field that doesn't contain an array.");
|
|
throw new Exception("Attempting to retrieve array information from a field that doesn't contain an array.");
|
|
|
|
|
|
|
|
- return new SerializableArray(GetValue<Array>());
|
|
|
|
|
|
|
+ return Internal_CreateArray(mCachedPtr, GetValue<Array>());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ [MethodImpl(MethodImplOptions.InternalCall)]
|
|
|
|
|
+ private static extern SerializableObject Internal_CreateObject(IntPtr nativeInstance, object instance);
|
|
|
|
|
+
|
|
|
|
|
+ [MethodImpl(MethodImplOptions.InternalCall)]
|
|
|
|
|
+ private static extern SerializableArray Internal_CreateArray(IntPtr nativeInstance, Array instance);
|
|
|
|
|
+
|
|
|
|
|
+ public static FieldType DetermineFieldType(Type internalType)
|
|
|
|
|
+ {
|
|
|
|
|
+ if (!internalType.IsArray)
|
|
|
|
|
+ {
|
|
|
|
|
+ if (internalType == typeof (Byte))
|
|
|
|
|
+ return FieldType.Int;
|
|
|
|
|
+ else if (internalType == typeof (SByte))
|
|
|
|
|
+ return FieldType.Int;
|
|
|
|
|
+ else if (internalType == typeof (Int16))
|
|
|
|
|
+ return FieldType.Int;
|
|
|
|
|
+ else if (internalType == typeof (UInt16))
|
|
|
|
|
+ return FieldType.Int;
|
|
|
|
|
+ else if (internalType == typeof (Int32))
|
|
|
|
|
+ return FieldType.Int;
|
|
|
|
|
+ else if (internalType == typeof (UInt32))
|
|
|
|
|
+ return FieldType.Int;
|
|
|
|
|
+ else if (internalType == typeof (Int64))
|
|
|
|
|
+ return FieldType.Int;
|
|
|
|
|
+ else if (internalType == typeof (UInt64))
|
|
|
|
|
+ return FieldType.Int;
|
|
|
|
|
+ else if (internalType == typeof (bool))
|
|
|
|
|
+ return FieldType.Bool;
|
|
|
|
|
+ else if (internalType == typeof (float))
|
|
|
|
|
+ return FieldType.Float;
|
|
|
|
|
+ else if (internalType == typeof (double))
|
|
|
|
|
+ return FieldType.Float;
|
|
|
|
|
+ else if (internalType == typeof (string))
|
|
|
|
|
+ return FieldType.String;
|
|
|
|
|
+ else if (internalType == typeof (Vector2))
|
|
|
|
|
+ return FieldType.Vector2;
|
|
|
|
|
+ else if (internalType == typeof (Vector3))
|
|
|
|
|
+ return FieldType.Vector3;
|
|
|
|
|
+ else if (internalType == typeof (Vector4))
|
|
|
|
|
+ return FieldType.Vector4;
|
|
|
|
|
+ else if (internalType == typeof (Color))
|
|
|
|
|
+ return FieldType.Color;
|
|
|
|
|
+ else if (internalType.IsSubclassOf(typeof (GameObject)))
|
|
|
|
|
+ return FieldType.GameObjectRef;
|
|
|
|
|
+ else if (internalType.IsSubclassOf(typeof (Resource)))
|
|
|
|
|
+ return FieldType.ResourceRef;
|
|
|
|
|
+ else if (internalType.IsGenericType)
|
|
|
|
|
+ {
|
|
|
|
|
+ Type genericType = internalType.GetGenericTypeDefinition();
|
|
|
|
|
+
|
|
|
|
|
+ if (genericType == typeof (List<>))
|
|
|
|
|
+ {
|
|
|
|
|
+ return FieldType.List;
|
|
|
|
|
+ }
|
|
|
|
|
+ else if (genericType == typeof (Dictionary<,>))
|
|
|
|
|
+ {
|
|
|
|
|
+ return FieldType.Dictionary;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // Shouldn't happen because native code should only supply us with supported types
|
|
|
|
|
+ throw new Exception("Cannot determine field type. Found an unsupported generic type.");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // Otherwise the type must be an object, unless some error occurred
|
|
|
|
|
+ return FieldType.Object;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return FieldType.Array;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|