Exemple #1
0
        public bool AttachToComponent(CSceneComponent parentComponent, bool bTransferOwnership = false)
        {
            if (parentComponent == this)
            {
                LogUtility.Log("[Components] Tried to attach to self, aborting");
                return(false);
            }

            if (parentComponent == null)
            {
                Detach();
                return(false);
            }

            if (parentComponent == m_parentComponent)
            {
                LogUtility.Log("[Components] Tried attaching component to the same parent again, aborting");
                return(false);
            }

            if (parentComponent.IsChildOf(this))
            {
                LogUtility.Log("[Components] Tried to attach to a component which is already a child, this would create a loop, aborting");
                return(false);
            }

            Detach();

            CSceneComponent oldParent = m_parentComponent;

            m_parentComponent  = parentComponent;
            m_transform.Parent = m_parentComponent.m_transform;
            m_parentComponent.m_children.Add(this);


            // todo henning handle different transform modes (Keep WorldTransform, Snap To etc.)

            if (m_parentComponent.Owner != Owner)
            {
                if (bTransferOwnership)
                {
                    ChangeOwner(m_parentComponent.Owner);
                }
                else
                {
                    CEntity currentParent = Owner.Parent;
                    if (currentParent != null)
                    {
                        currentParent.UnregisterChildEntity(Owner);
                    }

                    parentComponent.Owner.RegisterChildEntity(Owner);
                    World.TriggerHierarchyChanged(this, oldParent, parentComponent);
                }
            }

            return(true);
        }
Exemple #2
0
        public virtual void Shutdown()
        {
            foreach (CEntityComponent component in m_components)
            {
                component.Shutdown();
            }
            m_bIsAlive       = false;
            IsPhysicsEnabled = false;

            CEntity parent = Parent;

            if (parent != null)
            {
                parent.UnregisterChildEntity(this);
            }

            Input.UnregisterListener(OnInputEvent);
            m_updateScope?.Disconnect();
        }