2016-08-02 2 views
0

내 코드가 이상하게도 로컬 하드 드라이브의 사용자 이미지를 "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; 
    } 
} 

을 그리고 여기에 내가 이벤트를 처리하는 방법입니다.

enter image description here

나는 내가 알고있는 모든 것을 시도하고 프로젝트 유니티 내부 작업을 계속하지만이 HTML (WebGL을)로 컴파일 때하지 않습니다.

+0

간단한 웹 서버를 실행하십시오. 설정하는 데 몇 초가 걸립니다. [이 방법에 대해] (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

답변

0

유니티에서 WebGL은 파일 시스템

https://docs.unity3d.com/Manual/webgl-debugging.html

당신은 서버에서 이미지를 가져해야합니다에 액세스 할 수 없습니다. 그것은 빈민가지만 내가 볼 수있는 유일한 방법은 서버가 이미지를 로컬에서 가져 와서 WebGL 게임에 중계하는 것을 설정하는 것입니다.

관련 문제