【问题标题】:Snapping UI sprite in Unity?在 Unity 中捕捉 UI 精灵?
【发布时间】:2020-06-09 16:02:35
【问题描述】:

IMAGE

有没有办法捕捉 UI 精灵顶点?在这种情况下,按住“V”不起作用。

【问题讨论】:

    标签: unity3d


    【解决方案1】:

    当您遇到问题时,检查 Unity 的文档是一个好的开始。我检查了文档,可以在这里找到:Modifying Sprite Vertices via Script

    阅读文档,您可以使用 Vector2 数组获取 Sprites 顶点。

    //Fetch the Sprite and vertices from the SpriteRenderer
    Sprite sprite = m_SpriteRenderer.sprite;
    Vector2[] spriteVertices = sprite.vertices;
    

    您可以按照此操作使用顶点进行绘制并在场景视图中查看它们

    // Show the sprite triangles
    void DrawDebug()
    {
        Sprite sprite = m_SpriteRenderer.sprite;
    
        ushort[] triangles = sprite.triangles;
        Vector2[] vertices = sprite.vertices;
        int a, b, c;
    
        // draw the triangles using grabbed vertices
        for (int i = 0; i < triangles.Length; i = i + 3)
        {
            a = triangles[i];
            b = triangles[i + 1];
            c = triangles[i + 2];
    
            //To see these you must view the game in the Scene tab while in Play mode
            Debug.DrawLine(vertices[a], vertices[b], Color.red, 100.0f);
            Debug.DrawLine(vertices[b], vertices[c], Color.red, 100.0f);
            Debug.DrawLine(vertices[c], vertices[a], Color.red, 100.0f);
        }
    }
    

    然而,通过使用脚本将顶点捕捉在一起似乎过于复杂,具体取决于它们的用途。鉴于此,了解您为什么要这样做会很有用?如果这些精灵是静态的、不动的或者只使用了很短的时间,那么在场景视图中手动对齐它们可能会容易得多。

    另一种方法是使用 ProGrid,它是一个 Unity 包,可让您在场景中打开捕捉,对于对齐游戏对象非常有用;这也允许改变捕捉的数量。

    通过Window -> Package Manager找到它。请注意,您可能需要打开预览包才能找到它。

    【讨论】:

      猜你喜欢
      • 2014-10-27
      • 1970-01-01
      • 1970-01-01
      • 2019-07-13
      • 2023-03-19
      • 1970-01-01
      • 1970-01-01
      • 2020-05-26
      • 2016-09-02
      相关资源
      最近更新 更多