/// <summary> /// Gets the first component of type typeName, /// useful in lua scripts. /// </summary> /// <param name="typeName">The searched IComponent type name</param> /// <returns>The first component found, null if none</returns> public object GetComponent(string typeName, bool allowInherited = true) { var type = ComponentRecord.GetAssociatedType(typeName); //If we're looking for a Transform if (type == typeof(Transform)) { return(Transform); } foreach (IComponent component in components) { if (type == component.GetType() || (component.GetType().IsSubclassOf(type) && allowInherited)) { return(component); } } return(null); }
/// <summary> /// Gets the componets of type typename. /// If typename == "Transform", the method returns /// a list with the entity's single transform. /// </summary> /// <returns>The requested components of type typeName, an empty list if there's none.</returns> /// <typeparam name="typeName">The type requested.</typeparam> public List <object> GetComponents(string typeName, bool allowInherited = true) { var type = ComponentRecord.GetAssociatedType(typeName); var elems = new List <object>(); //If we're looking for a Transform if (type == typeof(Transform)) { elems.Add(Transform); return(elems); } foreach (IComponent component in components) { if (type == component.GetType() || (component.GetType().IsSubclassOf(type) && allowInherited)) { elems.Add(component); } } return(elems); }