Unity截屏并更新到UI上(PC端案例)

  • 截屏代码
UnityEngine.ScreenCapture.CaptureScreenshot(Application.streamingAssetsPath + "/phone/FileName.png");
  • 更新到UI

    private string DeletePath;


#region//删除
        DeletePath = Application.streamingAssetsPath + "/phone";
        if (!Directory.Exists(DeletePath))
        {
            Directory.CreateDirectory(DeletePath);
        }
        try
        {
            DirectoryInfo dir = new DirectoryInfo(DeletePath);
            FileSystemInfo[] files = dir.GetFileSystemInfos();
            foreach (FileSystemInfo item in files)
            {
                if (item is DirectoryInfo)//判断是否文件夹
                {
                    DirectoryInfo subdir = new DirectoryInfo(item.FullName);
                    subdir.Delete(true);//删除子目录和文件
                }
                else
                {
                    File.Delete(item.FullName);//删除指定文件
                }
            }
        }
        catch (Exception e)
        {
            throw new Exception(e.Message);
        }
        //刷新
        UnityEditor.AssetDatabase.Refresh();
        #endregion```

        UnityEngine.ScreenCapture.CaptureScreenshot(Application.streamingAssetsPath + "/phone/FileName.png");
        //刷新
        UnityEditor.AssetDatabase.Refresh();
        Invoke("dddd", 2f);




    void dddd()
    {
        StartCoroutine(TestLoadPhoto());
    }


    IEnumerator TestLoadPhoto()
    {
        WWW www = new WWW(Application.streamingAssetsPath + "/phone/FileName.png");
        yield return www;
        if (www != null && string.IsNullOrEmpty(www.error))
        {
            image.texture = www.texture;
        }
        
        image.gameObject.SetActive(true);
    }

猜你喜欢

转载自blog.csdn.net/Chj1319261607/article/details/128051194