【发布时间】:2015-02-18 16:42:35
【问题描述】:
我开发 Web Player 应用程序。 在场景中我有一些 3d 模型(例如:盒子)。 在运行时,我上传 *.png 图像并在贴花上使用此图像到我的汽车。 我使用这个包:https://www.assetstore.unity3d.com/en/#!/content/13889 用于贴花系统。 我的编辑器工作正常,但在运行时我无法在贴花系统中使用我的图片。 任务:需要随时更换一张图片,并成为贴花系统中的好东西。 请帮我。 谢谢!
public GameObject decal;
public Material mat;
Texture2D texTmp;
Sprite spr;
string settingsContent;
string[] settingsSplit;
int texWidth,texHeight;
void Awake()
{
StartCoroutine(DownloadSettings());
}
IEnumerator DownloadSettings()
{
WWW www = new WWW("http://585649.workwork.web.hosting-test.net/Logo1/settings.txt");
yield return www;
settingsContent = www.text;
settingsSplit = settingsContent.Split('\n');
if (www.isDone)
{
texWidth = int.Parse(settingsSplit[1]);
texHeight = int.Parse(settingsSplit[2]);
texTmp = new Texture2D(texWidth,texHeight);
StartCoroutine(DownloadLogos());
}
}
IEnumerator DownloadLogos()
{
WWW www = new WWW(settingsSplit[0]);
yield return www;
www.LoadImageIntoTexture(texTmp);
if (www.isDone)
{
spr = Sprite.Create(texTmp, new Rect(0, 0, texTmp.width, texTmp.height), Vector2.zero, 100);
spr.texture.wrapMode = TextureWrapMode.Clamp;
mat.mainTexture = spr.texture;
Color clr = new Color32(255,255,255,255);
clr.a = float.Parse(settingsSplit[3]);
mat.color = clr;
decal.AddComponent("Decal");
decal.GetComponent<Decal>().material = mat;
decal.GetComponent<Decal>().sprite = spr;
}
}
【问题讨论】:
-
我编辑我的问题(带代码)