From 9e966edb31bd31fe9ff9cf249028245376583a75 Mon Sep 17 00:00:00 2001 From: DCFApixels <99481254+DCFApixels@users.noreply.github.com> Date: Mon, 21 Apr 2025 20:26:42 +0800 Subject: [PATCH] update sample --- Samples/Sample.unity | 66 ++++++++++++++++++++++ Samples/Scripts/DebugXSample_Raycasts2D.cs | 13 ++++- Samples/Scripts/DebugXSample_Raycasts3D.cs | 15 ++++- 3 files changed, 89 insertions(+), 5 deletions(-) diff --git a/Samples/Sample.unity b/Samples/Sample.unity index 47bd2fa..483134e 100644 --- a/Samples/Sample.unity +++ b/Samples/Sample.unity @@ -875,6 +875,37 @@ Transform: m_Children: [] m_Father: {fileID: 2137543453} m_LocalEulerAnglesHint: {x: 45, y: 0, z: 0} +--- !u!1 &223293503 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 223293504} + m_Layer: 0 + m_Name: Warrning + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &223293504 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 223293503} + serializedVersion: 2 + m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: -1.82} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 241950277} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &227658960 GameObject: m_ObjectHideFlags: 0 @@ -975,6 +1006,7 @@ Transform: - {fileID: 629058557} - {fileID: 1190527457} - {fileID: 607411204} + - {fileID: 1275004640} m_Father: {fileID: 2070085917} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &239565651 @@ -1096,6 +1128,7 @@ Transform: - {fileID: 1968074010} - {fileID: 1230489027} - {fileID: 82819859} + - {fileID: 223293504} m_Father: {fileID: 700624119} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &290054995 @@ -2506,6 +2539,7 @@ MonoBehaviour: - {fileID: 1968074010} - {fileID: 1230489027} - {fileID: 82819859} + WarrningPoint: {fileID: 223293504} --- !u!4 &700624119 Transform: m_ObjectHideFlags: 0 @@ -3650,6 +3684,37 @@ Transform: m_Children: [] m_Father: {fileID: 162132448} m_LocalEulerAnglesHint: {x: 45, y: 0, z: 0} +--- !u!1 &1275004639 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1275004640} + m_Layer: 0 + m_Name: Warrning + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &1275004640 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1275004639} + serializedVersion: 2 + m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} + m_LocalPosition: {x: 0, y: 0.58000004, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 234433271} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &1302158462 GameObject: m_ObjectHideFlags: 0 @@ -5727,6 +5792,7 @@ MonoBehaviour: - {fileID: 629058557} - {fileID: 1190527457} - {fileID: 607411204} + WarrningPoint: {fileID: 1275004640} --- !u!4 &2070085917 Transform: m_ObjectHideFlags: 0 diff --git a/Samples/Scripts/DebugXSample_Raycasts2D.cs b/Samples/Scripts/DebugXSample_Raycasts2D.cs index 3e17740..25dcfb6 100644 --- a/Samples/Scripts/DebugXSample_Raycasts2D.cs +++ b/Samples/Scripts/DebugXSample_Raycasts2D.cs @@ -8,6 +8,8 @@ namespace DCFApixels.DebugXCore.Samples public Gradient Gradient; public float GradientMultiplier = 5; public Transform[] Points; + public Transform WarrningPoint; + #if UNITY_EDITOR private void OnDrawGizmos() @@ -50,6 +52,8 @@ namespace DCFApixels.DebugXCore.Samples ray = new Ray(point.position, point.forward); hit = Physics2D.CapsuleCast(ray.origin, point.localScale, CapsuleDirection2D.Vertical, point.eulerAngles.z, ray.direction, float.PositiveInfinity, int.MaxValue); DebugX.Draw(GetColor(point)).CapsuleCast2D(ray, point.eulerAngles.z, point.localScale, CapsuleDirection2D.Vertical, hit); +#else + DebugX.Draw(Inverse(GetColor(WarrningPoint))).Text(WarrningPoint.position, "Add \"DEBUGX_ENABLE_PHYSICS2D\" define", DebugXTextSettings.WorldSpaceScale.SetSize(22).SetAnchor(TextAnchor.MiddleCenter)); #endif } private Color GetColor(Transform pos1) @@ -57,11 +61,16 @@ namespace DCFApixels.DebugXCore.Samples Vector3 pos = pos1.localPosition; pos /= GradientMultiplier == 0 ? 1 : GradientMultiplier; pos += Vector3.one * 0.5f; - //float t = pos.x + pos.y + pos.z; - //t /= 3f; float t = pos.x + pos.z; t /= 2f; return Gradient.Evaluate(Mathf.Clamp01(t)); } + private Color Inverse(Color c) + { + var a = c.a; + c = Color.white - c; + c.a = a; + return c; + } } } diff --git a/Samples/Scripts/DebugXSample_Raycasts3D.cs b/Samples/Scripts/DebugXSample_Raycasts3D.cs index f026b3f..112cbda 100644 --- a/Samples/Scripts/DebugXSample_Raycasts3D.cs +++ b/Samples/Scripts/DebugXSample_Raycasts3D.cs @@ -8,7 +8,7 @@ namespace DCFApixels.DebugXCore.Samples public Gradient Gradient; public float GradientMultiplier = 5; public Transform[] Points; - + public Transform WarrningPoint; #if UNITY_EDITOR @@ -54,6 +54,8 @@ namespace DCFApixels.DebugXCore.Samples Vector3 point2 = ray.origin + point.up * point.localScale.y * RADIUS_M * -0.5f; Physics.CapsuleCast(point1, point2, point.localScale.x * RADIUS_M, ray.direction, out hit, float.PositiveInfinity, int.MaxValue, QueryTriggerInteraction.UseGlobal); DebugX.Draw(GetColor(point)).CapsuleCast(point1, point2, ray.direction, point.localScale.x * RADIUS_M, hit); +#else + DebugX.Draw(Inverse(GetColor(WarrningPoint))).Text(WarrningPoint.position, "Add \"DEBUGX_ENABLE_PHYSICS3D\" define", DebugXTextSettings.WorldSpaceScale.SetSize(22).SetAnchor(TextAnchor.MiddleCenter)); #endif } private Color GetColor(Transform pos1) @@ -61,9 +63,16 @@ namespace DCFApixels.DebugXCore.Samples Vector3 pos = pos1.localPosition; pos /= GradientMultiplier == 0 ? 1 : GradientMultiplier; pos += Vector3.one * 0.5f; - float t = pos.x + pos.y + pos.z; - t /= 3f; + float t = pos.x + pos.z; + t /= 2f; return Gradient.Evaluate(Mathf.Clamp01(t)); } + private Color Inverse(Color c) + { + var a = c.a; + c = Color.white - c; + c.a = a; + return c; + } } }