小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

編輯器窗口畫線修改

 tiancaiwrk 2019-05-13

使用某個(gè)編輯器窗口進(jìn)行畫線的邏輯使用的是

GUI.DrawTexture(new Rect(pointA.x, pointA.y, 1, 1), lineTex);

的方式, 可是在起點(diǎn)不被編輯器窗口渲染的情況下整條線段都不被渲染, 很有問題, 

修改為GUI.Box的情況就可以改善

 public static System.Collections.Generic.Dictionary<Color, Texture2D> lineTextures = new System.Collections.Generic.Dictionary<Color, Texture2D>();

   public static void DrawLine(Vector2 pointA, Vector2 pointB, Color color, float width)

        {

            pointA = new Vector2(Mathf.RoundToInt(pointA.x), Mathf.RoundToInt(pointA.y));

            pointB = new Vector2(Mathf.RoundToInt(pointB.x), Mathf.RoundToInt(pointB.y));

            var dis = Vector2.Distance(pointA, pointB);

            if(dis < 0.1f)

            {

                return;

            }

            width = Mathf.Max(1.0f, width);

            // Save the current GUI matrix, since we're going to make changes to it.

            Matrix4x4 matrix = GUI.matrix;

            var tex = lineTextures.TryGetNullableValue(color);

            // Generate a single pixel texture if it doesn't exist

            if(false == tex)

            {

                tex = new Texture2D(1, 1);

                tex.SetPixel(0, 0, color);

                tex.Apply();

                lineTextures[color] = tex;

            }

            // Store current GUI color, so we can switch it back later,

            // and set the GUI color to the color parameter

            Color savedColor = GUI.color;

            GUI.color = color;

            // Determine the angle of the line.

            float angle = Vector3.Angle(pointB - pointA, Vector2.right);

            // Vector3.Angle always returns a positive number.

            // If pointB is above pointA, then angle needs to be negative.

            if(pointA.y > pointB.y)

            { angle = -angle; }

            // Use ScaleAroundPivot to adjust the size of the line.

            // We could do this when we draw the texture, but by scaling it here we can use

            //  non-integer values for the width and length (such as sub 1 pixel widths).

            // Note that the pivot point is at +.5 from pointA.y, this is so that the width of the line

            //  is centered on the origin at pointA.

            //GUIUtility.ScaleAroundPivot(new Vector2(dis, width), new Vector2(pointA.x, pointA.y));

            // Set the rotation for the line.

            //  The angle was calculated with pointA as the origin.

            GUIUtility.RotateAroundPivot(angle, pointA);

            // Finally, draw the actual line.

            // We're really only drawing a 1x1 texture from pointA.

            // The matrix operations done with ScaleAroundPivot and RotateAroundPivot will make this

            //  render with the proper width, length, and angle.

            //GUI.DrawTexture(new Rect(pointA.x, pointA.y, 1, 1), lineTex);

            var lastBG = GUI.skin.box.normal.background;

            GUI.skin.box.normal.background = tex;

            GUI.Box(new Rect(pointA.x, pointA.y, dis, width), tex);

            GUI.skin.box.normal.background = lastBG;

            // We're done.  Restore the GUI matrix and GUI color to whatever they were before.

            GUI.matrix = matrix;

            GUI.color = savedColor;

        }

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多