示例#1
0
    void ClearRendering()
    {
        if (BaseSoldierCamera.MainInstance())
        {
            BaseSoldierCamera.MainInstance().UnRegsiterCameraModeChangeEvent(OnCameraModeChange);
        }
        isOcclusFadingEnabled_Camera = false;
        isOcclusFadingEnabled_GodEye = false;
        isOcclusFadingEnabled        = false;
        isOcclusValiding             = false;

        HitColliderBuffer = null;
        ClearAlphaMaterial();
        OrginalMaterList = null;
        Orginal_AlphaInstanceTable.Clear();
        Batch_instanceMaterials = null;
        BatchesIDs.Clear();

        m_HostColliderList.Clear();
        supportOptimitzedMatList.Clear();
        if (null != ShareResList)
        {
            ShareResList.Clear();
        }
    }
示例#2
0
    /// <summary>
    /// 初始化渲染相关的东西
    /// </summary>
    void InitRendering()
    {
        OrginalLayer = hostRender.gameObject.layer;
        if (OrginalMaterList == null)
        {
            OrginalMaterList = hostRender.sharedMaterials;
            int cou = OrginalMaterList.Length;
            for (int i = 0; i < cou; i++)
            {
                SetMaterialParams(OrginalMaterList[i]);
            }
        }
        SceneShareCollider ShareColliderRender = GetComponent <SceneShareCollider>();

        if (ShareColliderRender)
        {
            if (null != ShareColliderRender.ShareList && ShareColliderRender.ShareList.Count > 0)
            {
                ShareResList = new List <SceneResInfo>();
                foreach (Renderer re in ShareColliderRender.ShareList)
                {
                    SceneResInfo sc = re.GetComponent <SceneResInfo>();
                    if (sc)
                    {
                        ShareResList.Add(sc);
                    }
                }
            }
        }


        UpdateCollider();
        CreateAlphaMaterial();

        UpdateVisible();
        if (BaseSoldierCamera.MainInstance())
        {
            BaseSoldierCamera.MainInstance().RegsiterCameraModeChangeEvent(OnCameraModeChange);
        }
    }
示例#3
0
 public BaseCameraController()
 {
     this.soldierCam = BaseSoldierCamera.MainInstance <SoldierCamera>();
     Init();
     SetAllowChangeList();
 }
示例#4
0
    public void CheckOcclus()
    {
        //只有战场才有这个功能
        if (GameLogicAPI.isInWarScene() <= 0 || !hostResManager.IsActive || BaseStageManager.Instance.CurSubState == EStage_SubState.ESSS_WAREND)
        {
            return;
        }
        //地形不做这个检测并且没有被优化的,因为优化的已经没了
        if (AlwaysVisible && !isTerrain && !bOptimitzedRendering && BaseSoldierCamera.MainInstance())
        {
            //已经有一个了,不需要进行下面的计算了
            if (isOcclusFadingEnabled_GodEye)
            {
                UpdateOcclusFading();
                return;
            }
            if (!EnableOcclusFading_Camera)
            {
                return;
            }
            Vector3 pos = mainCameraTransform.position;
            isOcclusFadingEnabled_Camera = false;
            GameObject view           = BaseSoldierCamera.MainInstance().GetSoliderGo();
            float      heightInMeters = BaseSoldierCamera.MainInstance().GetSoliderHeightInMeters();
            if (view == null)
            {
                return;
            }

            if (view != null && view.gameObject)
            {
                Vector3 mainPlayPos = view.transform.position;
                mainPlayPos.y      += heightInMeters;
                CheckRay_Top.origin = mainPlayPos;
                Vector3 dir = pos - mainPlayPos;
                PlayerCameraDistance = Vector3.Distance(mainPlayPos, pos);

                CheckRay_Top.direction = dir.normalized;
                RaycastHit hitInfo;

                foreach (Collider col in m_HostColliderList)
                {
                    if (col.Raycast(CheckRay_Top, out hitInfo, PlayerCameraDistance))
                    {
                        isOcclusFadingEnabled_Camera = true;
                        UpdateOcclusFading();
                        UpdateShareCollider(true);
                        return;
                    }
                }

                mainPlayPos          = view.gameObject.transform.position;
                mainPlayPos.y       += heightInMeters * 0.2f;
                CheckRay_Down.origin = mainPlayPos;
                dir = pos - mainPlayPos;

                PlayerCameraDistance = Vector3.Distance(mainPlayPos, pos);

                CheckRay_Down.direction = dir.normalized;
                if (!isOcclusFadingEnabled_Camera)
                {
                    foreach (Collider col in m_HostColliderList)
                    {
                        if (col.Raycast(CheckRay_Down, out hitInfo, PlayerCameraDistance))
                        {
                            isOcclusFadingEnabled_Camera = true;
                            UpdateOcclusFading();
                            UpdateShareCollider(true);
                            return;
                        }

                        int oldLayer = col.gameObject.layer;
                        col.gameObject.layer = LayerMask.NameToLayer(Config.LayerLightingEffectOnly);

                        int cout = Physics.OverlapSphereNonAlloc(pos, 1.5f, HitColliderBuffer, 1 << LayerMask.NameToLayer(Config.LayerLightingEffectOnly));
                        if (cout > 0)
                        {
                            isOcclusFadingEnabled_Camera = true;
                            UpdateOcclusFading();
                            UpdateShareCollider(true);
                            col.gameObject.layer = oldLayer;
                            return;
                        }
                        col.gameObject.layer = oldLayer;
                    }
                }
                UpdateOcclusFading();
                UpdateShareCollider(false);
            }
        }
    }
示例#5
0
    IEnumerator InfoCheck()
    {
        if (DelayTime > 0.03f)
        {
            yield return(new WaitForSeconds(DelayTime));
        }
        OcclusCullingInit();
        while (true)
        {
            //if (Application.isEditor)
            //{
            //    Shader.SetGlobalFloat("_SceneBrightScale", SceneBrightScale);
            //    Shader.SetGlobalFloat("_CharacterBrightScale", CharacterBrightScale);
            //}

            if (!WaitngUpdate)
            {
                if (BaseSoldierCamera.MainInstance().GetSoliderGo())
                {
                    yield return(halfupdateTimer);

                    WaitngUpdate = true;
                }
            }

            if (isCanUpdate && m_IsActive && WaitngUpdate)
            {
                Vector3 pos   = SceneRoot.transform.worldToLocalMatrix.MultiplyPoint(SceneCamera.transform.position);
                Vector2 pos2D = Vector2.zero;
                Vector2 Dir2D = Vector2.zero;

                Dir2D.x = SceneCamera.transform.forward.x;
                Dir2D.y = SceneCamera.transform.forward.z;

                pos2D.x = pos.x;
                pos2D.y = pos.z;

                GenerateActiveQuadParent(ResRootParent, SceneCamera.fieldOfView, pos2D, Dir2D, currResInfoCellSize, ref ActiveResLeafList, ref ActiveResParent, ref unUsedResLeafList, ref unUsedResParent);
                GenerateActiveQuadParent(GrassResRootParent, SceneCamera.fieldOfView, pos2D, Dir2D, currGrassResInfoCellSize, ref ActiveGrassResLeafList, ref ActiveGrassResParent, ref unUsedGrassResLeafList, ref unUsedGrassResParent);
                GenerateActiveQuadParent(LightRootParent, SceneCamera.fieldOfView, pos2D, Dir2D, currResLightCellSize, ref ActiveLightLeafList, ref ActiveLightParent, ref unUsedLightLeafList, ref unUsedLightParent);
                GenerateActiveQuadParent(ColliderRootParent, SceneCamera.fieldOfView, pos2D, Dir2D, currResColliderCellSize, ref ActiveColliderLeafList, ref ActiveColliderParent, ref unUsedColliderLeafList, ref unUsedColliderParent);
                GenerateActiveQuadParent(EffectRootParent, SceneCamera.fieldOfView, pos2D, Dir2D, currEffectCellSize, ref ActiveEffectLeafList, ref ActiveEffectParent, ref unUsedEffectLeafList, ref unUsedEffectParent);
                GenerateActiveQuadParent(AlwaysVisibleResRootParent, SceneCamera.fieldOfView, pos2D, Dir2D, currAlwaysVisibleResInfoCellSize, ref ActiveAlwaysVisibleResLeafList, ref ActiveAlwaysVisibleResParent, ref unUsedAlwaysVisibleResLeafList, ref unUsedAlwaysVisibleResParent);

                int ResallCount  = ActiveResParent.Count;
                int ReshalfCount = ResallCount / 2;
                ReshalfCount = Mathf.Min(ReshalfCount, ResallCount);

                int GrassResallCount  = ActiveGrassResParent.Count;
                int GrassReshalfCount = GrassResallCount / 2;
                GrassReshalfCount = Mathf.Min(GrassReshalfCount, GrassResallCount);

                int LightallCount  = ActiveLightLeafList.Count;
                int LighthalfCount = LightallCount / 2;
                LighthalfCount = Mathf.Min(LighthalfCount, LightallCount);

                int ColliderallCount  = ActiveColliderLeafList.Count;
                int ColliderhalfCount = ColliderallCount / 2;
                ColliderhalfCount = Mathf.Min(ColliderhalfCount, ColliderallCount);

                int EffectallCount  = ActiveEffectLeafList.Count;
                int EffecthalfCount = EffectallCount / 2;
                EffecthalfCount = Mathf.Min(EffecthalfCount, EffectallCount);

                int AlwaysVisibleResallCount  = ActiveAlwaysVisibleResLeafList.Count;
                int AlwaysVisibleReshalfCount = AlwaysVisibleResallCount / 2;
                AlwaysVisibleReshalfCount = Mathf.Min(AlwaysVisibleReshalfCount, AlwaysVisibleResallCount);



                int unUsedResallCount  = unUsedResParent.Count;
                int unUsedReshalfCount = unUsedResallCount / 2;
                unUsedReshalfCount = Mathf.Min(unUsedReshalfCount, unUsedResallCount);

                int unUsedGrassResallCount  = unUsedGrassResParent.Count;
                int unUsedGrassReshalfCount = unUsedGrassResallCount / 2;
                unUsedGrassReshalfCount = Mathf.Min(unUsedGrassReshalfCount, unUsedGrassResallCount);

                int unUsedLightallCount  = unUsedLightLeafList.Count;
                int unUsedLighthalfCount = unUsedLightallCount / 2;
                unUsedLighthalfCount = Mathf.Min(unUsedLighthalfCount, unUsedLightallCount);

                int unUsedColliderallCount  = unUsedColliderLeafList.Count;
                int unUsedColliderhalfCount = unUsedColliderallCount / 2;
                unUsedColliderhalfCount = Mathf.Min(unUsedColliderhalfCount, unUsedColliderallCount);

                int unUsedEffectallCount  = unUsedEffectLeafList.Count;
                int unUsedEffecthalfCount = unUsedEffectallCount / 2;
                unUsedEffecthalfCount = Mathf.Min(unUsedEffecthalfCount, unUsedEffectallCount);

                int unUsedAlwaysVisibleResallCount  = unUsedAlwaysVisibleResLeafList.Count;
                int unUsedAlwaysVisibleReshalfCount = unUsedAlwaysVisibleResallCount / 2;
                unUsedAlwaysVisibleReshalfCount = Mathf.Min(unUsedAlwaysVisibleReshalfCount, unUsedAlwaysVisibleResallCount);

                //先处理一半

                UpdateResInfo(0, ReshalfCount, ActiveResParent);
                UpdateGrassResInfo(0, GrassReshalfCount, ActiveGrassResParent);
                UpdateLightInfo(0, LighthalfCount, ActiveLightLeafList);
                UpdateColliderInfo(0, ColliderhalfCount, ActiveColliderLeafList);
                UpdateEffectInfo(0, EffecthalfCount, ActiveEffectLeafList);
                UpdateAlwaysVisibleResInfo(0, AlwaysVisibleReshalfCount, ActiveAlwaysVisibleResLeafList);

                ProcessUnUsedResInfo(0, unUsedReshalfCount, unUsedResParent);
                ProcessUnUsedGrassResInfo(0, unUsedGrassReshalfCount, unUsedGrassResParent);
                ProcessUnUsedLightInfo(0, unUsedLighthalfCount, unUsedLightLeafList);
                ProcessUnUsedColliderInfo(0, unUsedColliderhalfCount, unUsedColliderLeafList);
                ProcessUnUsedEffectInfo(0, unUsedEffecthalfCount, unUsedEffectLeafList);
                ProcessUnUsedAlwaysVisibleResInfo(0, unUsedAlwaysVisibleReshalfCount, unUsedAlwaysVisibleResLeafList);

                yield return(halfupdateTimer);

                UpdateResInfo(ReshalfCount, ResallCount, ActiveResParent);
                UpdateGrassResInfo(GrassReshalfCount, GrassResallCount, ActiveGrassResParent);
                UpdateLightInfo(LighthalfCount, LightallCount, ActiveLightLeafList);
                UpdateColliderInfo(ColliderhalfCount, ColliderallCount, ActiveColliderLeafList);
                UpdateEffectInfo(EffecthalfCount, EffectallCount, ActiveEffectLeafList);
                UpdateAlwaysVisibleResInfo(AlwaysVisibleReshalfCount, AlwaysVisibleResallCount, ActiveAlwaysVisibleResLeafList);

                ProcessUnUsedResInfo(unUsedReshalfCount, unUsedResallCount, unUsedResParent);
                ProcessUnUsedGrassResInfo(unUsedGrassReshalfCount, unUsedGrassResallCount, unUsedGrassResParent);
                ProcessUnUsedLightInfo(unUsedLighthalfCount, unUsedLightallCount, unUsedLightLeafList);
                ProcessUnUsedColliderInfo(unUsedColliderhalfCount, unUsedColliderallCount, unUsedColliderLeafList);
                ProcessUnUsedEffectInfo(unUsedEffecthalfCount, unUsedEffectallCount, unUsedEffectLeafList);
                ProcessUnUsedAlwaysVisibleResInfo(unUsedAlwaysVisibleReshalfCount, unUsedAlwaysVisibleResallCount, unUsedAlwaysVisibleResLeafList);
            }

            yield return(halfupdateTimer);
        }
    }