Unity技巧总结02 GUI绘制 Loading遮罩

来源:互联网 发布:linux下输入ftp命令 编辑:程序博客网 时间:2024/06/14 08:14

直接上代码,有注释


    public Texture _mask, _circle;//遮罩图片,旋转图片    private bool _isLoading = false;//运行标志    private float _uvCoord, _loadingTime = 5.0f;//旋转图片位置, Loading时间(过了自动停止)    void LoadingAnimi()    {        if (_isLoading)        {            int screenW = Screen.width, screenH = Screen.height;            GUI.DrawTexture(new Rect(0, 0, screenW, screenH), _mask);//遮罩            //旋转圈            _uvCoord += Time.deltaTime * 100;            GUIUtility.RotateAroundPivot(_uvCoord, new Vector2(screenW / 2, screenH / 2));            Matrix4x4 _matrix = GUI.matrix;            GUI.DrawTexture(new Rect(screenW / 2 - _circle.width / 2, screenH / 2 - _circle.height / 2, _circle.width, _circle.height), _circle);            GUI.matrix = _matrix;//矩阵变换            if (Time.time - _loadingTime > 5)            {                _isLoading = false;            }        }    }    /// <summary>    /// 测试    /// </summary>    public void BtnEvent_Loading()    {        _isLoading = true;    }    void OnGUI()    {        LoadingAnimi();    }


需要准备两张图 一个半透明遮罩图,一张旋转图


原创粉丝点击