public void OnMoveEntity(Cv_Event eventData) { Cv_HolderNode holderNode = null; if (m_HolderNodes.TryGetValue(eventData.EntityID, out holderNode)) { SetNodeTransform(holderNode); } }
public bool AddNode(Cv_EntityID entityID, Cv_SceneNode node) { if (node == null) { Cv_Debug.Error("Trying to add nonexistant node to scene."); return(false); } if (entityID != Cv_EntityID.INVALID_ENTITY) { Cv_HolderNode holderNode = null; if (m_HolderNodes.TryGetValue(entityID, out holderNode)) { if (holderNode.Parent.Properties.EntityID != Cv_EntityID.INVALID_ENTITY) //holderNode is not direct child of root { Cv_Debug.Error("Cannot have two nodes belonging to the same entity with different parents."); return(false); } m_EntitiesMap[entityID].Add(node); } if (holderNode == null) { var nodes = new List <Cv_SceneNode>(); nodes.Add(node); m_EntitiesMap.Add(entityID, nodes); holderNode = new Cv_HolderNode(entityID); m_Root.AddChild(holderNode); m_HolderNodes.Add(entityID, holderNode); } SetNodeTransform(holderNode); return(holderNode.AddChild(node)); } return(m_Root.AddChild(node)); }
public bool AddNodeAsChild(Cv_EntityID parentEntity, Cv_EntityID entityID, Cv_SceneNode node) { if (node == null) { Cv_Debug.Error("Trying to add nonexistant node to scene."); return(false); } if (entityID != Cv_EntityID.INVALID_ENTITY) { Cv_HolderNode ancestorNode = null; if (parentEntity == Cv_EntityID.INVALID_ENTITY) { return(AddNode(entityID, node)); } else if (!m_HolderNodes.ContainsKey(parentEntity)) { var currEntity = Caravel.Logic.GetEntity(parentEntity); var entityStack = new Stack <Cv_Entity>(); if (currEntity == null) { return(false); } //Rebuild path to root entityStack.Push(currEntity); while (currEntity.Parent != Cv_EntityID.INVALID_ENTITY) { currEntity = Caravel.Logic.GetEntity(currEntity.Parent); if (m_HolderNodes.ContainsKey(currEntity.ID)) { ancestorNode = m_HolderNodes[currEntity.ID]; break; } entityStack.Push(currEntity); } //Add all the nodes starting with the closest to the root while (entityStack.Count > 0) { currEntity = entityStack.Pop(); var newNodes = new List <Cv_SceneNode>(); m_EntitiesMap.Add(currEntity.ID, newNodes); var hNode = new Cv_HolderNode(currEntity.ID); m_HolderNodes.Add(currEntity.ID, hNode); if (ancestorNode != null) { ancestorNode.AddChild(hNode); } else { m_Root.AddChild(hNode); } ancestorNode = hNode; SetNodeTransform(hNode); } } else { ancestorNode = m_HolderNodes[parentEntity]; } if (ancestorNode == null) { Cv_Debug.Error("Error while trying to find a parent for the new node."); return(false); } Cv_HolderNode holderNode = null; List <Cv_SceneNode> nodes = null; if (m_HolderNodes.TryGetValue(entityID, out holderNode)) { if (holderNode.Parent.Properties.EntityID != parentEntity) { Cv_Debug.Error("Cannot have two nodes belonging to the same entity with different parents."); return(false); } nodes = m_EntitiesMap[entityID]; } else { holderNode = new Cv_HolderNode(entityID); ancestorNode.AddChild(holderNode); SetNodeTransform(holderNode); nodes = new List <Cv_SceneNode>(); m_EntitiesMap.Add(entityID, nodes); m_HolderNodes.Add(entityID, holderNode); } nodes.Add(node); return(holderNode.AddChild(node)); } else { if (parentEntity != Cv_EntityID.INVALID_ENTITY) { Cv_Debug.Error("Trying to attach a node without entity to a node with an entity."); return(false); } return(m_Root.AddChild(node)); } }