コード例 #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);
        }
コード例 #2
0
        public bool IsChildOf(CSceneComponent parentComponent)
        {
            CSceneComponent parent = m_parentComponent;

            while (parent != null)
            {
                if (parent == parentComponent)
                {
                    return(true);
                }

                parent = parent.m_parentComponent;
            }

            return(false);
        }