• UE4 SetVisibility()和SetHiddenInGame()的比较


    区别与联系:SetVility()实现的更加广泛一些,而SetHiddenInGame()则是只在SceneComponent中有实现,意味着SetHiddenInGame()只能隐藏SceneComponent。SetVisibility()可以隐藏包括SceneComponent在内的很多东西(如UI组件)。一般来说能在场景中显示(看的见的)物体,都有SceneComponent,两种方法都可以达到目的,但是如果是一些SWeiget,SPanel,UWeiget等就只能通过SetVisibility()来做。
    另外,在SceneComponent中两种方法的实现几乎是相同的。
    void USceneComponent::SetVisibility(const bool bNewVisibility, const USceneComponent::EVisibilityPropagation PropagateToChildren)
    {
        bool bRecurseChildren = (PropagateToChildren == EVisibilityPropagation::Propagate);
        if ( bNewVisibility != GetVisibleFlag() )
        {
            bRecurseChildren = bRecurseChildren || (PropagateToChildren == EVisibilityPropagation::DirtyOnly);
            SetVisibleFlag(bNewVisibility);
            OnVisibilityChanged();
        }
    
        const TArray<USceneComponent*>& AttachedChildren = GetAttachChildren();
        if (bRecurseChildren && AttachedChildren.Num() > 0)
        {
            // fully traverse down the attachment tree
            // we do it entirely inline here instead of recursing in case a primitivecomponent is a child of a non-primitivecomponent
            TInlineComponentArray<USceneComponent*, NumInlinedActorComponents> ComponentStack;
    
            // prime the pump
            ComponentStack.Append(AttachedChildren);
    
            while (ComponentStack.Num() > 0)
            {
                USceneComponent* const CurrentComp = ComponentStack.Pop(/*bAllowShrinking=*/ false);
                if (CurrentComp)
                {
                    ComponentStack.Append(CurrentComp->GetAttachChildren());
    
                    if (PropagateToChildren == EVisibilityPropagation::Propagate)
                    {
                        CurrentComp->SetVisibility(bNewVisibility, EVisibilityPropagation::NoPropagation);
                    }
    
                    // Render state must be dirtied if any parent component's visibility has changed. Since we can't easily track whether 
                    // any parent in the hierarchy was dirtied, we have to mark dirty always.
                    CurrentComp->MarkRenderStateDirty();
                }
            }
        }
    }
    void USceneComponent::SetHiddenInGame(const bool bNewHiddenGame, const USceneComponent::EVisibilityPropagation PropagateToChildren)
    {
        bool bRecurseChildren = (PropagateToChildren == EVisibilityPropagation::Propagate);
        if ( bNewHiddenGame != bHiddenInGame )
        {
            bRecurseChildren = bRecurseChildren || (PropagateToChildren == EVisibilityPropagation::DirtyOnly);
            bHiddenInGame = bNewHiddenGame;
            OnHiddenInGameChanged();
        }
    
        const TArray<USceneComponent*>& AttachedChildren = GetAttachChildren();
        if (bRecurseChildren && AttachedChildren.Num() > 0)
        {
            // fully traverse down the attachment tree
            // we do it entirely inline here instead of recursing in case a primitivecomponent is a child of a non-primitivecomponent
            TInlineComponentArray<USceneComponent*, NumInlinedActorComponents> ComponentStack;
    
            // prime the pump
            ComponentStack.Append(AttachedChildren);
    
            while (ComponentStack.Num() > 0)
            {
                USceneComponent* const CurrentComp = ComponentStack.Pop(/*bAllowShrinking=*/ false);
                if (CurrentComp)
                {
                    ComponentStack.Append(CurrentComp->GetAttachChildren());
    
                    if (PropagateToChildren == EVisibilityPropagation::Propagate)
                    {
                        CurrentComp->SetHiddenInGame(bNewHiddenGame, EVisibilityPropagation::NoPropagation);
                    }
    
                    // Render state must be dirtied if any parent component's visibility has changed. Since we can't easily track whether 
                    // any parent in the hierarchy was dirtied, we have to mark dirty always.
                    CurrentComp->MarkRenderStateDirty();
                }
            }
        }
    }
  • 相关阅读:
    [ python ] 函数的参数
    [ python ] 文件读写操作
    [ python ] 集合的使用
    [ python ] 购物系统
    [ python ] 字符编码
    [ python ] 字典的使用
    [ python ] 列表和元组
    [ python ] 字符串的操作及作业题
    [ python ] 格式化输出、字符集、and/or/not 逻辑判断
    [ python ] 变量及基础的数据类型
  • 原文地址:https://www.cnblogs.com/yocichen/p/14213378.html
Copyright © 2020-2023  润新知