gpt4 book ai didi

c# - Unity 游戏在 IOS 上崩溃,但在 Android 上运行完美

转载 作者:行者123 更新时间:2023-12-02 02:40:59 24 4
gpt4 key购买 nike

我制作了一个应用程序,可以拍摄屏幕图片并将其保存在图库中,其名称是我使用 DateTime 类和我自己的前缀指定的。 Android 上的代码运行完美,当您按下按钮时,它会截取屏幕截图并完成所有操作。但 iOS 上的情况却不一样。每当按下按钮时它就会崩溃。这是代码:

Flash.SetActive(true); 

RenderTexture rt = new RenderTexture(resWidth, resHeight, 24);
cam.targetTexture = rt;

Texture2D screenShot = new Texture2D(resWidth, resHeight, TextureFormat.RGB24, false);

cam.Render();

RenderTexture.active = rt;
screenShot.ReadPixels(new Rect(0, 0, resWidth, resHeight), 0, 0);
cam.targetTexture = null;
RenderTexture.active = null;
Destroy(rt);

byte[] bytes = screenShot.EncodeToPNG();

filename = ScreenShotName(resWidth, resHeight);
FullSharePath = "/storage/emulated/0/GarderobaShots/" + filename + ".png";

Texture2D textu = new Texture2D(900,1320, TextureFormat.RGBAFloat, false);
textu.LoadImage(bytes);
textu.Apply();

spr = Sprite.Create(textu ,new Rect(0.0f, 0.0f, textu.width, textu.height), new Vector2(1f, 1f), 100.0f);
ShareAbleObject.transform.GetChild(1).gameObject.GetComponent<Image> ().sprite = spr;

ShareAbleObject.SetActive(true);
NativeGallery.SaveImageToGallery(textu, "AmazingGirlsShots", filename + ".png");
takeHiResShot = false;

只是代码的快速介绍它用我拥有的一些相机切换场景的 MainCamera(它更小并且有不同的 Canvas (仅文本))然后它激活我称为 Flash 的对象,它是屏幕上的白色闪光,它会之后它会从屏幕渲染纹理并将其保存在

Texture2D 纹理

完整共享路径是存储此文件的路径,以便用户可以共享它或从游戏中查看它

NativeGallery.SaveImageToGallery(textu, "AmazingGirlsShots", filename".png");

这是我为 ios 和 android 使用的插件,可以刷新图库以在图库中显示图像,否则它只是在手机中的某个位置,我认为这不会是问题,因为很多人都使用它的检查插件。

最佳答案

请务必在 Info.plist 中设置权限隐私设置

enter image description here

关于c# - Unity 游戏在 IOS 上崩溃,但在 Android 上运行完美,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54189152/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com