diff --git a/Runtime/Consts.cs b/Runtime/Consts.cs index 1833f87..9cf27c9 100644 --- a/Runtime/Consts.cs +++ b/Runtime/Consts.cs @@ -29,7 +29,7 @@ namespace DCFApixels - private enum PauseStateX + private enum DebugXPauseState { Unpaused = 0, PreUnpaused = 1, //нужно чтобы отщелкунть паузу с задержкой в один тик diff --git a/Runtime/DebugX.cs b/Runtime/DebugX.cs index 4147200..02e3d3e 100644 --- a/Runtime/DebugX.cs +++ b/Runtime/DebugX.cs @@ -22,7 +22,7 @@ namespace DCFApixels using IN = System.Runtime.CompilerServices.MethodImplAttribute; public static unsafe partial class DebugX { - private static PauseStateX _pauseState = PauseStateX.Unpaused; + private static DebugXPauseState _pauseState = DebugXPauseState.Unpaused; private static bool _isCameraContext = false; private static double _lastUnityTime; @@ -31,18 +31,12 @@ namespace DCFApixels private static ulong _editorTicks = 0; private static ulong _lastEditorToRenderTicks = 1000; private static ulong _renderTicks = 100; - //private static ulong _lastEditorToRenderGizmosTicks = 1000; - //private static ulong _renderGizmosTicks = 100; private static ulong _timeTicks = 0; public static ulong RenderTicks { get { return _renderTicks; } } - //public static ulong RenderGizmosTicks - //{ - // get { return _renderGizmosTicks; } - //} public static ulong TimeTicks { get { return _timeTicks; } @@ -65,7 +59,7 @@ namespace DCFApixels #if UNITY_EDITOR private static void EditorApplication_pauseStateChanged(PauseState obj) { - _pauseState = obj == PauseState.Paused ? PauseStateX.Paused : PauseStateX.PreUnpaused; + _pauseState = obj == PauseState.Paused ? DebugXPauseState.Paused : DebugXPauseState.PreUnpaused; } #endif #endregion @@ -234,12 +228,10 @@ namespace DCFApixels private static void OnPreRender_BRP(Camera camera) { PreRender_General(camera); - //throw new NotImplementedException(); } private static void OnPostRender_BRP(Camera camera) { PostRender_General(CommandBufferExecutorBRP.GetInstance(), camera); - //throw new NotImplementedException(); } private static void PreUpdateCallback() @@ -250,7 +242,7 @@ namespace DCFApixels if (_lastUnityTime < Time.unscaledTimeAsDouble) { _timeTicks++; - if (_pauseState == PauseStateX.Unpaused) + if (_pauseState == DebugXPauseState.Unpaused) { _deltaTime = Time.unscaledDeltaTime * _timeScaleCache; } @@ -269,9 +261,9 @@ namespace DCFApixels } } _lastUnityTime = Time.unscaledTimeAsDouble; - if (_pauseState == PauseStateX.PreUnpaused) + if (_pauseState == DebugXPauseState.PreUnpaused) { - _pauseState = PauseStateX.Unpaused; + _pauseState = DebugXPauseState.Unpaused; } SetGameSceneContext(); } @@ -294,7 +286,6 @@ namespace DCFApixels _currentCamera = camera; } - private static void PostRender_General(ICommandBufferExecutor cbExecutor, Camera camera) { if (_lastEditorToRenderTicks != _editorTicks) @@ -307,8 +298,9 @@ namespace DCFApixels { RenderContextController.StaicContextController.Prepare(); RenderContextController.StaicContextController.Render(cbExecutor); - - CallDrawGizmos(camera); + cbExecutor.Submit(); + RenderContextController.StaicContextController.PostRender(); + RenderContextController.StaicContextController.RunEnd(); } if (camera == null) { return; } @@ -316,54 +308,10 @@ namespace DCFApixels RenderContextController contextController = RenderContextController.GetController(new RenderContext(camera)); contextController.Prepare(); contextController.Render(cbExecutor); - + cbExecutor.Submit(); + contextController.PostRender(); + contextController.RunEnd(); } - -#if UNITY_EDITOR - - [DrawGizmo(GizmoType.NonSelected | GizmoType.Selected)] - private static void DrawGizmos(Camera obj, GizmoType gizmoType) - { - if (obj != Camera.main) { return; } - - //if (_lastEditorToRenderGizmosTicks != _editorTicks) - //{ - // _renderGizmosTicks++; - // _lastEditorToRenderGizmosTicks = _editorTicks; - //} - - //Camera camera = Camera.current; - //CallDrawGizmos(camera); - } -#endif - - private static void CallDrawGizmos(Camera camera) - { - - Color guiColor = GUI.color; - Color guiContextColor = GUI.contentColor; - Color guiBackgroundColor = GUI.backgroundColor; - Color gizmosColor = Gizmos.color; -#if Handles - Color handlesColor = Handles.color; -#endif - GL.MultMatrix(Handles.matrix); - - RenderContextController.StaicContextController.Render_UnityGizmos(); - - if (camera == null) { return; } - _currentCamera = camera; - RenderContextController.GetController(new RenderContext(camera)).Render_UnityGizmos(); - - GUI.color = guiColor; - GUI.contentColor = guiContextColor; - GUI.backgroundColor = guiBackgroundColor; - Gizmos.color = gizmosColor; -#if Handles - Handles.color = handlesColor; -#endif - } - #endregion @@ -585,14 +533,12 @@ namespace DCFApixels { _buffers[i].Render(cbExecutor); } - - RunEnd(); } } [IN(LINE)] - public void Render_UnityGizmos() + public void PostRender() { #if UNITY_EDITOR using (_cameraMarker.Auto()) @@ -600,10 +546,8 @@ namespace DCFApixels { for (int i = 0, iMax = _buffers.Count; i < iMax; i++) { - _buffers[i].Render_UnityGizmos(); + _buffers[i].PostRender(); } - - //RunEnd(); } } @@ -631,7 +575,7 @@ namespace DCFApixels public abstract int UpdateTimer(float deltaTime); public abstract void Prepare(); public abstract void Render(ICommandBufferExecutor cbExecutor); - public abstract void Render_UnityGizmos(); + public abstract void PostRender(); public abstract int RunEnd(); public abstract void Clear(); } @@ -654,7 +598,7 @@ namespace DCFApixels //private readonly CommandBuffer _dynamicCommandBuffer; private readonly IGizmoRenderer _renderer; - private readonly IGizmoRenderer_UnityGizmos _rendererUnityGizmos; + private readonly IGizmoRenderer_PostRender _rendererUnityGizmos; private readonly bool _isStatic; #if DEV_MODE @@ -681,7 +625,7 @@ namespace DCFApixels _renderer = new DummyRenderer(); } _isStatic = _renderer.IsStaticRender; - _rendererUnityGizmos = _renderer as IGizmoRenderer_UnityGizmos; + _rendererUnityGizmos = _renderer as IGizmoRenderer_PostRender; All.Add(this); All.Sort((a, b) => a.ExecuteOrder - b.ExecuteOrder); @@ -800,7 +744,7 @@ namespace DCFApixels cbExecutor.Execute(_staticCommandBuffer); } } - public override void Render_UnityGizmos() + public override void PostRender() { if (_rendererUnityGizmos == null) { return; } //Debug.Log(_gizmos._count); @@ -812,7 +756,7 @@ namespace DCFApixels GizmosList list = GizmosList.From(_gizmos._items, _gizmos._count); try { - _rendererUnityGizmos.Render_UnityGizmos(GetCurrentCamera(), list); + _rendererUnityGizmos.PostRender(GetCurrentCamera(), list); } catch (Exception e) { throw new Exception($"[{_debugName}] [Render] ", e); } } diff --git a/Runtime/Gizmos/DebugX.text.cs b/Runtime/Gizmos/DebugX.text.cs index 784402f..b84dd9f 100644 --- a/Runtime/Gizmos/DebugX.text.cs +++ b/Runtime/Gizmos/DebugX.text.cs @@ -14,110 +14,150 @@ namespace DCFApixels public readonly partial struct DrawHandler { #region Text - [IN(LINE)] public DrawHandler TextWorldScale(Vector3 position, object text) => Gizmo(new TextGizmo(position, text, DebugXTextSettings.Default, true)); - [IN(LINE)] public DrawHandler TextWorldScale(Vector3 position, object text, DebugXTextSettings settings) => Gizmo(new TextGizmo(position, text, settings, true)); - [IN(LINE)] public DrawHandler Text(Vector3 position, object text) => Gizmo(new TextGizmo(position, text, DebugXTextSettings.Default, false)); - [IN(LINE)] public DrawHandler Text(Vector3 position, object text, DebugXTextSettings settings) => Gizmo(new TextGizmo(position, text, settings, false)); + [IN(LINE)] public DrawHandler Text(Vector3 position, object text) => Gizmo(new TextGizmo(position, text, DebugXTextSettings.Default)); + [IN(LINE)] public DrawHandler Text(Vector3 position, object text, DebugXTextSettings settings) => Gizmo(new TextGizmo(position, text, settings)); private readonly struct TextGizmo : IGizmo { public readonly Vector3 Position; public readonly string Text; public readonly DebugXTextSettings Settings; - public readonly bool IsWorldSpaceScale; [IN(LINE)] - public TextGizmo(Vector3 position, object text, DebugXTextSettings settings, bool isWorldSpaceScale) + public TextGizmo(Vector3 position, object text, DebugXTextSettings settings) { Position = position; Text = text.ToString(); Settings = settings; - IsWorldSpaceScale = isWorldSpaceScale; } public IGizmoRenderer RegisterNewRenderer() { return new Renderer(); } #region Renderer - private class Renderer : IGizmoRenderer_UnityGizmos + private class Renderer : IGizmoRenderer_PostRender { - private static GUIStyle _labelStyle; + private static GUIStyle _labelStyle; private static GUIContent _labelDummy; + private static Texture2D _whiteTexture; public int ExecuteOrder => default(UnlitMat).GetExecuteOrder(); public bool IsStaticRender => false; public void Prepare(Camera camera, GizmosList list) { } public void Render(Camera camera, GizmosList list, CommandBuffer cb) { } - public void Render_UnityGizmos(Camera camera, GizmosList list) + public void PostRender(Camera camera, GizmosList list) { -#if UNITY_EDITOR - if (Event.current.type != EventType.Repaint) { return; } - //bool c = camera.name == "SceneCamera"; - bool ccc = camera == Camera.main; - //bool x = camera == Camera.main; - bool x = true; - if (camera == null) { return; } + if (Event.current.type != EventType.Repaint) { return; } + Color dfColor = GUI.color; InitStatic(); - var zoom = GetCameraZoom(camera); + bool isSceneView = false; + var backgroundMaterial = DebugXAssets.Materials.TextBackground; - Handles.BeginGUI(); +#if UNITY_EDITOR + //TODO костыльный вариант, нужно поискать более надежный способ определить рендер SceneView + isSceneView = camera.name == "SceneCamera"; +#endif + + if (isSceneView) + { +#if UNITY_EDITOR + Handles.BeginGUI(); +#endif + } + else + { + GL.PushMatrix(); + GL.LoadPixelMatrix(0, Screen.width, Screen.height, 0); + } foreach (ref readonly var item in list) { _labelDummy.text = item.Value.Text; GUIStyle style = _labelStyle; - style.fontSize = item.Value.IsWorldSpaceScale - ? Mathf.FloorToInt(item.Value.Settings.FontSize / zoom) - : item.Value.Settings.FontSize; + var zoom = GetCameraZoom(camera, item.Value.Position); + + style.fontSize = Mathf.FloorToInt(Mathf.Lerp(item.Value.Settings.FontSize, item.Value.Settings.FontSize / zoom, item.Value.Settings.WorldSpaceScaleFactor)); style.alignment = item.Value.Settings.TextAnchor; if (!(WorldToGUIPointWithDepth(camera, item.Value.Position).z < 0f)) { Rect rect = WorldPointToSizedRect(camera, item.Value.Position, _labelDummy, _labelStyle); - //if (x) Debug.Log(rect); - - - ////GUI.DrawTexture(rect, EditorGUIUtility.whiteTexture); - //Rect screenRect = default; - //Rect originRect = default; - //CalculateScaledTextureRects(rect, ScaleMode.StretchToFill, ref screenRect, ref originRect); - - - GL.PushMatrix(); - GL.LoadPixelMatrix(0, Screen.width, Screen.height, 0); - - //Graphics.DrawTexture(screenRect, EditorGUIUtility.whiteTexture, screenRect, 0, 0, 0, 0); - - Color c = item.Value.Settings.BackgroundColor * GlobalColor; - GUI.color = c; - GUI.DrawTexture(rect, EditorGUIUtility.whiteTexture); - - //Graphics.DrawTexture(screenRect, EditorGUIUtility.whiteTexture, screenRect, 0, 0, 0, 0); - //Graphics.DrawTexture(screenRect, EditorGUIUtility.whiteTexture, screenRect, 0, 0, 0, 0); - + Color backgroundColor = item.Value.Settings.BackgroundColor * GlobalColor; + Graphics.DrawTexture(rect, _whiteTexture, new Rect(0, 0, 1, 1), 0, 0, 0, 0, backgroundColor, backgroundMaterial, -1); GUI.color = item.Color * GlobalColor; style.Draw(rect, _labelDummy, false, false, false, false); - - GL.PopMatrix(); } } - Handles.EndGUI(); + GUI.color = dfColor; + backgroundMaterial.SetColor(ColorPropertyID, Color.white); + + if (isSceneView) + { +#if UNITY_EDITOR + Handles.EndGUI(); #endif + } + else + { + GL.PopMatrix(); + } } + #region Init + private void InitStatic() + { + if (_labelStyle == null || _labelDummy == null || _whiteTexture == null) + { + GUIStyleState GenerateGUIStyleState() + { + var result = new GUIStyleState(); + result.textColor = Color.white; + result.background = null; + return result; + } + GUISkin skin = (GUISkin)typeof(GUI).GetField("s_Skin", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static).GetValue(null); //GUI.s_Skin + //GUISkin skin = GUI.skin; + _labelStyle = new GUIStyle(skin.label) + { + richText = false, + padding = new RectOffset(1, 1, 0, 0), + margin = new RectOffset(0, 0, 0, 0), + normal = GenerateGUIStyleState(), + active = GenerateGUIStyleState(), + hover = GenerateGUIStyleState(), + focused = GenerateGUIStyleState(), + }; + + _labelDummy = new GUIContent(); + + _whiteTexture = new Texture2D(2, 2); + Color32[] color = new Color32[] + { + Color.white, + Color.white, + Color.white, + Color.white, + }; + _whiteTexture.SetPixels32(color); + _whiteTexture.Apply(); + } + } + #endregion #region Utils public static Vector3 WorldToGUIPointWithDepth(Camera camera, Vector3 world) { #if UNITY_EDITOR world = Handles.matrix.MultiplyPoint(world); +#endif Vector3 vector = camera.WorldToScreenPoint(world); vector.y = camera.pixelHeight - vector.y; - Vector2 vector2 = EditorGUIUtility.PixelsToPoints(vector); - return new Vector3(vector2.x, vector2.y, vector.z); + Vector2 vector2 = (Vector2)(vector); +#if UNITY_EDITOR + vector2 = EditorGUIUtility.PixelsToPoints(vector); #endif + return new Vector3(vector2.x, vector2.y, vector.z); } public static Rect WorldPointToSizedRect(Camera camera, Vector3 position, GUIContent content, GUIStyle style) { -#if UNITY_EDITOR Vector2 vector = (Vector2)WorldToGUIPointWithDepth(camera, position); Vector2 vector2 = style.CalcSize(content); Rect rect = new Rect(vector.x, vector.y, vector2.x, vector2.y); @@ -152,88 +192,27 @@ namespace DCFApixels rect.y -= rect.height; break; } - return style.padding.Add(rect); -#endif } - //internal static bool CalculateScaledTextureRects(Rect position, ScaleMode scaleMode, float imageAspect, ref Rect outScreenRect, ref Rect outSourceRect) - internal static bool CalculateScaledTextureRects(Rect position, ScaleMode scaleMode, ref Rect outScreenRect, ref Rect outSourceRect) + private static float GetCameraZoom(Camera camera, Vector3 position) { - const float imageAspect = 1; + position = Handles.matrix.MultiplyPoint(position); + Transform transform = camera.transform; + Vector3 position2 = transform.position; + float z = Vector3.Dot(position - position2, transform.TransformDirection(new Vector3(0f, 0f, 1f))); + Vector3 vector = camera.WorldToScreenPoint(position2 + transform.TransformDirection(new Vector3(0f, 0f, z))); + Vector3 vector2 = camera.WorldToScreenPoint(position2 + transform.TransformDirection(new Vector3(1f, 0f, z))); + float magnitude = (vector - vector2).magnitude; + return 80f / Mathf.Max(magnitude, 0.0001f) * EditorGUIUtility.pixelsPerPoint; - float num = position.width / position.height; - bool result = false; - switch (scaleMode) - { - case ScaleMode.StretchToFill: - outScreenRect = position; - outSourceRect = new Rect(0f, 0f, 1f, 1f); - result = true; - break; - case ScaleMode.ScaleAndCrop: - if (num > imageAspect) - { - float num4 = imageAspect / num; - outScreenRect = position; - outSourceRect = new Rect(0f, (1f - num4) * 0.5f, 1f, num4); - result = true; - } - else - { - float num5 = num / imageAspect; - outScreenRect = position; - outSourceRect = new Rect(0.5f - num5 * 0.5f, 0f, num5, 1f); - result = true; - } - - break; - case ScaleMode.ScaleToFit: - if (num > imageAspect) - { - float num2 = imageAspect / num; - outScreenRect = new Rect(position.xMin + position.width * (1f - num2) * 0.5f, position.yMin, num2 * position.width, position.height); - outSourceRect = new Rect(0f, 0f, 1f, 1f); - result = true; - } - else - { - float num3 = num / imageAspect; - outScreenRect = new Rect(position.xMin, position.yMin + position.height * (1f - num3) * 0.5f, position.width, num3 * position.height); - outSourceRect = new Rect(0f, 0f, 1f, 1f); - result = true; - } - - break; - } - - return result; - } - #endregion - - - private void InitStatic() - { - if (_labelStyle == null || _labelDummy == null) - { - _labelStyle = new GUIStyle(GUI.skin.label) - { - richText = false, - padding = new RectOffset(0, 0, 0, 0), - margin = new RectOffset(0, 0, 0, 0) - }; - _labelDummy = new GUIContent(); - } - } - private static float GetCameraZoom(Camera camera) - { - const float DEFAULT_ZOOM = 1f; - - if (camera != null) - { - return camera.orthographicSize; - } - return DEFAULT_ZOOM; + //const float DEFAULT_ZOOM = 1f; + // + //if (camera != null) + //{ + // return camera.orthographicSize; + //} + //return DEFAULT_ZOOM; //var currentDrawingSceneView = SceneView.currentDrawingSceneView; // @@ -251,6 +230,7 @@ namespace DCFApixels // //return DEFAULT_ZOOM; } + #endregion } #endregion } diff --git a/Runtime/Internal/CommandBufferExecutors.cs b/Runtime/Internal/CommandBufferExecutors.cs index af78f59..506d42f 100644 --- a/Runtime/Internal/CommandBufferExecutors.cs +++ b/Runtime/Internal/CommandBufferExecutors.cs @@ -7,6 +7,7 @@ namespace DCFApixels.DebugXCore.Internal internal interface ICommandBufferExecutor { void Execute(CommandBuffer cb); + void Submit(); } internal class CommandBufferExecutorSRP : ICommandBufferExecutor { @@ -24,6 +25,10 @@ namespace DCFApixels.DebugXCore.Internal { RenderContext.ExecuteCommandBuffer(cb); } + public void Submit() + { + RenderContext.Submit(); + } } internal class CommandBufferExecutorBRP : ICommandBufferExecutor { @@ -39,5 +44,6 @@ namespace DCFApixels.DebugXCore.Internal { Graphics.ExecuteCommandBuffer(cb); } + public void Submit() { } } } \ No newline at end of file diff --git a/Runtime/Materials/TextBackground.mat b/Runtime/Materials/TextBackground.mat new file mode 100644 index 0000000..88444a5 --- /dev/null +++ b/Runtime/Materials/TextBackground.mat @@ -0,0 +1,135 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!21 &2100000 +Material: + serializedVersion: 8 + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: TextBackground + m_Shader: {fileID: 4800000, guid: 1af3913ae49e790418a8d901f8982caf, type: 3} + m_Parent: {fileID: 0} + m_ModifiedSerializedProperties: 0 + m_ValidKeywords: [] + m_InvalidKeywords: [] + m_LightmapFlags: 4 + m_EnableInstancingVariants: 0 + m_DoubleSidedGI: 0 + m_CustomRenderQueue: -1 + stringTagMap: {} + disabledShaderPasses: + - MOTIONVECTORS + m_LockedProperties: + m_SavedProperties: + serializedVersion: 3 + m_TexEnvs: + - _BaseMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _BumpMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _DetailAlbedoMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _DetailMask: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _DetailNormalMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _EmissionMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _MainTex: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _MetallicGlossMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _OcclusionMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _ParallaxMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _SpecGlossMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - unity_Lightmaps: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - unity_LightmapsInd: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - unity_ShadowMasks: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + m_Ints: [] + m_Floats: + - _AddPrecomputedVelocity: 0 + - _AlphaClip: 0 + - _AlphaToMask: 0 + - _Blend: 0 + - _BlendModePreserveSpecular: 1 + - _BumpScale: 1 + - _ClearCoatMask: 0 + - _ClearCoatSmoothness: 0 + - _Cull: 2 + - _Cutoff: 0.5 + - _DetailAlbedoMapScale: 1 + - _DetailNormalMapScale: 1 + - _DstBlend: 0 + - _DstBlendAlpha: 0 + - _EnvironmentReflections: 1 + - _GlossMapScale: 0 + - _Glossiness: 0 + - _GlossyReflections: 0 + - _Metallic: 0 + - _OcclusionStrength: 1 + - _Parallax: 0.005 + - _QueueOffset: 0 + - _ReceiveShadows: 1 + - _Smoothness: 0.5 + - _SmoothnessTextureChannel: 0 + - _SpecularHighlights: 1 + - _SrcBlend: 1 + - _SrcBlendAlpha: 1 + - _Surface: 0 + - _WorkflowMode: 1 + - _ZWrite: 1 + m_Colors: + - _BaseColor: {r: 1, g: 1, b: 1, a: 1} + - _Color: {r: 1, g: 1, b: 1, a: 1} + - _EmissionColor: {r: 0, g: 0, b: 0, a: 1} + - _SpecColor: {r: 0.19999996, g: 0.19999996, b: 0.19999996, a: 1} + m_BuildTextureStacks: [] + m_AllowLocking: 1 +--- !u!114 &1974214919826471110 +MonoBehaviour: + m_ObjectHideFlags: 11 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: d0353a89b1f911e48b9e16bdc9f2e058, type: 3} + m_Name: + m_EditorClassIdentifier: + version: 9 diff --git a/Runtime/Materials/TextBackground.mat.meta b/Runtime/Materials/TextBackground.mat.meta new file mode 100644 index 0000000..98922e1 --- /dev/null +++ b/Runtime/Materials/TextBackground.mat.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 75409b93d220f694aa75eee6f4bfd840 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 2100000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Resources/DCFApixels.DebugX/MaterialsList.prefab b/Runtime/Resources/DCFApixels.DebugX/MaterialsList.prefab index 71cb551..624affb 100644 --- a/Runtime/Resources/DCFApixels.DebugX/MaterialsList.prefab +++ b/Runtime/Resources/DCFApixels.DebugX/MaterialsList.prefab @@ -86,6 +86,92 @@ MeshRenderer: m_SortingLayer: 0 m_SortingOrder: 0 m_AdditionalVertexStreams: {fileID: 0} +--- !u!1 &549390746132496352 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 7483746332942052062} + - component: {fileID: 6763744428275037148} + - component: {fileID: 387838602774759695} + m_Layer: 0 + m_Name: TextBackground + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &7483746332942052062 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 549390746132496352} + serializedVersion: 2 + m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} + m_LocalPosition: {x: 12.5, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 2844384060761577604} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!33 &6763744428275037148 +MeshFilter: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 549390746132496352} + m_Mesh: {fileID: 4300000, guid: 873de0939b7f76947a258a8897199a8e, type: 2} +--- !u!23 &387838602774759695 +MeshRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 549390746132496352} + m_Enabled: 1 + m_CastShadows: 1 + m_ReceiveShadows: 1 + m_DynamicOccludee: 1 + m_StaticShadowCaster: 0 + m_MotionVectors: 1 + m_LightProbeUsage: 1 + m_ReflectionProbeUsage: 1 + m_RayTracingMode: 2 + m_RayTraceProcedural: 0 + m_RayTracingAccelStructBuildFlagsOverride: 0 + m_RayTracingAccelStructBuildFlags: 1 + m_SmallMeshCulling: 1 + m_RenderingLayerMask: 1 + m_RendererPriority: 0 + m_Materials: + - {fileID: 2100000, guid: 75409b93d220f694aa75eee6f4bfd840, type: 2} + m_StaticBatchInfo: + firstSubMesh: 0 + subMeshCount: 0 + m_StaticBatchRoot: {fileID: 0} + m_ProbeAnchor: {fileID: 0} + m_LightProbeVolumeOverride: {fileID: 0} + m_ScaleInLightmap: 1 + m_ReceiveGI: 1 + m_PreserveUVs: 0 + m_IgnoreNormalsForChartDetection: 0 + m_ImportantGI: 0 + m_StitchLightmapSeams: 1 + m_SelectedEditorRenderState: 3 + m_MinimumChartSize: 4 + m_AutoUVMaxDistance: 0.5 + m_AutoUVMaxAngle: 89 + m_LightmapParameters: {fileID: 0} + m_SortingLayerID: 0 + m_SortingLayer: 0 + m_SortingOrder: 0 + m_AdditionalVertexStreams: {fileID: 0} --- !u!1 &1299980064020930364 GameObject: m_ObjectHideFlags: 0 @@ -292,6 +378,7 @@ Transform: - {fileID: 2770005348449356163} - {fileID: 5119875421667202613} - {fileID: 1046323005297189095} + - {fileID: 7483746332942052062} m_Father: {fileID: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &6563773915565914195 diff --git a/Runtime/Shaders/TextBackground.shader b/Runtime/Shaders/TextBackground.shader new file mode 100644 index 0000000..c1ca2f1 --- /dev/null +++ b/Runtime/Shaders/TextBackground.shader @@ -0,0 +1,49 @@ +Shader "DCFApixels/DebugX/TextBackground" +{ + SubShader + { + Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" "PreviewType"="Plane" } + Blend SrcAlpha OneMinusSrcAlpha + ZWrite Off Fog { Mode Off } + Lighting Off + ZTest Off + + Pass + { + CGPROGRAM + + #pragma vertex vert + #pragma fragment frag + #pragma multi_compile_instancing + #include "UnityCG.cginc" + + struct appdata_t + { + float4 vertex : POSITION; + float4 color : COLOR; + }; + + struct v2f + { + float4 vertex : SV_POSITION; + float4 color : COLOR; + }; + + float4 _DebugX_GlobalColor; + + v2f vert (appdata_t v) + { + v2f o; + o.vertex = UnityObjectToClipPos(v.vertex); + o.color = v.color * _DebugX_GlobalColor; + return o; + } + + float4 frag (v2f i) : SV_Target + { + return i.color; + } + ENDCG + } + } +} \ No newline at end of file diff --git a/Runtime/Shaders/TextBackground.shader.meta b/Runtime/Shaders/TextBackground.shader.meta new file mode 100644 index 0000000..b8042f8 --- /dev/null +++ b/Runtime/Shaders/TextBackground.shader.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 1af3913ae49e790418a8d901f8982caf +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Utils/DebugXAssets.cs b/Runtime/Utils/DebugXAssets.cs index 1a4d4ef..b7f61f5 100644 --- a/Runtime/Utils/DebugXAssets.cs +++ b/Runtime/Utils/DebugXAssets.cs @@ -47,6 +47,8 @@ namespace DCFApixels.DebugXCore public readonly Material Billboard; public readonly Material Dot; public readonly Material Wire; + + internal readonly Material TextBackground; } } } \ No newline at end of file diff --git a/Runtime/Utils/DebugXTextSettings.cs b/Runtime/Utils/DebugXTextSettings.cs index 8bba295..fb5d9f8 100644 --- a/Runtime/Utils/DebugXTextSettings.cs +++ b/Runtime/Utils/DebugXTextSettings.cs @@ -2,40 +2,44 @@ namespace DCFApixels { - public struct DebugXTextSettings + public readonly struct DebugXTextSettings { public const TextAnchor DEFAULT_TEXT_ANCHOR = TextAnchor.MiddleLeft; public const int DEFAULT_FONT_SIZE = 16; - public static readonly DebugXTextSettings Default = new DebugXTextSettings(DEFAULT_FONT_SIZE, DEFAULT_TEXT_ANCHOR, default); + public static readonly DebugXTextSettings Default = new DebugXTextSettings(DEFAULT_FONT_SIZE, DEFAULT_TEXT_ANCHOR, default, 0); + public static readonly DebugXTextSettings WorldSpaceScale = Default.SetWorldSpaceScaleFactor(1f); - public int FontSize; - public TextAnchor TextAnchor; - public Color BackgroundColor; + public readonly int FontSize; + public readonly TextAnchor TextAnchor; + public readonly Color BackgroundColor; + public readonly float WorldSpaceScaleFactor; public bool IsHasBackground { get { return BackgroundColor.a > 0; } } - public DebugXTextSettings(int fontSize, TextAnchor textAnchor, Color backgroundColor) + public DebugXTextSettings(int fontSize, TextAnchor textAnchor, Color backgroundColor, float worldSpaceScaleFactor) { FontSize = fontSize; TextAnchor = textAnchor; BackgroundColor = backgroundColor; + WorldSpaceScaleFactor = worldSpaceScaleFactor; } public DebugXTextSettings SetSize(int fontSize) { - FontSize = fontSize; - return this; + return new DebugXTextSettings(fontSize, TextAnchor, BackgroundColor, WorldSpaceScaleFactor); } public DebugXTextSettings SetAnchor(TextAnchor textAnchor) { - TextAnchor = textAnchor; - return this; + return new DebugXTextSettings(FontSize, textAnchor, BackgroundColor, WorldSpaceScaleFactor); } public DebugXTextSettings SetBackground(Color backgroundColor) { - BackgroundColor = backgroundColor; - return this; + return new DebugXTextSettings(FontSize, TextAnchor, backgroundColor, WorldSpaceScaleFactor); + } + public DebugXTextSettings SetWorldSpaceScaleFactor(float factor) + { + return new DebugXTextSettings(FontSize, TextAnchor, BackgroundColor, factor); } } } \ No newline at end of file diff --git a/Runtime/Utils/DebugXUtility.cs b/Runtime/Utils/DebugXUtility.cs index 57f3d0b..c3f4bca 100644 --- a/Runtime/Utils/DebugXUtility.cs +++ b/Runtime/Utils/DebugXUtility.cs @@ -41,7 +41,7 @@ namespace DCFApixels.DebugXCore field.SetValue(obj, meshFilter.sharedMesh); } else - { + { Debug.LogWarning(field.Name + " not found."); } } diff --git a/Runtime/Utils/IGizmo.cs b/Runtime/Utils/IGizmo.cs index e1073c0..e692740 100644 --- a/Runtime/Utils/IGizmo.cs +++ b/Runtime/Utils/IGizmo.cs @@ -17,9 +17,9 @@ namespace DCFApixels.DebugXCore void Prepare(Camera camera, GizmosList list); void Render(Camera camera, GizmosList list, CommandBuffer cb); } - public interface IGizmoRenderer_UnityGizmos : IGizmoRenderer where T : IGizmo + public interface IGizmoRenderer_PostRender : IGizmoRenderer where T : IGizmo { - void Render_UnityGizmos(Camera camera, GizmosList list); + void PostRender(Camera camera, GizmosList list); } diff --git a/Samples/Other/FakeLightMat.mat b/Samples/Other/FakeLightMat.mat index bc772f3..486aec6 100644 --- a/Samples/Other/FakeLightMat.mat +++ b/Samples/Other/FakeLightMat.mat @@ -54,6 +54,6 @@ Material: - _QueueControl: 0 - _QueueOffset: 0 m_Colors: - - _Color: {r: 0, g: 0.071999975, b: 0.09, a: 1} + - _Color: {r: 0, g: 0.08608696, b: 0.11, a: 1} m_BuildTextureStacks: [] m_AllowLocking: 1 diff --git a/Samples/Other/Ground.mat b/Samples/Other/Ground.mat index a397a41..1f5774b 100644 --- a/Samples/Other/Ground.mat +++ b/Samples/Other/Ground.mat @@ -135,14 +135,14 @@ Material: - _GlossinessSource: 0 - _GlossyReflections: 1 - _LightingEnabled: 1 - - _Metallic: 0 + - _Metallic: 0.046 - _Mode: 0 - _OcclusionStrength: 1 - _Parallax: 0.02 - _QueueOffset: 0 - _ReceiveShadows: 0 - _Shininess: 0 - - _Smoothness: 0 + - _Smoothness: 0.047 - _SmoothnessSource: 0 - _SmoothnessTextureChannel: 0 - _SoftParticlesEnabled: 0 diff --git a/Samples/Sample.unity b/Samples/Sample.unity index 3bfdc5a..608f33e 100644 --- a/Samples/Sample.unity +++ b/Samples/Sample.unity @@ -1229,7 +1229,7 @@ Camera: m_ShutterSpeed: 0.005 m_Aperture: 16 m_FocusDistance: 10 - m_FocalLength: 50 + m_FocalLength: 20.78461 m_BladeCount: 5 m_Curvature: {x: 2, y: 11} m_BarrelClipping: 0.25 @@ -1244,7 +1244,7 @@ Camera: height: 1 near clip plane: 0.3 far clip plane: 1000 - field of view: 60 + field of view: 60.000004 orthographic: 0 orthographic size: 5 m_Depth: -1 @@ -1277,7 +1277,7 @@ Transform: m_Children: - {fileID: 1800693605} m_Father: {fileID: 0} - m_LocalEulerAnglesHint: {x: 60, y: 0, z: 0} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!114 &298618463 MonoBehaviour: m_ObjectHideFlags: 0 @@ -4135,7 +4135,7 @@ GameObject: m_Component: - component: {fileID: 1482731616} m_Layer: 0 - m_Name: Hello World Hello World Hello World + m_Name: Hello World m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 diff --git a/Samples/Scripts/DebugXSample_Other.cs b/Samples/Scripts/DebugXSample_Other.cs index 71c06a1..d92b640 100644 --- a/Samples/Scripts/DebugXSample_Other.cs +++ b/Samples/Scripts/DebugXSample_Other.cs @@ -8,7 +8,6 @@ namespace DCFApixels.DebugXCore.Samples public Gradient Gradient; public float GradientMultiplier = 5; public Transform[] Points; - private static readonly Color _background = new Color(0, 0, 0, 0.5f); #if UNITY_EDITOR private void OnDrawGizmos() @@ -29,7 +28,9 @@ namespace DCFApixels.DebugXCore.Samples i++; DebugX.Draw(GetColor(Points[i])).Cross(Points[i].position, Points[i].localScale.x); i++; DebugX.Draw(GetColor(Points[i])).BillboardCircle(Points[i].position, Points[i].localScale.x * RADIUS_M); i++; DebugX.Draw(GetColor(Points[i])).WireMesh(Points[i].position, Points[i].rotation, Points[i].localScale * RADIUS_M); - i++; DebugX.Draw(GetColor(Points[i])).Text(Points[i].position, Points[i].name, DebugXTextSettings.Default.SetBackground(Color.black)); + Color backgroundColor = Color.white - GetColor(Points[i]); + backgroundColor.a = 0.5f; + i++; DebugX.Draw(GetColor(Points[i])).Text(Points[i].position, Points[i].name, DebugXTextSettings.WorldSpaceScale.SetSize(26).SetBackground(backgroundColor)); i++; DebugX.Draw(GetColor(Points[i])).Dot(Points[i].position); i++; DebugX.Draw(GetColor(Points[i])).WireDot(Points[i].position);