내 코드가 이상하게도 로컬 하드 드라이브의 사용자 이미지를 "planeLogo"라는 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을)로 컴파일 때하지 않습니다.
간단한 웹 서버를 실행하십시오. 설정하는 데 몇 초가 걸립니다. [이 방법에 대해] (https://chrome.google.com/webstore/detail/web-server-for-chrome/ofhbbkphhbklhfoeikjpcbhemlocgigb?hl=ko)? 또는 [these] (http://stackoverflow.com/questions/12905426/what-is-a-faster-alternative-to-pythons-simplehttpserver/) – gman