Example #1
0
        void AddCSComponent(CSComponent csc)
        {
            CSComponentInfo info;

            if (!CSComponentCore.csinfoLookup.TryGetValue(csc.GetType(), out info))
            {
                Log.Error("Scene.HandleComponentAdded - unable to get CSComponentInfo");
                return;
            }

            List <CSComponent> cslist;

            if (!cscomponents.TryGetValue(info, out cslist))
            {
                cslist = cscomponents[info] = new List <CSComponent>();
            }

            if (cslist.Contains(csc))
            {
                throw new InvalidOperationException("Scene.HandleComponentAdded - CSComponent already added to component list");
            }

            cslist.Add(csc);

            if (!csc.started)
            {
                if (cscomponentStart.Contains(csc))
                {
                    throw new InvalidOperationException("Scene.HandleComponentAdded CSComponent already added to start list");
                }


                cscomponentStart.Add(csc);
            }
        }
Example #2
0
 public static void RegisterInstance(CSComponent component)
 {
     instance.csinfoLookup[component.GetType()].RegisterInstance(component);
 }
Example #3
0
        void AddCSComponent(CSComponent csc)
        {
            CSComponentInfo info;

            if (!CSComponentCore.csinfoLookup.TryGetValue(csc.GetType(), out info))
            {
                Log.Error("Scene.HandleComponentAdded - unable to get CSComponentInfo");
                return;
            }

            List<CSComponent> cslist;

            if (!cscomponents.TryGetValue(info, out cslist))
            {
                cslist = cscomponents[info] = new List<CSComponent>();
            }

            if (cslist.Contains(csc))
            {
                throw new InvalidOperationException("Scene.HandleComponentAdded - CSComponent already added to component list");
            }

            cslist.Add(csc);

            if (cscomponentStart.Contains(csc))
            {
                throw new InvalidOperationException("Scene.HandleComponentAdded CSComponent already added to start list");
            }

            if (csc.started)
            {
                throw new InvalidOperationException("Scene.HandleComponentAdded CSComponent already started");
            }

            cscomponentStart.Add(csc);

        }
Example #4
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;
                    }
                }
            }
        }
 public static void RegisterInstance(CSComponent component)
 {
     instance.csinfoLookup[component.GetType()].RegisterInstance(component);
 }