unity EditorWindow 绘制时间刻度

最终效果图

绘制时间刻度其实主要靠,Handles类的DrawLine(),Handles类里还封装了许多其它的图形绘制方法,如画扇形等

知道这个方法就很简单了

    private void DrawfraemLine(Rect rect)
    {
        Handles.BeginGUI();
        Handles.color = new Color(0,1,0,0.4f);
        float step = 8;
        int Index = 0;
        for (float i = rect.x+2; i < rect.width; i+=step)
        {
            if (Index%5 == 0)
            {
                Handles.DrawLine(new Vector3(i, rect.y + rect.height - 20), new Vector3(i, rect.y + rect.height - 5));
                string str = Index.ToString();
                if (str.Length>2)
                {
                    GUI.Label(new Rect(i - 15, rect.y + 12, 30, 12), str);
                }
                else if(str.Length>1)
                {
                    GUI.Label(new Rect(i - 10, rect.y + 12, 20, 12), str);
                }
                else
                {
                    GUI.Label(new Rect(i - 5, rect.y + 12, 12, 12), str);
                }
                
            }
            else
            {
                Handles.DrawLine(new Vector3(i, rect.y + rect.height - 15), new Vector3(i, rect.y + rect.height - 10));
            }
            Index++;
            
        }
        
        Handles.EndGUI();
    }
原文地址:https://www.cnblogs.com/DazeJiang/p/14083221.html