본문 바로가기
모바일/유니티

유니티 | WebView

by KISCH 2020. 3. 10.
반응형

 

 

 

유니티 웹뷰 플러그인 사용법에 대해 알아보겠습니다. 먼저 플러그인을 다운로드해야합니다.

 

https://github.com/gree/unity-webview

 
다음으로 패키지 설치하고 오브젝트에 스크립트 추가합니다.
 
using UnityEngine;
using System.Collections;

public class WebViewScript : MonoBehaviour {

    private WebViewObject webViewObject;

    // Use this for initialization
    void Start () {
        StartWebView ();
    }
    
    // Update is called once per frame
    void Update () {

        //if (Application.platform == RuntimePlatform.Android) {
            if (Input.GetKey (KeyCode.Escape)) {                    // 뒤 로 가 기, esc 버 튼 
                Destroy (webViewObject);
                return;
            }
        //}
    }

    public void StartWebView() {

        string strUrl = "웹서버주소";

        webViewObject = (new GameObject ("WebViewObject")).AddComponent<WebViewObject> ();
        webViewObject.Init ((msg) => {
            Debug.Log (string.Format ("CallFromJS[{0}]", msg));
        });

        webViewObject.LoadURL (strUrl);
        webViewObject.SetVisibility (true);
        webViewObject.SetMargins (50, 50, 50, 50);
    }
}
 
웹서버와 연동
 
스크립트 -> 컨트롤러 -> 뷰
 
유니티웹뷰
 

 

반응형

댓글