Exemple #1
0
    /// <summary>
    /// 过度完成
    /// </summary>
    public void OnFadeFinish(Effect.SceneFadeInOutMaterialFloat FadeInOutMaterialFloat)
    {
        if (!CheckSupportFading())
        {
            return;
        }

        hostRender.materials = OrginalMaterList;

        if (bOptimitzedRendering)
        {
            QuadTreeNodeAcitiveVisible = false;
            UpdateVisible();
            InvokeFadeOutFinishEvent();
        }
        else
        {
            QuadTreeNodeAcitiveVisible = true;
            UpdateVisible();
            //激活一下,因为打包之后有的情况下,不激活物体有时候会看不见,哪怕原本就是激活的
            hostRender.gameObject.SetActive(false);
            hostRender.gameObject.SetActive(true);

            InvokeFadeInFinishEvent();
        }
    }
    void ClearBatchesRes()
    {
        foreach (Effect.SceneFadeInOutMaterialFloat lis in Batches_TreeNodeFadeTable.Values)
        {
            lis.InvokeFinishEvent();
            lis.ClearMaterialInstance();
            lis.ClearFinishEvent();
            Effect.SceneFadeInOutMaterialFloat temp = lis;
            ResNode.DestroyRes(ref temp);
        }
        foreach (QuadTreeNode m_Parent in Batches_AllResParentNode)
        {
            foreach (Material mat in m_Parent.FadeMaterialList)
            {
                DestroyImmediate(mat);
            }
            m_Parent.FadeMaterialList.Clear();
            m_Parent.FadeMaterialList = null;
        }
        InvBatches_TreeNodeFadeTable.Clear();
        Batches_TreeNodeFadeTable.Clear();

        Batches_AllGrassResParentNode.Clear();
        Batches_AllResParentNode.Clear();
    }
    Effect.SceneFadeInOutMaterialFloat CreateNewFadeInstance()
    {
        if (!GoablEnabledOcclusCulling)
        {
            return(null);
        }

        Effect.SceneFadeInOutMaterialFloat ef = gameObject.AddComponent <Effect.SceneFadeInOutMaterialFloat>();
        ef.enabled      = false;
        ef.PropertyName = SceneResInfo.CutOutKeyWorld;
        return(ef);
    }
 /// <summary>
 /// 拷贝编辑器变量
 /// </summary>
 /// <param name="FromInstance">从哪一个拷贝</param>
 public void CopyInspectorParamsTo(SceneFadeInOutMaterialFloat FromInstance)
 {
     PropertyName    = FromInstance.PropertyName;
     Loop            = FromInstance.Loop;
     FadeInDealy     = FromInstance.FadeInDealy;
     FadeInDuartion  = FromInstance.FadeInDuartion;
     FadeInFrom      = FromInstance.FadeInFrom;
     FadeInTo        = FromInstance.FadeInTo;
     FadeOutDelay    = FromInstance.FadeOutDelay;
     FadeOutDuartion = FromInstance.FadeOutDuartion;
     FadeOutFrom     = FromInstance.FadeOutFrom;
     FadeOutTo       = FromInstance.FadeOutTo;
 }
    void BuildOcclusCacheData()
    {
        if (!GoablEnabledOcclusCulling)
        {
            return;
        }

        for (int i = 0; i < 100; i++)
        {
            Effect.SceneFadeInOutMaterialFloat ke = CreateNewFadeInstance();
            m_UnActiveOcclusFadeFadeInOutFloatList.Enqueue(ke);
        }
    }
    void OptimitzedBaatchesRendering(QuadTreeNode parent)
    {
        if (!parent.bOpmitizedRendering)
        {
            Effect.SceneFadeInOutMaterialFloat m_FadeFloat = null;

            parent.bOpmitizedRendering = true;

            int length = parent.m_LeavesList.Count;
            for (int j = 0; j < length; j++)
            {
                QuadTreeLeaves leaf = parent.m_LeavesList[j];
                leaf.m_ResInfo.OptimitzedMemory();
                leaf.m_ResInfo.OptimitzedRendering(parent.FadeMaterialList);
            }



            if (Batches_TreeNodeFadeTable.TryGetValue(parent, out m_FadeFloat))
            {
                m_FadeFloat.SetMaterialInstance(parent.FadeMaterialList);
                m_FadeFloat.enabled = true;

                parent.isDistanceFadingOut = true;

                if (!parent.isDistanceFadingIn)
                {
                    m_FadeFloat.FadeOutFrom     = 0.0f;
                    m_FadeFloat.FadeOutTo       = 1.0f;
                    m_FadeFloat.FadeOutDuartion = FadeTime;
                    m_FadeFloat.Play();
                }
                else
                {
                    m_FadeFloat.FadeOutDuartion = m_FadeFloat.FadeTimer;
                    m_FadeFloat.FadeOutFrom     = m_FadeFloat.currentFloat;
                    m_FadeFloat.FadeOutTo       = 1;
                    m_FadeFloat.FadeTimer       = 0;
                    m_FadeFloat.Update();
                    m_FadeFloat.ReStartFadeOutFinish_Constant();
                }

                parent.isDistanceFadingIn = false;
            }
        }
    }
    void OcclusFadingFinish(Effect.SceneFadeInOutMaterialFloat instance)
    {
        if (!GoablEnabledOcclusCulling)
        {
            return;
        }

        CollectFadingMaterial(m_ActiveFadeSceneResTable[instance]);
        m_ActiveFadeSceneResTable[instance].occlusFadingOut   = false;
        m_ActiveFadeSceneResTable[instance].occlusFadingIn    = false;
        m_ActiveFadeSceneResTable[instance].occlusFadInstance = null;
        m_ActiveFadeSceneResTable.Remove(instance);
        m_UnActiveOcclusFadeFadeInOutFloatList.Enqueue(instance);
        instance.enabled = false;
        instance.ClearMaterialInstance();
        instance.ClearFinishEvent();
    }
    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);
    }
    /// <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);
        }
    }
 void OnBatchesFadingFinish(Effect.SceneFadeInOutMaterialFloat FadeInOutMaterialFloat)
 {
     FadeInOutMaterialFloat.enabled = false;
     InvBatches_TreeNodeFadeTable[FadeInOutMaterialFloat].isDistanceFadingIn  = false;
     InvBatches_TreeNodeFadeTable[FadeInOutMaterialFloat].isDistanceFadingOut = false;
 }
    void FadeInFromOcclusCulling(SceneResInfo res, bool testLog = false)
    {
        if (!GoablEnabledOcclusCulling)
        {
            return;
        }

        if (!res || res.hostTreeNode == null)
        {
            return;
        }
        QuadTreeNode parent = res.hostTreeNode;

        if (!parent.bOpmitizedRendering)
        {
            if (!res.CheckSupportFading())
            {
                return;
            }

            Material[] matList = GetFadingMaterial(res);
            if (null == matList)
            {
                return;
            }
            res.UpdateOcclusFadeIn(matList);
            if (!parent.isDistanceFadingIn)
            {
                if (!res.occlusFadingOut)
                {
                    if (!res.occlusFadingIn)
                    {
                        res.occlusFadingIn  = true;
                        res.occlusFadingOut = false;

                        Effect.SceneFadeInOutMaterialFloat occlusFade = GetFadeInstance(res);
                        occlusFade.SetMaterialInstance(matList);
                        occlusFade.FadeOutDuartion = FadeTime;
                        occlusFade.FadeOutFrom     = 1;
                        occlusFade.FadeOutTo       = 0;
                        occlusFade.enabled         = true;
                        occlusFade.Play();
                    }
                }
                else
                {
                    res.occlusFadingIn  = true;
                    res.occlusFadingOut = false;

                    Effect.SceneFadeInOutMaterialFloat occlusFade = res.occlusFadInstance;
                    occlusFade.SetMaterialInstance(matList);
                    occlusFade.FadeOutDuartion = occlusFade.FadeTimer;
                    occlusFade.FadeOutFrom     = occlusFade.currentFloat;
                    occlusFade.FadeOutTo       = 0;
                    occlusFade.FadeTimer       = 0;



                    occlusFade.Update();

                    if (occlusFade)
                    {
                        occlusFade.ReStartFadeOutFinish_Constant();
                    }
                }
            }
            else
            {
                res.occlusFadingIn        = true;
                res.occlusFadingOut       = false;
                parent.isDistanceFadingIn = false;

                Effect.SceneFadeInOutMaterialFloat distanceFade = Batches_TreeNodeFadeTable[parent];
                Effect.SceneFadeInOutMaterialFloat occlusFade   = GetFadeInstance(res);
                occlusFade.enabled = true;


                occlusFade.SetMaterialInstance(matList);
                occlusFade.FadeOutDuartion = distanceFade.FadeTimer;
                occlusFade.FadeOutFrom     = distanceFade.currentFloat;
                occlusFade.FadeOutTo       = 0;
                occlusFade.FadeTimer       = 0;
                occlusFade.Update();

                if (occlusFade)
                {
                    occlusFade.Play();
                }


                distanceFade.enabled = false;
                distanceFade.Stop();
            }
        }
    }