Effect.SceneFadeInOutMaterialFloat GetFadeInstance(SceneResInfo res)
    {
        if (!GoablEnabledOcclusCulling)
        {
            return(null);
        }

        Effect.SceneFadeInOutMaterialFloat ef = null;
        if (m_UnActiveOcclusFadeFadeInOutFloatList.Count > 0)
        {
            ef = m_UnActiveOcclusFadeFadeInOutFloatList.Dequeue();
        }
        else
        {
            ef = CreateNewFadeInstance();
        }

        res.occlusFadInstance = ef;
        ef.ClearFinishEvent();
        ef.RegisterFinishEvent(OcclusFadingFinish);
        ef.RegisterFinishEvent(res.OnFadeFinish);
        m_ActiveFadeSceneResTable.Add(ef, res);
        return(ef);
    }
Пример #2
0
    /// <summary>
    /// 插入到batches,batches是以一个QuadTreeNode为单位
    /// </summary>
    /// <param name="parent"></param>
    void BuildBatches(QuadTreeNode parent)
    {
        //如果没存在淡入淡出
        if (!Batches_TreeNodeFadeTable.ContainsKey(parent))
        {
            Effect.SceneFadeInOutMaterialFloat m_FadeFloat = gameObject.AddComponent <Effect.SceneFadeInOutMaterialFloat>();
            m_FadeFloat.PropertyName = SceneResInfo.CutOutKeyWorld;
            m_FadeFloat.RegisterFinishEvent(OnBatchesFadingFinish);
            m_FadeFloat.FadeOutDuartion = FadeTime;
            m_FadeFloat.FadeOutFrom     = 1.0f;
            m_FadeFloat.FadeOutTo       = 0.0f;
            m_FadeFloat.FadeTimer       = m_FadeFloat.FadeOutFrom;
            m_FadeFloat.enabled         = false;


            List <Material>                 FadeInstanceList     = new List <Material>();
            Dictionary <Material, int>      matIndexTable        = new Dictionary <Material, int>();
            Dictionary <Material, Material> matFadeInstanceTable = new Dictionary <Material, Material>();
            foreach (QuadTreeLeaves m_Leaves in parent.m_LeavesList)
            {
                SceneResInfo res = m_Leaves.m_ResInfo;
                //回调,给到每个具体的类里,恢复原本的材质球
                m_FadeFloat.RegisterFinishEvent(res.OnFadeFinish);

                if (res.CheckSupportFading())
                {
                    Material[] shareds     = res.hostRender.sharedMaterials;
                    int        sharedCount = shareds.Length;
                    for (int i = 0; i < sharedCount; i++)
                    {
                        //如果这是一个全新的材质球,就新建一个,然后加入的实例链表里
                        if (!matIndexTable.ContainsKey(shareds[i]))
                        {
                            Material matFadeIn = SceneResInfo.CreateFadeingMaterial(shareds[i]);
                            FadeInstanceList.Add(matFadeIn);
                            matFadeInstanceTable.Add(shareds[i], matFadeIn);
                            matIndexTable.Add(shareds[i], FadeInstanceList.Count - 1);
                            res.BatchesIDs.Add(FadeInstanceList.Count - 1);
                        }
                        else
                        {
                            res.BatchesIDs.Add(matIndexTable[shareds[i]]);
                        }
                    }
                }
            }

            foreach (QuadTreeLeaves m_Leaves in parent.m_LeavesList)
            {
                SceneResInfo res = m_Leaves.m_ResInfo;
                res.Init(matFadeInstanceTable, SceneCamera);
            }

            parent.FadeMaterialList    = FadeInstanceList;
            parent.isDistanceFadingIn  = false;
            parent.isDistanceFadingIn  = false;
            parent.bOpmitizedRendering = true;
            InvBatches_TreeNodeFadeTable.Add(m_FadeFloat, parent);
            Batches_TreeNodeFadeTable.Add(parent, m_FadeFloat);
        }
    }