home打开关闭逻辑修改调整提交
This commit is contained in:
93
Assets/Scripts/Common/Blur/UIBlur.cs
Normal file
93
Assets/Scripts/Common/Blur/UIBlur.cs
Normal file
@@ -0,0 +1,93 @@
|
||||
using FairyGUI;
|
||||
using NBF;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class UIBlur : MonoBehaviour
|
||||
{
|
||||
[Header("Quality")] public RenderTexture blurRT;
|
||||
[Range(1, 6)] public int iterations = 2; // 模糊迭代次数
|
||||
[Range(0.5f, 4f)] public float blurSize = 1.2f;
|
||||
|
||||
[Header("Shader")] public Shader blurShader;
|
||||
|
||||
Material _mat;
|
||||
|
||||
RenderTexture _capturedRT;
|
||||
public static UIBlur Instance { get; private set; }
|
||||
|
||||
void Awake()
|
||||
{
|
||||
blurRT = new RenderTexture((int)(Screen.width * 0.5f), (int)(Screen.height * 0.5f), 0,
|
||||
RenderTextureFormat.ARGB32);
|
||||
_mat = new Material(blurShader);
|
||||
DontDestroyOnLoad(gameObject);
|
||||
Instance = this;
|
||||
}
|
||||
|
||||
public void CaptureAndBlurOnce()
|
||||
{
|
||||
if (blurRT == null) return;
|
||||
var captureCamera = Camera.main;
|
||||
if (captureCamera == null) return;
|
||||
|
||||
|
||||
int w = blurRT.width;
|
||||
int h = blurRT.width;
|
||||
|
||||
ReleaseRTs();
|
||||
|
||||
var oldEnabled = StageCamera.main.enabled;
|
||||
|
||||
StageCamera.main.enabled = false;
|
||||
|
||||
_capturedRT = new RenderTexture(w, h, 0, RenderTextureFormat.ARGB32);
|
||||
_capturedRT.Create();
|
||||
|
||||
// 1) 抓摄像机画面到RT(不做ReadPixels)
|
||||
var prevTarget = captureCamera.targetTexture;
|
||||
captureCamera.targetTexture = _capturedRT;
|
||||
captureCamera.Render();
|
||||
captureCamera.targetTexture = prevTarget;
|
||||
StageCamera.main.enabled = oldEnabled;
|
||||
// 2) 模糊:ping-pong
|
||||
var rt1 = RenderTexture.GetTemporary(w, h, 0, RenderTextureFormat.ARGB32);
|
||||
var rt2 = RenderTexture.GetTemporary(w, h, 0, RenderTextureFormat.ARGB32);
|
||||
|
||||
Graphics.Blit(_capturedRT, rt1);
|
||||
|
||||
_mat.SetFloat("_BlurSize", blurSize);
|
||||
|
||||
for (int i = 0; i < iterations; i++)
|
||||
{
|
||||
// 横向
|
||||
_mat.SetVector("_Direction", new Vector2(1, 0));
|
||||
Graphics.Blit(rt1, rt2, _mat);
|
||||
|
||||
// 纵向
|
||||
_mat.SetVector("_Direction", new Vector2(0, 1));
|
||||
Graphics.Blit(rt2, rt1, _mat);
|
||||
}
|
||||
|
||||
Graphics.Blit(rt1, blurRT);
|
||||
|
||||
RenderTexture.ReleaseTemporary(rt1);
|
||||
RenderTexture.ReleaseTemporary(rt2);
|
||||
}
|
||||
|
||||
void ReleaseRTs()
|
||||
{
|
||||
if (_capturedRT != null)
|
||||
{
|
||||
_capturedRT.Release();
|
||||
Destroy(_capturedRT);
|
||||
_capturedRT = null;
|
||||
}
|
||||
}
|
||||
|
||||
void OnDestroy()
|
||||
{
|
||||
ReleaseRTs();
|
||||
if (_mat) Destroy(_mat);
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Common/Blur/UIBlur.cs.meta
Normal file
3
Assets/Scripts/Common/Blur/UIBlur.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9a0a734b63534f5e8f244a76a4a8f48d
|
||||
timeCreated: 1770122480
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
@@ -91,10 +92,15 @@ namespace NBF
|
||||
return;
|
||||
}
|
||||
|
||||
// 读取 Build Settings 中 “Scenes In Build” 勾选的场景
|
||||
var scenes = EditorBuildSettings.scenes
|
||||
.Where(s => s.enabled)
|
||||
.Select(s => s.path)
|
||||
.ToArray();
|
||||
var buildOptions = BuildOptions.CompressWithLz4;
|
||||
BuildPlayerOptions buildPlayerOptions = new BuildPlayerOptions()
|
||||
{
|
||||
scenes = new[] { "Assets/Scenes/StartUp.unity" },//Assets/Scenes/StartUp.unity
|
||||
scenes = scenes, //new[] { "Assets/Scenes/StartUp.unity" }, //Assets/Scenes/StartUp.unity
|
||||
locationPathName = location,
|
||||
options = buildOptions,
|
||||
target = activeTarget,
|
||||
|
||||
26
Assets/Scripts/Editor/Test/UIBlurEditor.cs
Normal file
26
Assets/Scripts/Editor/Test/UIBlurEditor.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NBF
|
||||
{
|
||||
[CustomEditor(typeof(UIBlur))]
|
||||
public class UIBlurEditor : Editor
|
||||
{
|
||||
private UIBlur _target;
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
_target = target as UIBlur;
|
||||
// lookAtPoint = serializedObject.FindProperty("lookAtPoint");
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
base.OnInspectorGUI();
|
||||
if (GUILayout.Button("Blur"))
|
||||
{
|
||||
_target.CaptureAndBlurOnce();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Editor/Test/UIBlurEditor.cs.meta
Normal file
3
Assets/Scripts/Editor/Test/UIBlurEditor.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ebaa0f203943458688dac255c2ea6441
|
||||
timeCreated: 1770124598
|
||||
@@ -61,7 +61,7 @@ namespace NBF
|
||||
// await Task.Delay(100);
|
||||
CommonTopPanel.Show();
|
||||
// SettingPanel.Show();
|
||||
// LoginPanel.Show();
|
||||
LoginPanel.Show();
|
||||
// PreviewPanel.Show();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ namespace NBF
|
||||
public static void BindAll()
|
||||
{
|
||||
UIObjectFactory.SetPackageItemExtension(SelectPages.URL, typeof(SelectPages));
|
||||
UIObjectFactory.SetPackageItemExtension(UIBlurBackground.URL, typeof(UIBlurBackground));
|
||||
UIObjectFactory.SetPackageItemExtension(BottomMenu.URL, typeof(BottomMenu));
|
||||
UIObjectFactory.SetPackageItemExtension(CommonInput.URL, typeof(CommonInput));
|
||||
UIObjectFactory.SetPackageItemExtension(ClassifyList.URL, typeof(ClassifyList));
|
||||
|
||||
@@ -17,6 +17,17 @@ namespace NBF
|
||||
|
||||
protected override void OnShow()
|
||||
{
|
||||
InputManager.OnUICanceled += OnUICanceled;
|
||||
}
|
||||
|
||||
private void OnUICanceled(string action)
|
||||
{
|
||||
if (action == InputDef.UI.Back)
|
||||
{
|
||||
var panel = UI.Inst.GetUI<HomePanel>();
|
||||
if (panel != null && panel.IsShowing) return;
|
||||
HomePanel.Show();
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnUpdate()
|
||||
@@ -60,6 +71,7 @@ namespace NBF
|
||||
|
||||
protected override void OnHide()
|
||||
{
|
||||
InputManager.OnUICanceled -= OnUICanceled;
|
||||
}
|
||||
|
||||
protected override void OnDestroy()
|
||||
|
||||
@@ -36,10 +36,21 @@ namespace NBF
|
||||
|
||||
protected override void OnShow()
|
||||
{
|
||||
InputManager.Instance.On(this);
|
||||
Menu.SetTabs(tabList);
|
||||
ChangeTab(0);
|
||||
}
|
||||
|
||||
#region UI事件
|
||||
|
||||
[InputInvoke(InputDef.UI.Back, UIInputButtonShowMode.BottomRight)]
|
||||
private void OnBack()
|
||||
{
|
||||
Hide();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Tab切换
|
||||
|
||||
private void ChangeTab(int index)
|
||||
@@ -84,6 +95,7 @@ namespace NBF
|
||||
|
||||
protected override void OnHide()
|
||||
{
|
||||
InputManager.Instance.Off(this);
|
||||
}
|
||||
|
||||
protected override void OnDestroy()
|
||||
|
||||
@@ -30,15 +30,15 @@ namespace NBF
|
||||
{
|
||||
await LoginHelper.Login(InputAccount.text);
|
||||
|
||||
// await Fishing.Instance.Go(RoleModel.Instance.Info.MapId);
|
||||
await Fishing.Instance.Go(RoleModel.Instance.Info.MapId);
|
||||
// await MapHelper.EnterMap(mapId, role.RoomCode);
|
||||
|
||||
// BagPanel.Show();
|
||||
// BagSlotPanel.Show();
|
||||
|
||||
// SettingPanel.Show();
|
||||
HomePanel.Show();
|
||||
// FishingShopPanel.Show();
|
||||
// HomePanel.Show();
|
||||
FishingShopPanel.Show();
|
||||
|
||||
Del();
|
||||
}
|
||||
|
||||
27
Assets/Scripts/UI/UIBlurBackground.Designer.cs
generated
Normal file
27
Assets/Scripts/UI/UIBlurBackground.Designer.cs
generated
Normal file
@@ -0,0 +1,27 @@
|
||||
/**本脚本为自动生成,每次生成会覆盖!请勿手动修改,生成插件文档及项目地址:https://git.whoot.com/whoot-games/whoot.fguieditorplugin**/
|
||||
|
||||
|
||||
using FairyGUI;
|
||||
using FairyGUI.Utils;
|
||||
using NBC;
|
||||
|
||||
namespace NBF
|
||||
{
|
||||
public partial class UIBlurBackground
|
||||
{
|
||||
public const string URL = "ui://6hgkvlau8hy8la";
|
||||
|
||||
public GLoader Back;
|
||||
public GImage back;
|
||||
|
||||
public override void ConstructFromXML(XML xml)
|
||||
{
|
||||
base.ConstructFromXML(xml);
|
||||
|
||||
Back = (GLoader)GetChild("Back");
|
||||
back = (GImage)GetChild("back");
|
||||
OnInited();
|
||||
UILanguage.TrySetComponentLanguage(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/UI/UIBlurBackground.Designer.cs.meta
Normal file
2
Assets/Scripts/UI/UIBlurBackground.Designer.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 37696980c373d4d46884022914bfe1b9
|
||||
31
Assets/Scripts/UI/UIBlurBackground.cs
Normal file
31
Assets/Scripts/UI/UIBlurBackground.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
// 本脚本只在不存在时会生成一次。组件逻辑写在当前脚本内。已存在不会再次生成覆盖
|
||||
|
||||
using UnityEngine;
|
||||
using FairyGUI;
|
||||
using NBC;
|
||||
|
||||
namespace NBF
|
||||
{
|
||||
public partial class UIBlurBackground : GLabel
|
||||
{
|
||||
private NTexture _nTexture;
|
||||
|
||||
private void OnInited()
|
||||
{
|
||||
// icon = new NTexture(your_Texture2D);
|
||||
// UIBlur.texture = new NTexture(UIBlur);
|
||||
UIBlur.Instance.CaptureAndBlurOnce();
|
||||
Back.texture = new NTexture(UIBlur.Instance.blurRT);
|
||||
}
|
||||
|
||||
public override void Dispose()
|
||||
{
|
||||
// if (_nTexture != null)
|
||||
// {
|
||||
// _nTexture = null;
|
||||
// }
|
||||
|
||||
base.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/UI/UIBlurBackground.cs.meta
Normal file
2
Assets/Scripts/UI/UIBlurBackground.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 93754091e25692446aabdab03d905f42
|
||||
Reference in New Issue
Block a user