zoukankan      html  css  js  c++  java
  • 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();
                }
            }
        }
    }
  • 相关阅读:
    iOS开发多线程篇 03 —线程安全
    【Objective-C】01-Objective-C概述
    insert小细节,大问题
    高速修复汉澳sinox命令解释程序bash shell漏洞
    load-on-startup 解释
    研究下JavaScript中的Rest參数和參数默认值
    UVALive 6530 Football (水
    Android多线程分析之五:使用AsyncTask异步下载图像
    POJ2407_Relatives【欧拉phi函数】【基本】
    cocos2d-x 下使用加密 sqlite3
  • 原文地址:https://www.cnblogs.com/yocichen/p/14213378.html
Copyright © 2011-2022 走看看