Exemple #1
0
 public static void RegisterCSComponent(CSComponent component)
 {
     // register (holds a reference)
     liveComponents [component.RefID] = component;
 }
Exemple #2
0
        // This will need to be optimized
        public static void CSComponentApplyFields(IntPtr componentPtr, IntPtr fieldMapPtr)
        {
            NETVariantMap fieldMap  = NativeCore.WrapNative <NETVariantMap>(fieldMapPtr);;
            CSComponent   component = NativeCore.WrapNative <CSComponent>(componentPtr);;

            if (fieldMap == null || component == null)
            {
                return;
            }

            FieldInfo[] fields = componentClassFields[component.GetType()];

            foreach (var field in fields)
            {
                if (fieldMap.Contains(field.Name))
                {
                    //Console.WriteLine("Applying: {0} {1}", field.Name, field.FieldType.Name);

                    var fieldType = field.FieldType;

                    if (fieldType.IsEnum)
                    {
                        field.SetValue(component, fieldMap.GetInt(field.Name));
                        continue;
                    }

                    switch (Type.GetTypeCode(fieldType))
                    {
                    case TypeCode.Boolean:
                        field.SetValue(component, fieldMap.GetBool(field.Name));
                        break;

                    case TypeCode.Int32:
                        field.SetValue(component, fieldMap.GetInt(field.Name));
                        break;

                    case TypeCode.Single:
                        field.SetValue(component, fieldMap.GetFloat(field.Name));
                        break;

                    case TypeCode.String:
                        field.SetValue(component, fieldMap.GetString(field.Name));
                        break;

                    default:

                        if (fieldType == typeof(Vector3))
                        {
                            field.SetValue(component, fieldMap.GetVector3(field.Name));
                        }
                        else if (fieldType == typeof(Quaternion))
                        {
                            field.SetValue(component, fieldMap.GetQuaternion(field.Name));
                        }
                        else if (fieldType.IsSubclassOf(typeof(Resource)))
                        {
                            field.SetValue(component, fieldMap.GetResourceFromRef(field.Name));
                        }
                        else if (fieldType.IsSubclassOf(typeof(RefCounted)))
                        {
                            field.SetValue(component, fieldMap.GetPtr(field.Name));
                        }

                        break;
                    }
                }
            }
        }