Unity-GUI绘制旋转的Texture

效果图:Unity-GUI绘制旋转的Texture_第1张图片

打包一个root.assetbundle文件,添加如下脚本:

public class LoadSence : MonoBehaviour
{
    public Texture Background;
    public Texture loading;
    private float time=0;

    public string url = null;
    private WWW www;
    
    void Awake()
    {
        //加载路径
        if (Application.platform == RuntimePlatform.WindowsEditor)
        {
            url = "file:///" + Application.dataPath + "/StreamingAssets/WebPlayer/"; 
        }
        else if (Application.platform == RuntimePlatform.WindowsWebPlayer)
        {
            
        }
    }

    void Start()
    {
        StartCoroutine(LoadSenceAssetbundle());
    }

    void FixedUpdate()
    {
        time += Time.deltaTime;
    }

    void OnGUI()
    {
        if (www != null)
        {
            //背景图片
            GUI.SetNextControlName("Background");
            GUI.DrawTexture(new Rect(0, 0, Screen.width, Screen.height), Background, ScaleMode.StretchToFill);
            GUI.depth = 0;
            //loading的图片(旋转)
            GUI.SetNextControlName("loading");
            GUIUtility.RotateAroundPivot(300*time, new Vector2(Screen.width / 2, Screen.height / 2));
            GUI.DrawTexture(new Rect(Screen.width / 2 - 75, Screen.height / 2 - 75, 150, 150), loading, ScaleMode.ScaleToFit);
            GUI.depth = -1;
        }
    }

    IEnumerator LoadSenceAssetbundle()
    {
        //加载Root.assetbundle文件
        www = new WWW(url + "Root.assetbundle");
        while (!www.isDone)
        {
            yield return www;
        }
        Instantiate(www.assetBundle.mainAsset);
        www.assetBundle.Unload(false);
        if (www != null)
        {
            www.Dispose();
            www = null;
        }
    }
}


你可能感兴趣的:(unity,GUI绘制旋转贴图)