Misaki的代码无法在我这里生效只能在场景中看到绘制信息无法在Game中看到
我自己参考了的代码(我使用的是4.1版本的runtime所以没有bone.AppliedPose)
using System.Collections.Generic;
using UnityEngine;
using Spine;
using Spine.Unity;
public class SpineRuntimeDebugLines : MonoBehaviour
{
public Color boneColor = Color.green;
public Color meshColor = Color.cyan;
float lineWidth = 1.5f;
SkeletonRenderer skeletonRenderer;
Material lineMaterial;
readonly List<LineRenderer> lines = new();
int lineIndex;
void Awake()
{
skeletonRenderer = GetComponent<SkeletonRenderer>();
lineMaterial = new Material(Shader.Find("Sprites/Default"));
}
void LateUpdate()
{
lineIndex = 0;
if (settingctl.showbonesdebug)
DrawBones();
if (settingctl.showmeshdebug)
DrawMesh();
if (settingctl.showhulldebug)
DrawHull();
for (int i = lineIndex; i < lines.Count; i++)
{
lines[i].gameObject.SetActive(false);
}
}
void DrawBones()
{
foreach (var bone in skeletonRenderer.Skeleton.Bones)
{
float x = bone.WorldX;
float y = bone.WorldY;
float rot = bone.WorldRotationX * Mathf.Deg2Rad;
float len = bone.Data.Length;
Vector3 a = new Vector3(x, y, 0);
Vector3 b = new Vector3(
x + Mathf.Cos(rot) * len,
y + Mathf.Sin(rot) * len,
0
);
DrawLine(a, b, boneColor);
}
}
static readonly float[] worldVertices = new float[8192];
void DrawMesh()
{
var skeleton = skeletonRenderer.Skeleton;
foreach (var slot in skeleton.DrawOrder)
{
var attachment = slot.Attachment;
if (attachment == null)
continue;
if (attachment is RegionAttachment region)
{
DrawRegion(slot, region);
}
else if (attachment is MeshAttachment mesh)
{
DrawMeshAttachment(slot, mesh);
}
}
}
void DrawHull()
{
var skeleton = skeletonRenderer.Skeleton;
foreach (var slot in skeleton.DrawOrder)
{
var attachment = slot.Attachment;
if (attachment == null)
continue;
if (attachment is RegionAttachment region)
{
region.ComputeWorldVertices(slot, worldVertices, 0, 2);
Vector3 a = new(worldVertices[0], worldVertices[1], 0);
Vector3 b = new(worldVertices[2], worldVertices[3], 0);
Vector3 c = new(worldVertices[4], worldVertices[5], 0);
Vector3 d = new(worldVertices[6], worldVertices[7], 0);
DrawLine(a, b, Color.yellow);
DrawLine(b, c, Color.yellow);
DrawLine(c, d, Color.yellow);
DrawLine(d, a, Color.yellow);
continue;
}
if (attachment is MeshAttachment mesh)
{
int vertexCount = mesh.WorldVerticesLength;
mesh.ComputeWorldVertices(slot, 0, vertexCount, worldVertices, 0, 2);
int hull = mesh.HullLength;
if (hull <= 0)
continue;
for (int i = 0; i < hull; i += 2)
{
int ni = (i + 2) % hull;
Vector3 a = new(
worldVertices[i],
worldVertices[i + 1],
0
);
Vector3 b = new(
worldVertices[ni],
worldVertices[ni + 1],
0
);
DrawLine(a, b, Color.yellow);
}
}
}
}
void DrawRegion(Slot slot, RegionAttachment region)
{
region.ComputeWorldVertices(slot, worldVertices, 0, 2);
Vector3 v0 = new(worldVertices[0], worldVertices[1], 0);
Vector3 v1 = new(worldVertices[2], worldVertices[3], 0);
Vector3 v2 = new(worldVertices[4], worldVertices[5], 0);
Vector3 v3 = new(worldVertices[6], worldVertices[7], 0);
DrawLine(v0, v1, meshColor);
DrawLine(v1, v2, meshColor);
DrawLine(v2, v3, meshColor);
DrawLine(v3, v0, meshColor);
}
void DrawMeshAttachment(Slot slot, MeshAttachment mesh)
{
int vertexCount = mesh.WorldVerticesLength;
mesh.ComputeWorldVertices(slot, 0, vertexCount, worldVertices, 0, 2);
var triangles = mesh.Triangles;
for (int i = 0; i < triangles.Length; i += 3)
{
int ia = triangles[i] * 2;
int ib = triangles[i + 1] * 2;
int ic = triangles[i + 2] * 2;
Vector3 a = new(worldVertices[ia], worldVertices[ia + 1], 0);
Vector3 b = new(worldVertices[ib], worldVertices[ib + 1], 0);
Vector3 c = new(worldVertices[ic], worldVertices[ic + 1], 0);
DrawLine(a, b, meshColor);
DrawLine(b, c, meshColor);
DrawLine(c, a, meshColor);
}
}
void DrawLine(Vector3 a, Vector3 b, Color color)
{
LineRenderer lr;
if (lineIndex >= lines.Count)
{
lr = CreateLineRenderer();
lines.Add(lr);
}
else
{
lr = lines[lineIndex];
}
lineIndex++;
lr.gameObject.SetActive(true);
lr.startColor = color;
lr.endColor = color;
lr.positionCount = 2;
lr.SetPosition(0, a);
lr.SetPosition(1, b);
}
LineRenderer CreateLineRenderer()
{
GameObject go = new("DebugLine");
go.transform.SetParent(transform, false);
var lr = go.AddComponent<LineRenderer>();
lr.material = lineMaterial;
lr.useWorldSpace = false;
lr.sortingOrder = 9999;
lr.startWidth = lineWidth;
lr.endWidth = lineWidth;
lr.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
lr.receiveShadows = false;
lr.textureMode = LineTextureMode.Stretch;
lr.numCapVertices = 0;
lr.numCornerVertices = 0;
return lr;
}
}
这段代码实现了一个看起来和ts运行时中debug绘制差不多的效果我也可以用来调试其他角色在画面中的位置
ts中开启bones的debug还有这种绿色的点

我不知道怎么使用C#去实现
以及Clipping