【发布时间】:2020-09-27 20:28:16
【问题描述】:
我有一个附加到游戏对象的脚本。我也有一个按钮。按下按钮时,文件资源管理器打开并允许从 PC 中选择自定义图像,并在导入 Gameobject 更改的原始纹理后。但是当我退出并再次运行时,自定义纹理将替换为原始纹理。我想保存自定义纹理而不是原始 tex,然后选择删除自定义并返回原始 tex。请帮助我。对不起,我的英语不好。这是我的代码:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEditor;
using System.IO;
public class ChangeTex : MonoBehaviour
{
string path;
public MeshRenderer mRenderer;
public void OpenExplorer()
{
path = EditorUtility.OpenFilePanel("Overwrite with png", "", "png");
GetImage();
}
void GetImage()
{
if (path != null)
{
UpdateImage();
}
}
void UpdateImage()
{
byte[] imgByte = File.ReadAllBytes(path);
Texture2D texture = new Texture2D (2, 2);
texture.LoadImage(imgByte);
mRenderer.material.mainTexture = texture;
}
}
【问题讨论】:
标签: android unity3d 3d textures texture2d