public Node CreateNode(EntityInternal entity) { Node node2; Node nodeInstance = Cache.GetNodeInstance(this.nodeClass); nodeInstance.Entity = entity; try { Collections.Enumerator <Type> enumerator = Collections.GetEnumerator <Type>(this.nodeDescription.Components); while (true) { if (!enumerator.MoveNext()) { node2 = nodeInstance; break; } Type current = enumerator.Current; this.SetComponent(nodeInstance, current, entity.GetComponent(current)); } } catch (Exception exception) { throw new ConvertEntityToNodeException(this.nodeClass, entity, exception); } return(node2); }
public EntityInternal Clone(string name, EntityInternal entity, EntityBuilder entityBuilder) { entityBuilder.SetName(name); if (entity.TemplateAccessor.IsPresent()) { TemplateAccessor accessor = entity.TemplateAccessor.Get(); if (accessor != null) { TemplateDescription templateDescription = accessor.TemplateDescription; entityBuilder.SetTemplate(templateDescription.TemplateClass); if (accessor.HasConfigPath()) { entityBuilder.SetConfig(accessor.ConfigPath); } else { YamlNode yamlNode = accessor.YamlNode; if (yamlNode != null) { entityBuilder.SetTemplateYamlNode(yamlNode); } } } } EntityInternal internal2 = entityBuilder.Build(true); foreach (Type type in entity.ComponentClasses) { if (!ReferenceEquals(type, this.newEntityComponentType)) { internal2.AddComponent(entity.GetComponent(type)); } } return(internal2); }
public void DecodeToInstance(ProtocolBuffer protocolBuffer, object instance) { ComponentChangeCommand command = (ComponentChangeCommand)instance; EntityInternal internal2 = (EntityInternal)this.entityCodec.Decode(protocolBuffer); long uid = (long)this.longCodec.Decode(protocolBuffer); Type typeByUid = this.protocol.GetTypeByUid(uid); Component component = null; component = !internal2.HasComponent(typeByUid) ? ((Component)Activator.CreateInstance(typeByUid)) : internal2.GetComponent(typeByUid); this.protocol.GetCodec(typeByUid).DecodeToInstance(protocolBuffer, component); command.Entity = internal2; command.Component = component; }