【Webview】unity-webview/UniWebView3

8879 단어 Unity

unity-webview


단순 디스플레이

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SimpleWebView : MonoBehaviour {

    private string url = "https://www.google.co.jp/";
    WebViewObject webViewObject;

    void Start () {
        webViewObject = (new GameObject("WebViewObject")).AddComponent<WebViewObject>();
        webViewObject.Init((msg) => {
            Debug.Log(msg);
        });
        webViewObject.LoadURL(url);
        // 中央に配置
        webViewObject.SetMargins(Screen.width / 4, Screen.height / 4, Screen.width / 4, Screen.height / 4);
        webViewObject.SetVisibility(true);
    }
}

로컬 파일 보이기


• HTML 등 필요한 파일을 Assets/StreamingAssets/ 아래에 구성
· 파일의 읽기를 webViewObject.LoadURL("file://${filePath}");로 변경한다.
string filePath = System.IO.Path.Combine(Application.persistentDataPath, "sample.html");
webViewObject.LoadURL("file://" + filePath.Replace(" ", "%20"));
참고 자료
Unity에서 WebView의 unity-webview 열기
Unity 3D의gree webview에 로컬 HTML을 표시하고 JS에서 Unity 코드를 실행하고 파일 읽기와 쓰기

UniWebView3


https://www.assetstore.unity3d.com/jp/?stay#!/content/92605
http://docs.uniwebview.com/api/

단순 디스플레이

UniWebView.cs를 빈 대상에 부속시키면 된다.

로컬 파일 보이기


● 프레젠테이션의 LocalHTMLSceneManager.cs에 모든 객체를 첨부합니다.
• fileName에 Assets/StreamingAssets/ 아래 구성의 파일 경로를 입력합니다.
・ 임의의 시기에 두드린다LoadFromFileメソッド.
LocalHTMLSceneManager.cs
using UnityEngine;

public class LocalHTMLSceneManager : MonoBehaviour {
    public string fileName;
    public string htmlText;
#if UNITY_IOS || UNITY_ANDROID || UNITY_WP8
    public void LoadFromFile() {

        var webView = CreateWebView();
        webView.url = UniWebViewHelper.streamingAssetURLForPath(fileName);
        webView.Load();
        webView.Show();
    }

    public void LoadFromText() {
        var webView = CreateWebView();

        webView.LoadHTMLString(htmlText, null);
        webView.Show();
    }

    UniWebView CreateWebView() {
        var webViewGameObject = GameObject.Find("WebView");
        if (webViewGameObject == null) {
            webViewGameObject = new GameObject("WebView");
        }

        var webView = webViewGameObject.AddComponent<UniWebView>();

        webView.toolBarShow = true;
        return webView;
    }

#else //End of #if UNITY_IOS || UNITY_ANDROID || UNITY_WP8
    void Start() {
        Debug.LogWarning("UniWebView only works on iOS/Android/WP8. Please switch to these platforms in Build Settings.");
    }
#endif
}
참고 자료
UNITY의 WEBVIEW 정보(브라우저 내장)

좋은 웹페이지 즐겨찾기