/// <summary> /// Adds the child. /// </summary> /// <param name="child">The child.</param> /// <param name="preserveWorldPos">if set to <c>true</c> [preserve absolute position].</param> public void AddChild(IMyEntity child, bool preserveWorldPos = false, bool insertIntoSceneIfNeeded = true) { //MyEntities.Remove(child); // if it's already in the world, remove it MyHierarchyComponentBase childHierarchy = child.Components.Get <MyHierarchyComponentBase>(); childHierarchy.Parent = this; if (preserveWorldPos) { var tmpWorldMatrix = child.WorldMatrix; this.Children.Add(childHierarchy); child.PositionComp.SetWorldMatrix(tmpWorldMatrix, Entity, true); } else { this.Children.Add(childHierarchy); MyPositionComponentBase positionComponent = Container.Get <MyPositionComponentBase>(); MyPositionComponentBase childPositionComponent = child.Components.Get <MyPositionComponentBase>(); var m = positionComponent.WorldMatrix; childPositionComponent.UpdateWorldMatrix(ref m); } if (Container.Entity.InScene && !child.InScene && insertIntoSceneIfNeeded) { child.OnAddedToScene(Container.Entity); } }
void Container_ComponentAdded(Type arg1, MyEntityComponentBase arg2) { if (typeof(MyHierarchyComponentBase).IsAssignableFrom(arg1)) { m_parent = arg2 as MyHierarchyComponentBase; } }
/// <summary> /// Adds the child. /// </summary> /// <param name="child">The child.</param> /// <param name="preserveWorldPos">if set to <c>true</c> [preserve absolute position].</param> public void RemoveChild(IMyEntity child, bool preserveWorldPos = false) { MyHierarchyComponentBase childHierarchy = child.Components.Get <MyHierarchyComponentBase>(); if (preserveWorldPos) { var tmpWorldMatrix = child.WorldMatrix; this.Children.Remove(childHierarchy); child.WorldMatrix = tmpWorldMatrix; } else { this.Children.Remove(childHierarchy); } childHierarchy.Parent = null; if (child.InScene) { child.OnRemovedFromScene(this); } if (OnChildRemoved != null) { OnChildRemoved(child); } }
void Container_ComponentRemoved(Type arg1, MyEntityComponentBase arg2) { if (arg2 == m_parent) { m_parent = null; } }
void Container_ComponentAdded(Type arg1, MyEntityComponentBase arg2) { if (typeof(MyHierarchyComponentBase).IsAssignableFrom(arg1)) { m_parent = arg2 as MyHierarchyComponentBase; } }
public override void OnAddedToContainer() { base.OnAddedToContainer(); m_syncObject = Container.Get<MySyncComponentBase>(); m_physics = Container.Get<MyPhysicsComponentBase>(); m_hierarchy = Container.Get<MyHierarchyComponentBase>(); Container.ComponentAdded += container_ComponentAdded; Container.ComponentRemoved += container_ComponentRemoved; }
void container_ComponentAdded(Type type, MyEntityComponentBase comp) { if (type == typeof(MySyncComponentBase)) m_syncObject = comp as MySyncComponentBase; else if (type == typeof(MyPhysicsComponentBase)) m_physics = comp as MyPhysicsComponentBase; else if (type == typeof(MyHierarchyComponentBase)) m_hierarchy = comp as MyHierarchyComponentBase; }
void container_ComponentRemoved(Type type, MyEntityComponentBase comp) { if (type == typeof(MySyncComponentBase)) m_syncObject = null; else if (type == typeof(MyPhysicsComponentBase)) m_physics = null; else if (type == typeof(MyHierarchyComponentBase)) m_hierarchy = null; }
public override void OnAddedToContainer() { base.OnAddedToContainer(); m_syncObject = Container.Get <MySyncComponentBase>(); m_physics = Container.Get <MyPhysicsComponentBase>(); m_hierarchy = Container.Get <MyHierarchyComponentBase>(); Container.ComponentAdded += container_ComponentAdded; Container.ComponentRemoved += container_ComponentRemoved; }
/// <summary> /// Return top most parent of this entity /// </summary> /// <returns></returns> public MyHierarchyComponentBase GetTopMostParent(Type type = null) { MyHierarchyComponentBase parent = this; while (parent.Parent != null && (type == null || !parent.Container.Contains(type))) { parent = parent.Parent; } return(parent); }
public override void OnBeforeRemovedFromContainer() { if (m_parentContainer != null) { m_parentContainer.ComponentAdded -= Container_ComponentAdded; m_parentContainer.ComponentRemoved -= Container_ComponentRemoved; m_parentContainer = null; } m_parent = null; base.OnBeforeRemovedFromContainer(); }
public void AddChildWithMatrix(IMyEntity child, ref Matrix childLocalMatrix, bool insertIntoSceneIfNeeded = true) { MyHierarchyComponentBase childHierarchy = child.Components.Get <MyHierarchyComponentBase>(); childHierarchy.Parent = this; Children.Add(childHierarchy); child.WorldMatrix = (MatrixD)childLocalMatrix * Container.Get <MyPositionComponentBase>().WorldMatrix; if (Container.Entity.InScene && !child.InScene && insertIntoSceneIfNeeded) { child.OnAddedToScene(this); } }
public void UpdateRenderObject(bool visible) { if (!Container.Entity.InScene && visible) { return; } MyHierarchyComponentBase hierarchyComponent = Container.Get <MyHierarchyComponentBase>(); if (visible) { if (hierarchyComponent != null) { if (Visible && (hierarchyComponent.Parent == null || hierarchyComponent.Parent.Container.Entity.Visible)) { if (CanBeAddedToRender()) { if (!IsRenderObjectAssigned(0)) { AddRenderObjects(); } else { UpdateRenderObjectVisibility(visible); } } } } } else { if (m_renderObjectIDs[0] != VRageRender.MyRenderProxy.RENDER_ID_UNASSIGNED) { UpdateRenderObjectVisibility(visible); } RemoveRenderObjects(); } if (hierarchyComponent != null) { foreach (var child in hierarchyComponent.Children) { MyRenderComponentBase renderComponent = null; if (child.Container.TryGet(out renderComponent)) { renderComponent.UpdateRenderObject(visible); } } } }
void container_ComponentRemoved(Type type, MyEntityComponentBase comp) { if (type == typeof(MySyncComponentBase)) { m_syncObject = null; } else if (type == typeof(MyPhysicsComponentBase)) { m_physics = null; } else if (type == typeof(MyHierarchyComponentBase)) { m_hierarchy = null; } }
void container_ComponentAdded(Type type, MyEntityComponentBase comp) { if (type == typeof(MySyncComponentBase)) { m_syncObject = comp as MySyncComponentBase; } else if (type == typeof(MyPhysicsComponentBase)) { m_physics = comp as MyPhysicsComponentBase; } else if (type == typeof(MyHierarchyComponentBase)) { m_hierarchy = comp as MyHierarchyComponentBase; } }
void Container_ComponentRemoved(Type arg1, MyEntityComponentBase arg2) { if (arg2 == m_parent) m_parent = null; }
public override void OnBeforeRemovedFromContainer() { if (m_parentContainer != null) { m_parentContainer.ComponentAdded -= Container_ComponentAdded; m_parentContainer.ComponentRemoved -= Container_ComponentRemoved; m_parentContainer = null; } m_parent = null; base.OnBeforeRemovedFromContainer(); }