void RegisterComponent(Component component) { const BindingFlags flags = BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly; FieldInfo[] fields = component.GetType().GetFields(flags); // Find the fields that are marked for exposition OssiaEnabledComponent ossia_c = null; foreach (FieldInfo field in fields) { if (Attribute.IsDefined(field, typeof(Ossia.Expose))) { // Get the type of the field ossia_type t; try { t = Ossia.Value.GetOssiaType(field.FieldType); } catch { continue; } // Create a node for the component if (ossia_c == null) { ossia_c = makeComponent(component); } // Create an attribute to bind the field. var attr = (Ossia.Expose)Attribute.GetCustomAttribute(field, typeof(Ossia.Expose)); var oep = new OssiaEnabledField(field, attr.ExposedName, ossia_c, t); ossia_c.fields.Add(oep); controller.Register(oep); } } foreach (PropertyInfo prop in component.GetType().GetProperties()) { if (Attribute.IsDefined(prop, typeof(Ossia.Expose))) { // Get the type of the property; ossia_type t; try { t = Ossia.Value.GetOssiaType(prop.PropertyType); } catch { continue; } // Create a node for the component if (ossia_c == null) { ossia_c = makeComponent(component); } var attr = (Ossia.Expose)Attribute.GetCustomAttribute(prop, typeof(Ossia.Expose)); // Create an attribute to bind the property. var oep = new OssiaEnabledProperty(prop, attr.ExposedName, ossia_c, t); ossia_c.properties.Add(oep); controller.Register(oep); } } }
internal void Unregister(Ossia.OssiaEnabledField p) { Queue.Unregister(p.ossia_parameter); Hash.Remove(p.ossia_parameter.ossia_parameter); }
internal void Register(Ossia.OssiaEnabledField p) { Queue.Register(p.ossia_parameter); Hash.Add(p.ossia_parameter.ossia_parameter, p); }
void RegisterComponent(Component component, Ossia.Node node) { var flags = BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly; var fields = component.GetType().GetFields(flags); var properties = component.GetType().GetProperties(); if (fields.Length == 0 && properties.Length == 0) { return; } // Create a node for the component var ossia_c = new OssiaEnabledComponent(component, node); ossia_components.Add(ossia_c); // Create nodes for all the fields that were exposed foreach (var field in fields) { // Get the type of the field ossia_type t; try { t = Ossia.Value.GetOssiaType(field.FieldType); } catch { continue; } // Create an attribute to bind the field. var oep = new OssiaEnabledField(field, field.Name, ossia_c, t); ossia_c.fields.Add(oep); controller.Register(oep); } // Create nodes for all the fields that were exposed foreach (PropertyInfo prop in properties) { var prop_t = prop.PropertyType; Debug.Log("Prop: " + prop.Name + " => " + prop.PropertyType.ToString()); if (prop_t == typeof(UnityEngine.Transform)) { // TODO } else if (prop_t == typeof(UnityEngine.Component)) { try { var subcomp = (Component)prop.GetValue(component, null); var subnode = node.AddChild(prop.Name); RegisterComponent(subcomp, subnode); } catch { } } else { // Get the type of the field ossia_type t; try { t = Ossia.Value.GetOssiaType(prop_t); } catch { continue; } var oep = new OssiaEnabledProperty(prop, prop.Name, ossia_c, t); ossia_c.properties.Add(oep); controller.Register(oep); } } }