virtual protected internal Cv_EntityComponent[] ModifyEntity(Cv_Entity entity, XmlNodeList overrides) { var modifiedComponents = new List <Cv_EntityComponent>(); foreach (XmlElement componentNode in overrides) { var componentID = Cv_EntityComponent.GetID(componentNode.Name); var component = entity.GetComponent(componentID); if (component != null) { component.VInitialize(componentNode); component.VOnChanged(); modifiedComponents.Add(component); } else { component = CreateComponent(componentNode); if (component != null) { entity.AddComponent(component); modifiedComponents.Add(component); } } } return(modifiedComponents.ToArray()); }
internal void RemoveChild(Cv_Entity entity) { lock (m_Children) { m_Children.Remove(entity); entity.Parent = Cv_EntityID.INVALID_ENTITY; } }
internal void AddChild(Cv_Entity entity) { lock (m_Children) { m_Children.Add(entity); entity.Parent = ID; } }
public Cv_Entity GetEntity(string entityPath) { var paths = entityPath.Split('/'); Cv_Entity currEntity = this; var consumedSceneName = false; foreach (var subPath in paths) { if (subPath == "..") { var parent = CaravelApp.Instance.Logic.GetEntity(currEntity.Parent); if (parent != null && parent.SceneID == SceneID) { currEntity = parent; } else { return(null); } } else if (subPath == "." || subPath == "") { continue; } else { bool found = false; foreach (var child in currEntity.Children) { if (child.EntityName == subPath) { consumedSceneName = false; currEntity = child; found = true; break; } if (child.SceneRoot && child.SceneName == subPath && !consumedSceneName) { found = true; consumedSceneName = true; break; } } if (!found) { return(null); } } } return(currEntity); }
virtual protected internal Cv_Entity CreateEntity(string entityTypeResource, Cv_EntityID parent, Cv_EntityID serverEntityID, string resourceBundle, Cv_SceneID sceneID, string sceneName) { Cv_XmlResource resource; resource = Cv_ResourceManager.Instance.GetResource <Cv_XmlResource>(entityTypeResource, resourceBundle, CaravelApp.Instance.EditorRunning); XmlElement root = ((Cv_XmlResource.Cv_XmlData)resource.ResourceData).RootNode; if (root == null) { Cv_Debug.Error("Failed to load entity resource file: " + entityTypeResource); return(null); } Cv_EntityID entityId = serverEntityID; if (entityId == Cv_EntityID.INVALID_ENTITY) { lock (m_Mutex) { entityId = GetNextEntityID(); } } var entity = new Cv_Entity(entityId, resourceBundle, sceneName, sceneID); if (!entity.Initialize(entityTypeResource, root, parent)) { Cv_Debug.Error("Failed to initialize entity: " + entityTypeResource); return(null); } foreach (var componentNode in root.ChildNodes) { if (componentNode.GetType() != typeof(XmlElement)) { continue; } var component = CreateComponent((XmlElement)componentNode); if (component != null) { entity.AddComponent(component); } else { return(null); } } return(entity); }
protected internal Cv_Entity CreateEmptyEntity(Cv_EntityID parent, Cv_EntityID serverEntityID, string resourceBundle, Cv_SceneID sceneID, string sceneName) { Cv_EntityID entityId = serverEntityID; if (entityId == Cv_EntityID.INVALID_ENTITY) { lock (m_Mutex) { entityId = GetNextEntityID(); } } var entity = new Cv_Entity(entityId, resourceBundle, sceneName, sceneID); if (!entity.Initialize(null, null, parent)) { Cv_Debug.Error("Failed to initialize empty entity."); return(null); } return(entity); }