mirror of
https://github.com/DCFApixels/Unity-DebugX.git
synced 2025-09-18 01:54:37 +08:00
Compare commits
7 Commits
a7b06f5af7
...
c6e1acc697
Author | SHA1 | Date | |
---|---|---|---|
![]() |
c6e1acc697 | ||
![]() |
587500061e | ||
![]() |
e3341988b0 | ||
![]() |
964ba7e3df | ||
![]() |
fe5142dbdc | ||
![]() |
809a04c8fb | ||
![]() |
60b2e0ea21 |
@ -27,9 +27,11 @@ namespace DCFApixels.DebugXCore.Internal
|
||||
//private bool? _isHasDisableDebugXInBuildSymbols = false;
|
||||
//private const string DEFINE_NAME = nameof(DebugXDefines.DEBUGX_DISABLE_INBUILD);
|
||||
private static (string name, bool flag)[] _defines = null;
|
||||
private static Vector2 _pos;
|
||||
|
||||
private void OnGUI()
|
||||
{
|
||||
|
||||
_pos = GUILayout.BeginScrollView(_pos, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true));
|
||||
float tmpValue;
|
||||
|
||||
DebugX.GlobalTimeScale = EditorGUILayout.FloatField("TimeScale", DebugX.GlobalTimeScale);
|
||||
@ -53,6 +55,23 @@ namespace DCFApixels.DebugXCore.Internal
|
||||
color.a = EditorGUILayout.Slider(DebugX.GlobalColor.a, 0, 1);
|
||||
DebugX.GlobalColor = color;
|
||||
|
||||
if (GUILayout.Button("Reset"))
|
||||
{
|
||||
DebugX.ResetGlobals();
|
||||
}
|
||||
if (GUILayout.Button("Clear All Gizmos"))
|
||||
{
|
||||
DebugX.ClearAllGizmos();
|
||||
}
|
||||
|
||||
GUILayout.Space(4);
|
||||
|
||||
GUILayout.BeginVertical(EditorStyles.helpBox);
|
||||
GUILayout.Label("Information", EditorStyles.helpBox);
|
||||
DrawReadonlyLeftToggle("Is SRP", DebugXConsts.IsSRP);
|
||||
DrawReadonlyLeftToggle("Support GPU Instancing", DebugXConsts.IsSupportsComputeShaders);
|
||||
DrawReadonlyLeftToggle("Support OnGizmosDraw methods", DebugXConsts.IsSRP);
|
||||
GUILayout.EndVertical();
|
||||
|
||||
GUILayout.BeginVertical(EditorStyles.helpBox);
|
||||
GUILayout.Label("Scripting Define Symbols", EditorStyles.helpBox);
|
||||
@ -71,72 +90,18 @@ namespace DCFApixels.DebugXCore.Internal
|
||||
}
|
||||
GUILayout.EndVertical();
|
||||
|
||||
// if (_isCompilation == false)
|
||||
// {
|
||||
// if (_isHasDisableDebugXInBuildSymbols == null)
|
||||
// {
|
||||
// BuildTargetGroup group = EditorUserBuildSettings.selectedBuildTargetGroup;
|
||||
//#if UNITY_6000_0_OR_NEWER
|
||||
// string symbolsString = PlayerSettings.GetScriptingDefineSymbols(NamedBuildTarget.FromBuildTargetGroup(group));
|
||||
//#else
|
||||
// string symbolsString = PlayerSettings.GetScriptingDefineSymbolsForGroup(group);
|
||||
//#endif
|
||||
// _isHasDisableDebugXInBuildSymbols = symbolsString.Contains(DEFINE_NAME);
|
||||
// }
|
||||
//
|
||||
// EditorGUI.BeginChangeCheck();
|
||||
// _isHasDisableDebugXInBuildSymbols = !EditorGUILayout.ToggleLeft("Show Gizmos in Build", !_isHasDisableDebugXInBuildSymbols.Value);
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
// if (EditorGUI.EndChangeCheck())
|
||||
// {
|
||||
// BuildTargetGroup group = EditorUserBuildSettings.selectedBuildTargetGroup;
|
||||
//#if UNITY_6000_0_OR_NEWER
|
||||
// string symbolsString = PlayerSettings.GetScriptingDefineSymbols(NamedBuildTarget.FromBuildTargetGroup(group));
|
||||
//#else
|
||||
// string symbolsString = PlayerSettings.GetScriptingDefineSymbolsForGroup(group);
|
||||
//#endif
|
||||
// if (symbolsString.Contains(DEFINE_NAME) == false)
|
||||
// {
|
||||
// symbolsString = symbolsString + ", " + DEFINE_NAME;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// symbolsString = symbolsString.Replace(DEFINE_NAME, "");
|
||||
//
|
||||
// }
|
||||
//
|
||||
//#if UNITY_6000_0_OR_NEWER
|
||||
// PlayerSettings.SetScriptingDefineSymbols(NamedBuildTarget.FromBuildTargetGroup(group), symbolsString);
|
||||
//#else
|
||||
// PlayerSettings.SetScriptingDefineSymbolsForGroup(group, symbolsString);
|
||||
//#endif
|
||||
// _isCompilation = true;
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// _isHasDisableDebugXInBuildSymbols = null;
|
||||
// GUI.enabled = false;
|
||||
// EditorGUILayout.ToggleLeft("Show Gizmos in Build (Locked for compilation)", false);
|
||||
// GUI.enabled = true;
|
||||
// }
|
||||
GUILayout.EndScrollView();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
if (GUILayout.Button("Reset"))
|
||||
{
|
||||
DebugX.ResetGlobals();
|
||||
}
|
||||
|
||||
if (GUILayout.Button("Clear All Gizmos"))
|
||||
{
|
||||
DebugX.ClearAllGizmos();
|
||||
}
|
||||
private void DrawReadonlyLeftToggle(string text, bool value)
|
||||
{
|
||||
GUILayout.BeginHorizontal();
|
||||
bool GUI_enabled_default = GUI.enabled;
|
||||
GUI.enabled = false;
|
||||
EditorGUILayout.Toggle(value, GUILayout.Width(14), GUILayout.ExpandWidth(false));
|
||||
GUI.enabled = GUI_enabled_default;
|
||||
EditorGUILayout.LabelField(text, GUILayout.ExpandWidth(true));
|
||||
GUILayout.EndHorizontal();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ using UnityEngine.Rendering;
|
||||
|
||||
namespace DCFApixels
|
||||
{
|
||||
//TODO для разработки аналога Handlers.DrawWireArc можно посмотреть в сторону того чтобы на уровне шейдера делать пиксели прозрачными
|
||||
public static class DebugXConsts
|
||||
{
|
||||
public const float IMMEDIATE_DURATION = -1;
|
||||
|
@ -198,10 +198,18 @@ namespace DCFApixels
|
||||
{
|
||||
return new DrawHandler(GetCurrentDefaultDuration(), color);
|
||||
}
|
||||
public static DrawHandler Draw((Color color, float alphaMultiplier) color)
|
||||
{
|
||||
return new DrawHandler(GetCurrentDefaultDuration(), color.ToColor());
|
||||
}
|
||||
public static DrawHandler Draw(float duration, Color color)
|
||||
{
|
||||
return new DrawHandler(duration, color);
|
||||
}
|
||||
public static DrawHandler Draw(float duration, (Color color, float alphaMultiplier) color)
|
||||
{
|
||||
return new DrawHandler(duration, color.ToColor());
|
||||
}
|
||||
//public static DrawHandler Draw(float r, float g, float b, float a = 1f) //TODO
|
||||
|
||||
public readonly partial struct DrawHandler
|
||||
@ -221,8 +229,10 @@ namespace DCFApixels
|
||||
//ContextController = GetCurrenRenderContextController();
|
||||
}
|
||||
[IN(LINE)] public DrawHandler Setup(float duration, Color color) => new DrawHandler(duration, color);
|
||||
[IN(LINE)] public DrawHandler Setup(float duration, (Color color, float alphaMultiplier) color) => new DrawHandler(duration, color.ToColor());
|
||||
[IN(LINE)] public DrawHandler Setup(float duration) => new DrawHandler(duration, Color);
|
||||
[IN(LINE)] public DrawHandler Setup(Color color) => new DrawHandler(Duration, color);
|
||||
[IN(LINE)] public DrawHandler Setup((Color color, float alphaMultiplier) color) => new DrawHandler(Duration, color.ToColor());
|
||||
//[IN(LINE)]
|
||||
//private DrawHandler(float time, Color color, RenderContextController contextController)
|
||||
//{
|
||||
|
@ -43,7 +43,7 @@ namespace DCFApixels
|
||||
//}
|
||||
#endregion
|
||||
|
||||
#region Mesh //TODO потестить
|
||||
#region Mesh
|
||||
[IN(LINE)]
|
||||
public DrawHandler Mesh<TMat>(Mesh mesh, Vector3 position, Quaternion rotation, Vector3 size)
|
||||
where TMat : struct, IStaticMaterial
|
||||
|
@ -12,16 +12,40 @@ namespace DCFApixels
|
||||
public readonly partial struct DrawHandler
|
||||
{
|
||||
#region BillboardCircle
|
||||
[IN(LINE)] public DrawHandler BillboardCircle(Vector3 position, float radius) => Mesh<CircleMesh, BillboardMat>(position, Quaternion.identity, new Vector3(radius, radius, radius));
|
||||
[IN(LINE)]
|
||||
public DrawHandler BillboardCircle(Vector3 position, float radius)
|
||||
{
|
||||
return Mesh<CircleMesh, BillboardMat>(position, Quaternion.identity, new Vector3(radius, radius, radius));
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Cross
|
||||
[IN(LINE)] public DrawHandler Cross(Vector3 position, float size) => Mesh<DotCrossMesh, BillboardMat>(position, Quaternion.identity, new Vector3(size, size, size));
|
||||
#region BillboardCross
|
||||
[IN(LINE)]
|
||||
[Obsolete("Use BillboardCross(position, size)")]
|
||||
public DrawHandler Cross(Vector3 position, float size)
|
||||
{
|
||||
return Mesh<DotCrossMesh, BillboardMat>(position, Quaternion.identity, new Vector3(size, size, size));
|
||||
}
|
||||
[IN(LINE)]
|
||||
public DrawHandler BillboardCross(Vector3 position, float size)
|
||||
{
|
||||
return Mesh<DotCrossMesh, BillboardMat>(position, Quaternion.identity, new Vector3(size, size, size));
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
#region Sphere
|
||||
[IN(LINE)] public DrawHandler Sphere(Vector3 position, float radius) => Mesh<SphereMesh, LitMat>(position, Quaternion.identity, new Vector3(radius, radius, radius));
|
||||
[IN(LINE)]
|
||||
public DrawHandler Sphere<TMat>(Vector3 position, float radius)
|
||||
where TMat : struct, IStaticMaterial
|
||||
{
|
||||
return Mesh<SphereMesh, TMat>(position, Quaternion.identity, new Vector3(radius, radius, radius));
|
||||
}
|
||||
[IN(LINE)]
|
||||
public DrawHandler Sphere(Vector3 position, float radius)
|
||||
{
|
||||
return Mesh<SphereMesh>(position, Quaternion.identity, new Vector3(radius, radius, radius));
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region WireSphere
|
||||
@ -107,9 +131,30 @@ namespace DCFApixels
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
#region Circle
|
||||
[IN(LINE)] public DrawHandler Circle(Vector3 position, Vector3 normal, float radius) => Mesh<CircleMesh, LitMat>(position, Quaternion.LookRotation(normal), new Vector3(radius, radius, radius));
|
||||
[IN(LINE)] public DrawHandler Circle(Vector3 position, Quaternion rotation, float radius) => Mesh<CircleMesh, LitMat>(position, rotation, new Vector3(radius, radius, radius));
|
||||
[IN(LINE)]
|
||||
public DrawHandler Circle<TMat>(Vector3 position, Vector3 normal, float radius)
|
||||
where TMat : struct, IStaticMaterial
|
||||
{
|
||||
return Mesh<CircleMesh, TMat>(position, Quaternion.LookRotation(normal), new Vector3(radius, radius, radius));
|
||||
}
|
||||
[IN(LINE)]
|
||||
public DrawHandler Circle<TMat>(Vector3 position, Quaternion rotation, float radius)
|
||||
where TMat : struct, IStaticMaterial
|
||||
{
|
||||
return Mesh<CircleMesh, TMat>(position, rotation, new Vector3(radius, radius, radius));
|
||||
}
|
||||
[IN(LINE)]
|
||||
public DrawHandler Circle(Vector3 position, Vector3 normal, float radius)
|
||||
{
|
||||
return Mesh<CircleMesh>(position, Quaternion.LookRotation(normal), new Vector3(radius, radius, radius));
|
||||
}
|
||||
[IN(LINE)]
|
||||
public DrawHandler Circle(Vector3 position, Quaternion rotation, float radius)
|
||||
{
|
||||
return Mesh<CircleMesh>(position, rotation, new Vector3(radius, radius, radius));
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region WireCircle
|
||||
@ -120,10 +165,15 @@ namespace DCFApixels
|
||||
|
||||
#region Cylinder
|
||||
[IN(LINE)]
|
||||
public DrawHandler Cylinder<TMat>(Vector3 position, Quaternion rotation, float radius, float height)
|
||||
where TMat : struct, IStaticMaterial
|
||||
{
|
||||
return Mesh<CylinderMesh, TMat>(position, rotation * Quaternion.Euler(-90, 0, 0), new Vector3(radius * 2f, radius * 2f, height));
|
||||
}
|
||||
[IN(LINE)]
|
||||
public DrawHandler Cylinder(Vector3 position, Quaternion rotation, float radius, float height)
|
||||
{
|
||||
Mesh<CylinderMesh, LitMat>(position, rotation * Quaternion.Euler(-90, 0, 0), new Vector3(radius * 2f, radius * 2f, height));
|
||||
return this;
|
||||
return Mesh<CylinderMesh>(position, rotation * Quaternion.Euler(-90, 0, 0), new Vector3(radius * 2f, radius * 2f, height));
|
||||
}
|
||||
#endregion
|
||||
|
||||
@ -169,12 +219,18 @@ namespace DCFApixels
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
#region Cone
|
||||
[IN(LINE)]
|
||||
public DrawHandler Cone<TMat>(Vector3 position, Quaternion rotation, float radius, float height)
|
||||
where TMat : struct, IStaticMaterial
|
||||
{
|
||||
return Mesh<ConeMesh, TMat>(position, rotation * Quaternion.Euler(-90, 0, 0), new Vector3(radius * 2f, radius * 2f, height));
|
||||
}
|
||||
[IN(LINE)]
|
||||
public DrawHandler Cone(Vector3 position, Quaternion rotation, float radius, float height)
|
||||
{
|
||||
Mesh<ConeMesh, LitMat>(position, rotation * Quaternion.Euler(-90, 0, 0), new Vector3(radius * 2f, radius * 2f, height));
|
||||
return this;
|
||||
return Mesh<ConeMesh>(position, rotation * Quaternion.Euler(-90, 0, 0), new Vector3(radius * 2f, radius * 2f, height));
|
||||
}
|
||||
#endregion
|
||||
|
||||
@ -215,12 +271,18 @@ namespace DCFApixels
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
#region Triangle
|
||||
[IN(LINE)]
|
||||
public DrawHandler Triangle<TMat>(Vector3 position, Quaternion rotation, Vector2 size)
|
||||
where TMat : struct, IStaticMaterial
|
||||
{
|
||||
return Mesh<TriangleMesh, TMat>(position, rotation, new Vector3(size.x, size.y, 1f));
|
||||
}
|
||||
[IN(LINE)]
|
||||
public DrawHandler Triangle(Vector3 position, Quaternion rotation, Vector2 size)
|
||||
{
|
||||
Mesh<TriangleMesh, LitMat>(position, rotation, new Vector3(size.x, size.y, 1f));
|
||||
return this;
|
||||
return Mesh<TriangleMesh>(position, rotation, new Vector3(size.x, size.y, 1f));
|
||||
}
|
||||
#endregion
|
||||
|
||||
@ -236,7 +298,8 @@ namespace DCFApixels
|
||||
|
||||
#region Capsule
|
||||
[IN(LINE)]
|
||||
public DrawHandler Capsule(Vector3 position, Quaternion rotation, float radius, float height)
|
||||
public DrawHandler Capsule<TMat>(Vector3 position, Quaternion rotation, float radius, float height)
|
||||
where TMat : struct, IStaticMaterial
|
||||
{
|
||||
radius = Mathf.Max(0, radius);
|
||||
height -= radius * 2f;
|
||||
@ -244,11 +307,16 @@ namespace DCFApixels
|
||||
var halfHeigth = height * 0.5f;
|
||||
var normal = rotation * Vector3.up;
|
||||
|
||||
Mesh<CapsuleHeadMesh, LitMat>(position + normal * halfHeigth, rotation, new Vector3(radius, radius, radius));
|
||||
Mesh<CapsuleBodyMesh, LitMat>(position, rotation, new Vector3(radius, height, radius));
|
||||
Mesh<CapsuleHeadMesh, LitMat>(position - normal * halfHeigth, rotation * Quaternion.Euler(0, 0, 180), new Vector3(radius, radius, radius));
|
||||
Mesh<CapsuleHeadMesh, TMat>(position + normal * halfHeigth, rotation, new Vector3(radius, radius, radius));
|
||||
Mesh<CapsuleBodyMesh, TMat>(position, rotation, new Vector3(radius, height, radius));
|
||||
Mesh<CapsuleHeadMesh, TMat>(position - normal * halfHeigth, rotation * Quaternion.Euler(0, 0, 180), new Vector3(radius, radius, radius));
|
||||
return this;
|
||||
}
|
||||
[IN(LINE)]
|
||||
public DrawHandler Capsule(Vector3 position, Quaternion rotation, float radius, float height)
|
||||
{
|
||||
return Capsule<LitMat>(position, rotation, radius, height);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region WireCapsule
|
||||
@ -280,9 +348,11 @@ namespace DCFApixels
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
#region FlatCapsule
|
||||
[IN(LINE)]
|
||||
public DrawHandler FlatCapsule(Vector3 position, Quaternion rotation, float radius, float height)
|
||||
public DrawHandler FlatCapsule<TMat>(Vector3 position, Quaternion rotation, float radius, float height)
|
||||
where TMat : struct, IStaticMaterial
|
||||
{
|
||||
radius = Mathf.Max(0, radius);
|
||||
height -= radius * 2f;
|
||||
@ -290,11 +360,16 @@ namespace DCFApixels
|
||||
var halfHeigth = height * 0.5f;
|
||||
var normal = rotation * Vector3.up;
|
||||
|
||||
Mesh<FlatCapsuleHeadMesh, LitMat>(position + normal * halfHeigth, rotation, new Vector3(radius, radius, radius));
|
||||
Mesh<FlatCapsuleBodyMesh, LitMat>(position, rotation, new Vector3(radius, height, radius));
|
||||
Mesh<FlatCapsuleHeadMesh, LitMat>(position - normal * halfHeigth, rotation * Quaternion.Euler(0, 0, 180), new Vector3(radius, radius, radius));
|
||||
Mesh<FlatCapsuleHeadMesh, TMat>(position + normal * halfHeigth, rotation, new Vector3(radius, radius, radius));
|
||||
Mesh<FlatCapsuleBodyMesh, TMat>(position, rotation, new Vector3(radius, height, radius));
|
||||
Mesh<FlatCapsuleHeadMesh, TMat>(position - normal * halfHeigth, rotation * Quaternion.Euler(0, 0, 180), new Vector3(radius, radius, radius));
|
||||
return this;
|
||||
}
|
||||
[IN(LINE)]
|
||||
public DrawHandler FlatCapsule(Vector3 position, Quaternion rotation, float radius, float height)
|
||||
{
|
||||
return FlatCapsule<LitMat>(position, rotation, radius, height);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region WireFlatCapsule
|
||||
@ -336,8 +411,28 @@ namespace DCFApixels
|
||||
#region Cube
|
||||
//[IN(LINE)] public void Cube(Vector3 position, float size) => Cube(position, Quaternion.identity, new Vector3(size, size, size));
|
||||
//[IN(LINE)] public void Cube(Vector3 position, Vector3 size) => Cube(position, Quaternion.identity, size);
|
||||
[IN(LINE)] public DrawHandler Cube(Vector3 position, Quaternion rotation, float size) => Mesh<CubeMesh, LitMat>(position, rotation, new Vector3(size, size, size));
|
||||
[IN(LINE)] public DrawHandler Cube(Vector3 position, Quaternion rotation, Vector3 size) => Mesh<CubeMesh, LitMat>(position, rotation, size);
|
||||
[IN(LINE)]
|
||||
public DrawHandler Cube<TMat>(Vector3 position, Quaternion rotation, float size)
|
||||
where TMat : struct, IStaticMaterial
|
||||
{
|
||||
return Mesh<CubeMesh, TMat>(position, rotation, new Vector3(size, size, size));
|
||||
}
|
||||
[IN(LINE)]
|
||||
public DrawHandler Cube<TMat>(Vector3 position, Quaternion rotation, Vector3 size)
|
||||
where TMat : struct, IStaticMaterial
|
||||
{
|
||||
return Mesh<CubeMesh, TMat>(position, rotation, size);
|
||||
}
|
||||
[IN(LINE)]
|
||||
public DrawHandler Cube(Vector3 position, Quaternion rotation, float size)
|
||||
{
|
||||
return Mesh<CubeMesh>(position, rotation, new Vector3(size, size, size));
|
||||
}
|
||||
[IN(LINE)]
|
||||
public DrawHandler Cube(Vector3 position, Quaternion rotation, Vector3 size)
|
||||
{
|
||||
return Mesh<CubeMesh>(position, rotation, size);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region WireCube
|
||||
@ -458,11 +553,32 @@ namespace DCFApixels
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
#region Quad
|
||||
//[IN(LINE)] public DrawHandler Quad(Vector3 position, Vector3 normal, float size) => Mesh(Meshes.Quad, position, Quaternion.LookRotation(normal), new Vector3(size, size, size));
|
||||
//[IN(LINE)] public DrawHandler Quad(Vector3 position, Vector3 normal, Vector2 size) => Mesh(Meshes.Quad, position, Quaternion.LookRotation(normal), size);
|
||||
[IN(LINE)] public DrawHandler Quad(Vector3 position, Quaternion rotation, float size) => Mesh<QuadMesh, LitMat>(position, rotation, new Vector3(size, size, 1f)); //TODO fix quad mesh
|
||||
[IN(LINE)] public DrawHandler Quad(Vector3 position, Quaternion rotation, Vector2 size) => Mesh<QuadMesh, LitMat>(position, rotation, new Vector3(size.x, size.y, 1f)); //TODO fix quad mesh
|
||||
[IN(LINE)]
|
||||
public DrawHandler Quad<TMat>(Vector3 position, Quaternion rotation, float size)
|
||||
where TMat : struct, IStaticMaterial
|
||||
{
|
||||
return Mesh<QuadMesh, TMat>(position, rotation, new Vector3(size, size, 1f));
|
||||
}
|
||||
[IN(LINE)]
|
||||
public DrawHandler Quad<TMat>(Vector3 position, Quaternion rotation, Vector2 size)
|
||||
where TMat : struct, IStaticMaterial
|
||||
{
|
||||
return Mesh<QuadMesh, TMat>(position, rotation, new Vector3(size.x, size.y, 1f));
|
||||
}
|
||||
[IN(LINE)]
|
||||
public DrawHandler Quad(Vector3 position, Quaternion rotation, float size)
|
||||
{
|
||||
return Mesh<QuadMesh>(position, rotation, new Vector3(size, size, 1f));
|
||||
}
|
||||
[IN(LINE)]
|
||||
public DrawHandler Quad(Vector3 position, Quaternion rotation, Vector2 size)
|
||||
{
|
||||
return Mesh<QuadMesh>(position, rotation, new Vector3(size.x, size.y, 1f));
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region WireQuad
|
||||
|
@ -9,5 +9,10 @@ namespace DCFApixels.DebugXCore.Internal
|
||||
self.a *= v;
|
||||
return self;
|
||||
}
|
||||
public static Color ToColor(ref this (Color color, float alpha) self)
|
||||
{
|
||||
self.color.a *= self.alpha;
|
||||
return self.color;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -31,15 +31,23 @@ Shader "DCFApixels/DebugX/Handles"
|
||||
#pragma instancing_options procedural:setup
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
#include "HandlesLibrary.cginc"
|
||||
|
||||
#if defined(UNITY_PROCEDURAL_INSTANCING_ENABLED)
|
||||
#if defined(UNITY_PROCEDURAL_INSTANCING_ENABLED)
|
||||
struct InstanceData
|
||||
{
|
||||
float4x4 m;
|
||||
float4 color;
|
||||
};
|
||||
StructuredBuffer<InstanceData> _DataBuffer;
|
||||
#endif
|
||||
void setup()
|
||||
{
|
||||
InstanceData data = _DataBuffer[unity_InstanceID];
|
||||
UNITY_MATRIX_M = data.m; //UNITY_MATRIX_M
|
||||
_Color = data.color;
|
||||
}
|
||||
#endif
|
||||
|
||||
struct appdata_t
|
||||
{
|
||||
float4 vertex : POSITION;
|
||||
@ -58,55 +66,14 @@ Shader "DCFApixels/DebugX/Handles"
|
||||
half4 color : COLOR;
|
||||
};
|
||||
|
||||
float4 _Color;
|
||||
float4 _DebugX_GlobalColor;
|
||||
|
||||
void setup()
|
||||
{
|
||||
#if defined(UNITY_PROCEDURAL_INSTANCING_ENABLED)
|
||||
InstanceData data = _DataBuffer[unity_InstanceID];
|
||||
|
||||
UNITY_MATRIX_M = data.m; //UNITY_MATRIX_M
|
||||
_Color = data.color;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
#if _DOT_ON
|
||||
float _DebugX_GlobalDotSize;
|
||||
float GetHandleSize(float3 objectPosition)
|
||||
{
|
||||
float3 viewDir = normalize(_WorldSpaceCameraPos - objectPosition);
|
||||
|
||||
float distance = length(_WorldSpaceCameraPos - objectPosition);
|
||||
float isOrthographic = UNITY_MATRIX_P[3][3];
|
||||
distance = lerp(distance, 1, isOrthographic);
|
||||
|
||||
float fov = radians(UNITY_MATRIX_P[1][1] * 2.0);
|
||||
float scale = distance * (1 / fov) * 0.015;
|
||||
|
||||
|
||||
return scale * _DebugX_GlobalDotSize;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
v2f vert (appdata_t v)
|
||||
{
|
||||
v2f o;
|
||||
UNITY_SETUP_INSTANCE_ID(v);
|
||||
|
||||
float4x4 M = UNITY_MATRIX_M;
|
||||
#if _DOT_ON
|
||||
float scaleMultiplier = GetHandleSize(mul(UNITY_MATRIX_M, float4(0, 0, 0, 1)).xyz);
|
||||
M._m00 *= scaleMultiplier;
|
||||
M._m11 *= scaleMultiplier;
|
||||
M._m22 *= scaleMultiplier;
|
||||
#endif
|
||||
|
||||
float4x4 M = GET_HANDLE_UNITY_MATRIX_M();
|
||||
|
||||
#if _BILLBOARD_ON
|
||||
float4 worldOrigin = mul(M, float4(0, 0, 0, 1));
|
||||
|
47
Runtime/Shaders/HandlesLibrary.cginc
Normal file
47
Runtime/Shaders/HandlesLibrary.cginc
Normal file
@ -0,0 +1,47 @@
|
||||
|
||||
|
||||
|
||||
float GetHandleSize(float3 objectPosition, float scaleM)
|
||||
{
|
||||
float3 viewDir = normalize(_WorldSpaceCameraPos - objectPosition);
|
||||
|
||||
float distance = length(_WorldSpaceCameraPos - objectPosition);
|
||||
float isOrthographic = UNITY_MATRIX_P[3][3];
|
||||
distance = lerp(distance, 1, isOrthographic);
|
||||
|
||||
float fov = radians(UNITY_MATRIX_P[1][1] * 2.0);
|
||||
float scale = distance * (1 / fov) * 0.015;
|
||||
|
||||
return scale * scaleM;
|
||||
}
|
||||
|
||||
float4x4 GetHandleSizeMatrix(float3 objectPosition, float scaleM)
|
||||
{
|
||||
float4x4 M = UNITY_MATRIX_M;
|
||||
|
||||
float scale = GetHandleSize(objectPosition, scaleM);
|
||||
M._m00 *= scale;
|
||||
M._m11 *= scale;
|
||||
M._m22 *= scale;
|
||||
|
||||
return M;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//Macros
|
||||
#if _DOT_ON
|
||||
float _DebugX_GlobalDotSize;
|
||||
#endif
|
||||
float4 _Color;
|
||||
|
||||
float4x4 GET_HANDLE_UNITY_MATRIX_M()
|
||||
{
|
||||
#if _DOT_ON
|
||||
return GetHandleSizeMatrix(mul(UNITY_MATRIX_M, float4(0, 0, 0, 1)).xyz, _DebugX_GlobalDotSize);
|
||||
#else
|
||||
return UNITY_MATRIX_M;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
7
Runtime/Shaders/HandlesLibrary.cginc.meta
Normal file
7
Runtime/Shaders/HandlesLibrary.cginc.meta
Normal file
@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 728ffe8b3d2321e45a960a3a90e65bc6
|
||||
ShaderIncludeImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -33,15 +33,23 @@ Shader "DCFApixels/DebugX/Handles Overwrite"
|
||||
#pragma instancing_options procedural:setup
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
#include "HandlesLibrary.cginc"
|
||||
|
||||
#if defined(UNITY_PROCEDURAL_INSTANCING_ENABLED)
|
||||
#if defined(UNITY_PROCEDURAL_INSTANCING_ENABLED)
|
||||
struct InstanceData
|
||||
{
|
||||
float4x4 m;
|
||||
float4 color;
|
||||
};
|
||||
StructuredBuffer<InstanceData> _DataBuffer;
|
||||
#endif
|
||||
void setup()
|
||||
{
|
||||
InstanceData data = _DataBuffer[unity_InstanceID];
|
||||
UNITY_MATRIX_M = data.m; //UNITY_MATRIX_M
|
||||
_Color = data.color;
|
||||
}
|
||||
#endif
|
||||
|
||||
struct appdata_t
|
||||
{
|
||||
float4 vertex : POSITION;
|
||||
@ -60,54 +68,13 @@ Shader "DCFApixels/DebugX/Handles Overwrite"
|
||||
half4 color : COLOR;
|
||||
};
|
||||
|
||||
float4 _Color;
|
||||
float4 _DebugX_GlobalColor;
|
||||
|
||||
void setup()
|
||||
{
|
||||
#if defined(UNITY_PROCEDURAL_INSTANCING_ENABLED)
|
||||
InstanceData data = _DataBuffer[unity_InstanceID];
|
||||
|
||||
UNITY_MATRIX_M = data.m; //UNITY_MATRIX_M
|
||||
_Color = data.color;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
#if _DOT_ON
|
||||
float _DebugX_GlobalDotSize;
|
||||
float GetHandleSize(float3 objectPosition)
|
||||
{
|
||||
float3 viewDir = normalize(_WorldSpaceCameraPos - objectPosition);
|
||||
|
||||
float distance = length(_WorldSpaceCameraPos - objectPosition);
|
||||
float isOrthographic = UNITY_MATRIX_P[3][3];
|
||||
distance = lerp(distance, 1, isOrthographic);
|
||||
|
||||
float fov = radians(UNITY_MATRIX_P[1][1] * 2.0);
|
||||
float scale = distance * (1 / fov) * 0.015;
|
||||
|
||||
return scale * _DebugX_GlobalDotSize;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
v2f vert (appdata_t v)
|
||||
{
|
||||
v2f o;
|
||||
UNITY_SETUP_INSTANCE_ID(v);
|
||||
|
||||
float4x4 M = UNITY_MATRIX_M;
|
||||
#if _DOT_ON
|
||||
float scaleMultiplier = GetHandleSize(mul(UNITY_MATRIX_M, float4(0, 0, 0, 1)).xyz);
|
||||
M._m00 *= scaleMultiplier;
|
||||
M._m11 *= scaleMultiplier;
|
||||
M._m22 *= scaleMultiplier;
|
||||
#endif
|
||||
|
||||
float4x4 M = GET_HANDLE_UNITY_MATRIX_M();
|
||||
|
||||
#if _BILLBOARD_ON
|
||||
float4 worldOrigin = mul(M, float4(0, 0, 0, 1));
|
||||
|
@ -32,15 +32,24 @@ Shader "DCFApixels/DebugX/Handles Wire"
|
||||
#pragma instancing_options procedural:setup
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
#include "HandlesLibrary.cginc"
|
||||
|
||||
#if defined(UNITY_PROCEDURAL_INSTANCING_ENABLED)
|
||||
#if defined(UNITY_PROCEDURAL_INSTANCING_ENABLED)
|
||||
struct InstanceData
|
||||
{
|
||||
float4x4 m;
|
||||
float4 color;
|
||||
};
|
||||
StructuredBuffer<InstanceData> _DataBuffer;
|
||||
#endif
|
||||
void setup()
|
||||
{
|
||||
InstanceData data = _DataBuffer[unity_InstanceID];
|
||||
UNITY_MATRIX_M = data.m; //UNITY_MATRIX_M
|
||||
_Color = data.color;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
struct appdata_t
|
||||
{
|
||||
float4 vertex : POSITION;
|
||||
@ -64,54 +73,14 @@ Shader "DCFApixels/DebugX/Handles Wire"
|
||||
float4 color : COLOR;
|
||||
};
|
||||
|
||||
float4 _Color;
|
||||
float4 _DebugX_GlobalColor;
|
||||
|
||||
void setup()
|
||||
{
|
||||
#if defined(UNITY_PROCEDURAL_INSTANCING_ENABLED)
|
||||
InstanceData data = _DataBuffer[unity_InstanceID];
|
||||
|
||||
UNITY_MATRIX_M = data.m; //UNITY_MATRIX_M
|
||||
_Color = data.color;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
#if _DOT_ON
|
||||
float _DebugX_GlobalDotSize;
|
||||
float GetHandleSize(float3 objectPosition)
|
||||
{
|
||||
float3 viewDir = normalize(_WorldSpaceCameraPos - objectPosition);
|
||||
|
||||
float distance = length(_WorldSpaceCameraPos - objectPosition);
|
||||
float isOrthographic = UNITY_MATRIX_P[3][3];
|
||||
distance = lerp(distance, 1, isOrthographic);
|
||||
|
||||
float fov = radians(UNITY_MATRIX_P[1][1] * 2.0);
|
||||
float scale = distance * (1 / fov) * 0.015;
|
||||
|
||||
return scale * _DebugX_GlobalDotSize;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
v2g vert (appdata_t v)
|
||||
{
|
||||
v2g o;
|
||||
UNITY_SETUP_INSTANCE_ID(v);
|
||||
|
||||
float4x4 M = UNITY_MATRIX_M;
|
||||
#if _DOT_ON
|
||||
float scaleMultiplier = GetHandleSize(mul(UNITY_MATRIX_M, float4(0, 0, 0, 1)).xyz);
|
||||
M._m00 *= scaleMultiplier;
|
||||
M._m11 *= scaleMultiplier;
|
||||
M._m22 *= scaleMultiplier;
|
||||
#endif
|
||||
|
||||
float4x4 M = GET_HANDLE_UNITY_MATRIX_M();
|
||||
|
||||
#if _BILLBOARD_ON
|
||||
float4 worldOrigin = mul(M, float4(0, 0, 0, 1));
|
||||
|
Loading…
Reference in New Issue
Block a user