| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244 | using Fort23.Core;using Fort23.Mono.Test;using Fort23.UTool;using UnityEngine;using UnityEngine.Events;using UnityEngine.Rendering;using UnityEngine.Rendering.Universal;namespace Fort23.Mono{    [UIBinding(prefab = "BackgroundPanel")]    public partial class BackgroundPanel : UIPanel    {        // public RawImage backImage;        public UnityAction callback;        protected Material Material;        /// <summary>        /// 是否激活背景开关        /// </summary>        public bool EnableBGBtn        {            get { return _enableBGBtn; }            set { _enableBGBtn = value; }        }        private bool _enableBGBtn = true;        public void Init()        {            isAddStack = false;            IsShowAppBar = false;        }        protected override void AddEvent()        {        }        private RenderTexture renderTexture        {            get            {                if (_renderTexture == null)                {                    _renderTexture = new RenderTexture(Screen.width, Screen.height, 0, RenderTextureFormat.Default);                }                return _renderTexture;            }        }        private RenderTexture _renderTexture;        public override CTask Show()        {            if (GObjectPoolInterface == null)            {                return null;            }            CTask cTask = CTask.Create();            _isShow = true;            GObjectPoolInterface.SetActive(true);            if (timerEntity != null)            {                TimerComponent.Instance.Remove(timerEntity);            }            if (openTimerEntity != null)            {                TimerComponent.Instance.Remove(openTimerEntity);            }            ShowAnimator();            cTask.SetResult();            return cTask;        }        protected override async CTask ProOpen()        {            ManualAsyncTask ct = ManualAsyncTask.Create();            // if (GObjectPoolInterface != null)            // {            //     GObjectPoolInterface.SetActive(false);            // }            IsClose = true;            isFullUI = true;            UIManager.Instance.RefreshFull();            IsClose = false;            // Shader.SetGlobalTexture(CameraTransparentColorTexture, renderTexture);            InterceptGamePass.SetRenderTexture(renderTexture, delegate { ct.SetResult(); }, executeCallBack: Execute);            await ct.Wait();            LogTool.Log("完成背景图加载");            if (RawImage.texture != renderTexture)            {                RawImage.texture = renderTexture;            }            if (GObjectPoolInterface != null)            {                GObjectPoolInterface.SetActive(true);            }            UIManager.Instance.RefreshFull();            // TimerComponent.Instance.AddTimer(500, delegate { UIManager.Instance.RefreshFull(); });        }        protected void Execute(ScriptableRenderContext context, RenderingData renderingData,            RenderTexture renderTargetHandle, RenderTargetIdentifier source,            RenderTextureDescriptor cameraTextureDescriptor)        {            if (Material == null)            {                Material = new Material(Shader.Find("Unlit/MoHu"));            }            // return;            // LogTool.Log("回调背景图加载");            CommandBuffer cmd = CommandBufferPool.Get("background");            int w = cameraTextureDescriptor.width;            int h = cameraTextureDescriptor.height;            int randerIndex = -255;            RenderTargetIdentifier lasetIdentifier = default;            int lasetranderIndex = 10000;            for (int i = 0; i < 4; i++)            {                w /= 2;                h /= 2;                if (w <= 1 || h <= 1)                {                    break;                }                int index = Shader.PropertyToID("back_tu" + i);                // isTu1 = !isTu1;                cmd.GetTemporaryRT(index, w, h, 0, FilterMode.Bilinear, RenderTextureFormat.ARGB32);                RenderTargetIdentifier renderTargetIdentifier = new RenderTargetIdentifier(index);                if (lasetranderIndex != 10000)                {                    cmd.Blit(lasetIdentifier, renderTargetIdentifier, Material, 0);                    cmd.ReleaseTemporaryRT(lasetranderIndex);                }                else                {                    cmd.Blit(source, renderTargetIdentifier, Material, 0);                }                lasetIdentifier = renderTargetIdentifier;                lasetranderIndex = index;            }            for (int i = 0; i < 4; i++)            {                w *= 2;                h *= 2;                if (w > cameraTextureDescriptor.width || h > cameraTextureDescriptor.height)                {                    break;                }                int index = Shader.PropertyToID("back_fd" + i);                cmd.GetTemporaryRT(index, w, h, 0, FilterMode.Bilinear, RenderTextureFormat.ARGB32);                RenderTargetIdentifier renderTargetIdentifier = new RenderTargetIdentifier(index);                if (lasetranderIndex != 10000)                {                    cmd.Blit(lasetIdentifier, renderTargetIdentifier, Material, 1);                    cmd.ReleaseTemporaryRT(lasetranderIndex);                }                lasetIdentifier = renderTargetIdentifier;                lasetranderIndex = index;            }            // int index = Shader.PropertyToID("back_tu");            // isTu1 = !isTu1;            // cmd.GetTemporaryRT(index, w, h, 0, FilterMode.Bilinear,            //     RenderTextureFormat.ARGB32);            // RenderTargetIdentifier renderTargetIdentifier = new RenderTargetIdentifier(index);            // cmd.Blit(source, renderTargetIdentifier,Material,0);            cmd.Blit(lasetIdentifier, renderTargetHandle, Material, 2);            cmd.ReleaseTemporaryRT(lasetranderIndex);            context.ExecuteCommandBuffer(cmd);            CommandBufferPool.Release(cmd);        }        /// <summary>        /// 关闭当前有背景的面板        /// </summary>        public void CloseTopPanel()        {            if (!EnableBGBtn)            {                return;            }            if (UIManager.Instance.AllShowBGUIs.Count > 0 && UIManager.Instance.AllShowBGUIs[^1] != null)            {                UIPanel uiPanel = UIManager.Instance.AllShowBGUIs[^1];                if (!uiPanel.IsHindBackground())                {                    return;                }            }            UnityAction action = callback;            callback = null;            if (action != null)                action?.Invoke();            Close();            if (UIManager.Instance.AllShowBGUIs.Count > 0 && UIManager.Instance.AllShowBGUIs[^1] != null)            {                UIPanel uiPanel = UIManager.Instance.AllShowBGUIs[^1];                uiPanel.BackgroundCallBack();                UIManager.Instance.HideUIUIPanel(uiPanel);            }        }        public override void AddButtonEvent()        {            Btn_BG.onClick.AddListener(CloseTopPanel);        }        public void CustomInit()        {        }        protected override void DelEvent()        {        }        public async override CTask Close()        {            EnableBGBtn = true;            await base.Close();        }    }}
 |