depth reserved keypoint - woodelf-treetop/rcwiki GitHub Wiki

遇到的问题:

最近在做累计充值功能,遇到了关于UI深度预留的问题。累计充值界面需要在每个可领取状态的档位上加特效,我的档位列表里的item是用multigrid动态加载的,特效需要加在每个可领取的item上。这个时候没进行深度排序,会出现特效被UI图片遮挡的问题。这时,就用到了UIOrderObjectList深度排序组件。
由于系统只能拿到最外层对象,UIOrderObjectList深度排序组件只能挂在最外层的Panel上,而我的item是单独做的预制体,因此,这种情况需要使用深度预留。

UIOrderObjectList组件使用:

1、Panel上添加UIOrderObjectList组件
2、添加一项,OrderArray下面,根据需要进行深度排序的类型选择。
类型分别为:
Spine Spine动画
UIPanel
Reserved 预留
Particle 粒子特效
Mixture 混合类型

    if orderType == OrderObjectType.Spine then --Spine动画
        currentSortOrder = currentSortOrder + 1
    elseif orderType == OrderObjectType.UIPanel then --UIPanel组件
        if currentOrderType ~= orderType then --当前不是UIPanel
            currentSortOrder = currentSortOrder + 1
        end
        currentDepth = currentDepth + 1
    elseif orderType == OrderObjectType.Particle then --粒子特效
        currentSortOrder = currentSortOrder + 1
    elseif orderType == OrderObjectType.Reserved then --预留
        currentSortOrder = currentSortOrder + 1
        currentDepth = currentDepth + 1
    else
        return nil
    end

由于,每次后一个的深度是根据之前的值计算的,因而,添加的顺序,按照深度从小到大,自上而下添加。
3、关于预留。类型选择Reserved,下方KeyCode,可以随便填入名称。(代码中会根据KeyCode获取预留深度数据的数组)。

深度预留相关代码:

以累计充值为例:

local function _UpdateOrder(self)
    local sortDataList = ActivityRechargeCtrlPanel.Instance:GetReservedSortDataList("AwardEffect")
    local orderList = self.awardEffect.transform:GetComponent("UIParticleOrder")
    if orderList ~= nil then
        orderList:SetOrderDataList(sortDataList)
    end
end

由于panel继承了基类BaseCtrlPanel,可以调用基类方法GetReservedSortDataList,传入参数为设置的KeyCode,得到预留深度数据的数组。这个是粒子特效在整个panel中的深度。
在特效上添加了UIParticleOrder组件,用于粒子特效的深度排序。

UIParticleOrder的SetOrderDataList部分代码如下:

for (int j = 0; j < particleOrderList.particleItemList.Count; j++) {

    ParticleOrderItem particleOrderItem = particleOrderList.particleItemList[j];
    if (particleOrderItem == null) {
        continue;
    }
    ParticleSystem orderParticleItem = particleOrderItem.orderParticle;
    if (orderParticleItem == null) {
        continue;
     }

    Renderer renderer = orderParticleItem.GetComponent<Renderer>();
    renderer.sortingOrder = sortOrder;

    bool isContainsChildren = particleOrderItem.isContainsChildren;
    if (isContainsChildren) {
     Renderer[] rendererArray = orderParticleItem.GetComponentsInChildren<Renderer>(true);
    for (int k = 0; k < rendererArray.Length; k++) {
        rendererArray[k].sortingOrder = sortOrder;
        }
    }
}

调用其中的SetOrderDataList方法,将深度数据赋值给特效的OrderInLayer。

⚠️ **GitHub.com Fallback** ⚠️