私のコードは、奇妙なことに、ローカルハードドライブから "planarLogo"というgameObjectにユーザーイメージを読み込んでいません。 ImageUploaderCaptureClick()関数を持つファイルはImageUploader1.jslibと呼ばれ、plugins/WebGlフォルダにあります。Unity3D - ユーザーがwebglのイメージを読み込ませます
ここで、ここで
using UnityEngine;
using System.Collections;
using System.Runtime.InteropServices;
public class LoadImage : MonoBehaviour
{
[DllImport("__Internal")]
private static extern void ImageUploaderCaptureClick();
private Texture2D displayedTexture;
IEnumerator LoadTexture(string url)
{
WWW image = new WWW(url);
yield return image;
image.LoadImageIntoTexture(displayedTexture);
}
void FileSelected(string url)
{
StartCoroutine(LoadTexture(url));
}
public void OnButtonPointerDown()
{
#if UNITY_EDITOR
string path = UnityEditor.EditorUtility.OpenFilePanel("Open image", "", "jpg,png,bmp");
if (!System.String.IsNullOrEmpty(path))
FileSelected("file:///" + path);
#else
ImageUploaderCaptureClick();
#endif
}
void Start()
{
displayedTexture = new Texture2D(1, 1);
GameObject.Find("PlaneLogo").GetComponent<MeshRenderer>().material.mainTexture = displayedTexture;
GameObject.Find("PlaneLogo").GetComponent<Renderer>().enabled = true;
}
}
そして私はイベントに対処する方法を説明しますスクリプトです。
私が知っているすべてを試みたし、プロジェクトがユニティ内部の作業を続けたが、それは、HTML(WebGLの)としてコンパイルされます際ません。
単純なWebサーバーを実行します。セットアップに数秒かかります。 [この方法について](https://chrome.google.com/webstore/detail/web-server-for-chrome/ofhbbkphhbklhfoeikjpcbhemlocgigb?hl=ja)?または[これらの](http://stackoverflow.com/questions/12905426/what-is-a-faster-alternative-to-pythons-simplehttpserver/) – gman