private static void UpdateComponentData(Component component, YamlNode componentYamlNode, INamingConvention nameConvertor) { foreach (PropertyInfo info in component.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance)) { string key = nameConvertor.Apply(info.Name); if (componentYamlNode.HasValue(key) && info.CanWrite) { info.SetValue(component, componentYamlNode.GetValue(key), null); } } }
public static void SetPropertiesFromYamlNode(object target, YamlNode componentYamlNode, INamingConvention nameConvertor) { foreach (PropertyInfo info in target.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance)) { string key = nameConvertor.Apply(info.Name); if (componentYamlNode.HasValue(key) && info.CanWrite) { try { info.SetValue(target, componentYamlNode.GetValue(key), null); } catch (ArgumentException) { object[] args = new object[] { info.PropertyType, componentYamlNode.GetValue(key).GetType() }; UnityEngine.Debug.LogFormat("Can't convert to {0} from {1}", args); } } } }
public static int Calculate(string path) { path = path.Replace(@"\", "/"); if (path.StartsWith("/", StringComparison.Ordinal)) { path = path.Substring(1); } if (path.EndsWith("/", StringComparison.Ordinal)) { path = path.Substring(0, path.Length - 1); } if (ConfigurationService.HasConfig(path)) { YamlNode config = ConfigurationService.GetConfig(path); if (config.HasValue("id")) { return(int.Parse(config.GetStringValue("id"))); } } return(path.GetHashCode()); }
protected internal override Component GetComponentInstance(ComponentDescription componentDescription, EntityInternal entity) { Component component2; YamlNode yamlNode = entity.TemplateAccessor.Get().YamlNode; ConfigComponentInfo info = componentDescription.GetInfo <ConfigComponentInfo>(); string keyName = info.KeyName; if (info.ConfigOptional && !yamlNode.HasValue(keyName)) { return((Component)Activator.CreateInstance(componentDescription.ComponentType)); } try { component2 = (Component)yamlNode.GetChildNode(keyName).ConvertTo(componentDescription.ComponentType); } catch (Exception exception) { TemplateAccessor accessor; string str2 = !accessor.HasConfigPath() ? yamlNode.ToString() : accessor.ConfigPath; object[] objArray1 = new object[] { "Error deserializing component ", componentDescription.ComponentType, " from configs, entity=", entity, ", key=", keyName, ", pathOrNode=", str2 }; throw new Exception(string.Concat(objArray1), exception); } return(component2); }