Example #1
0
    /// <summary>
    /// Main initialization of web core, must be called before any UWKViews are created.
    /// </summary>
    public static void Init(bool inactivation)
    {
        if (sInstance != null)
        {
            return;
        }

        Application.runInBackground = true;

        string lang = Application.systemLanguage.ToString();

                #if UNITY_EDITOR || !UNITY_IPHONE
        if (lang == "Chinese" || lang == "Japanese" || lang == "Korean")
        {
            imeEnabled = true;
        }
                #endif

        GameObject go = new GameObject("UWKCore");

        UnityEngine.Object.DontDestroyOnLoad(go);

        UWKCore core = go.AddComponent <UWKCore> ();

        sInstance = core;
                #if UNITY_EDITOR
        activation = inactivation;
                #endif
        core.init();
    }
Example #2
0
    /// <summary>
    /// The main method to create a UWKView, note that views with identical names
    /// are reused
    /// </summary>
    public static UWKView CreateView(string name, string URL, int width, int height, bool smartRects)
    {
        if (RuntimeError)
        {
            return(null);
        }

        // ensure core is up
        UWKCore.Init();

        UWKView view;

        if (viewLookup.TryGetValue(name, out view))
        {
            //Debug.LogWarning ("View already exists " + name);
            return(view);
        }

        if (StandardVersion)
        {
            if (viewLookup.Count >= 1)
            {
                Debug.LogError("uWebKit Standard Version supports 1 web view");
                                #if UNITY_EDITOR
                EditorUtility.DisplayDialog("uWebKit Standard Version", "uWebKit Pro required for multiple web views", "Ok");
                                #endif
                return(null);
            }
        }

        view     = CreateViewInternal(name, width, height, smartRects);
        view.URL = URL;
        return(view);
    }
Example #3
0
    private static void processMessage(IntPtr pcmd)
    {
        UWKMessage msg = (UWKMessage)Marshal.PtrToStructure(pcmd, typeof(UWKMessage));

        msg._this = pcmd;
        UWKCore.ProcessMessage(ref msg);
    }
Example #4
0
    void windowFunction(int windowID)
    {
        int  titleHeight = 24;
        Rect titleRect   = new Rect(0, 0, Width + 16, titleHeight);

        GUI.DragWindow(titleRect);

        GUILayout.BeginVertical();

        GUIStyle style = new GUIStyle(GUI.skin.textArea);

        style.fontSize = 24;

        string text = @"This example shows everything needed to implement a login to Facebook dialog using uWebKit2";

        GUILayout.TextArea(text, style);

        if (state == State.Start)
        {
            if (GUILayout.Button(LoginTexture))
            {
                if (accessToken == "")
                {
                    view.Show();
                    state = State.Login;
                }
                else
                {
                    handleLoggedIn();
                }
            }

            GUILayout.Space(64);

            if (GUILayout.Button("Clear\nCookies", GUILayout.MaxWidth(100)))
            {
                UWKCore.ClearCookies();
            }
        }
        else if (state == State.Login)
        {
            GUILayout.Box(view.WebTexture);

            if (Event.current.type == EventType.Repaint)
            {
                browserRect = GUILayoutUtility.GetLastRect();

                browserRect.x += windowRect.x;
                browserRect.y += windowRect.y;

                scale.x = (float)Width / (float)browserRect.width;
                scale.y = (float)Height / (float)browserRect.height;
            }
        }
        else if (state == State.LoggedIn)
        {
        }

        GUILayout.EndVertical();
    }
Example #5
0
    public void load(string url)
    {
        if (View == null)
        {
            isLoaded = false;
            // Create the WebView, note that smart rects are disabled as they are only supported on 2D surfaces
            View = UWKCore.CreateView("WebTextureExample", url, Width, Height, true);

            // setup out delegate for when the view has veen created and ready to go
            View.ViewCreated += viewCreated;
        }
        else
        {
            Valid    = true;
            isLoaded = true;
        }

        // listen in for loaded page if we have a URL
        if (url != null && url.Length > 0)
        {
            Debug.Log("????!!!!!!!!!!!!!!!!???");
            View.LoadFinished += loadFinished;
        }
        else if (HtmlText != null)
        {
            // for TextAsset example, we won't render object until the view is loaded
            gameObject.renderer.enabled = false;
        }
    }
Example #6
0
    /// <summary>
    /// Main initialization of web core
    /// </summary>
    public static void Init()
    {
        // if we're already initialized, return immediately
        if (sInstance != null)
        {
            return;
        }

        // we want to run in the background
        Application.runInBackground = true;

        // check for IME and enable it if necessary
        string lang = Application.systemLanguage.ToString();

        if (lang == "Chinese" || lang == "Japanese" || lang == "Korean")
        {
            IMEEnabled = true;
        }

        // initialize the native plugin
        UWKPlugin.Initialize();

        // add ourselves to a new game object
        GameObject go = new GameObject("UWKCore");

        UnityEngine.Object.DontDestroyOnLoad(go);
        UWKCore core = go.AddComponent <UWKCore> ();

        // we're all ready to go
        sInstance = core;
    }
Example #7
0
    void OnDestroy()
    {
        UWKCore.DestroyView(this);

        if (WebTexture != null)
        {
            UnityEngine.Object.Destroy(WebTexture);
            WebTexture = null;
        }
    }
Example #8
0
    private static void processUWKEvent(StringBuilder eventType, IntPtr variantMap)
    {
        using (UWKEvent e = new UWKEvent())
        {
            e.variantMap = variantMap;
            e.eventType  = eventType.ToString();

            if (e.eventType.StartsWith("E_IPCWEBVIEW"))
            {
                UWKCore.ProcessWebViewEvent(e);
            }
        }
    }
 void Awake()
 {
     // ensure Core is up
     UWKCore.Init();
 }
Example #10
0
 void Close()
 {
     Valid = false;
     UWKCore.ClosePopup(this);
 }
    void OnGUI()
    {
        int buttonWidth = 180;

        // get the attached view component
        UWKWebView view = gameObject.GetComponent <UWKWebView>();

        int x = Screen.width / 2 - 1024 / 2 + 84;
        int y = Screen.height / 2 - 720 / 2;

        // draw it
        Rect r = new Rect(x, y, view.CurrentWidth, view.CurrentHeight);

        view.DrawTexture(r);

        // get the mouse coordinate
        Vector3 mousePos = Input.mousePosition;

        mousePos.y = Screen.height - mousePos.y;

        // translate based on position
        mousePos.x -= x;
        mousePos.y -= y;

        view.ProcessMouse(mousePos);

        // process keyboard
        if (Event.current.isKey)
        {
            view.ProcessKeyboard(Event.current);
        }

        x -= (buttonWidth + 32);
        y  = Screen.height / 2 - 720 / 2;

        if (y < 0)
        {
            y = 0;
        }

        GUI.BeginGroup(new Rect(x, y, buttonWidth, Screen.height));

        Rect brect = new Rect(0, 0, buttonWidth, 60);

        if (GUI.Button(brect, "Example 1 - Web Browser"))
        {
            Application.LoadLevel("Example1WebBrowser");
        }

        brect.y += 80;
        if (GUI.Button(brect, "Example 2 - Web GUI"))
        {
            Application.LoadLevel("Example2WebGUI");
        }

        brect.y += 80;
        if (GUI.Button(brect, "Example 3 - Web Texture"))
        {
            Application.LoadLevel("Example3WebTexture");
        }

        brect.y += 80;
        if (GUI.Button(brect, "Example 4 - Scene"))
        {
            Application.LoadLevel("Example4Scene");
        }

        brect.y += 80;
        if (GUI.Button(brect, "Example 5 - Javascript"))
        {
            Application.LoadLevel("Example5Javascript");
        }

        brect.y += 80;
        if (GUI.Button(brect, "Example 6 - Facebook"))
        {
            Application.LoadLevel("Example6Facebook");
        }

        brect.y += 80;
        if (GUI.Button(brect, "Example 7- Alpha Mask"))
        {
            Application.LoadLevel("Example7AlphaMask");
        }

        brect.y += 80;
        if (GUI.Button(brect, "Clear Cookies"))
        {
            UWKCore.ClearCookies();
        }

        brect.y += 80;
        if (GUI.Button(brect, "Quit"))
        {
            Application.Quit();
        }

        GUI.EndGroup();

        if (UWKCore.BetaVersion)
        {
            GUI.Label(new Rect(0, 0, 200, 60), "UWEBKIT BETA VERSION");
        }
    }
Example #12
0
    void Awake()
    {
        // ensure core is up
        if (!UWKCore.Init())
        {
            return;
        }

        if (createMode)
        {
            URL           = createURL;
            MaxWidth      = createMaxWidth;
            MaxHeight     = createMaxHeight;
            InitialWidth  = createInitialWidth;
            InitialHeight = createInitialHeight;
        }

        if (InitialWidth <= 0)
        {
            InitialWidth = MaxWidth;
        }

        if (InitialHeight <= 0)
        {
            InitialHeight = MaxHeight;
        }

        InitialWidth  = Mathf.Clamp(InitialWidth, 64, 4096);
        InitialHeight = Mathf.Clamp(InitialHeight, 64, 4096);
        MaxWidth      = Mathf.Clamp(MaxWidth, 64, 4096);
        MaxHeight     = Mathf.Clamp(MaxHeight, 64, 4096);

        if (InitialWidth > MaxWidth)
        {
            MaxWidth = InitialWidth;
        }

        if (InitialHeight > MaxHeight)
        {
            MaxHeight = InitialHeight;
        }

        TextureFormat format = TextureFormat.ARGB32;

        if (SystemInfo.graphicsDeviceVersion.IndexOf("Direct3D 11") != -1)
        {
            format = TextureFormat.BGRA32;
        }

        // note that on Direct3D11 shared gpu textures, mipmapping is not allowed
        WebTexture = new Texture2D(MaxWidth, MaxHeight, format, false);

        Color32[] colors = new Color32[MaxWidth * MaxHeight];

        for (int i = 0; i < MaxWidth * MaxHeight; i++)
        {
            colors[i].r = colors[i].g = colors[i].b = colors[i].a = 0;
        }

        WebTexture.SetPixels32(colors);
        WebTexture.Apply();

        width  = InitialWidth;
        height = InitialHeight;

        ID = UWKCore.CreateView(this, InitialWidth, InitialHeight, MaxWidth, MaxHeight, URL, WebTexture.GetNativeTexturePtr());

        // default delegate handlers
        LoadFinished     += loadFinished;
        URLChanged       += urlChanged;
        TitleChanged     += titleChanged;
        LoadStateChanged += loadStateChanged;
        PopupRequested   += popupRequested;

        WebQuery += webQuery;
    }
Example #13
0
 public static void ClearCookies()
 {
     UWKCore.Init();
     UWKPlugin.UWK_ClearCookies();
 }
Example #14
0
    private static void Shutdown()
    {
        if (sInstance == null)
            return;

        sInstance.shutdown ();

        sInstance = null;
    }
Example #15
0
    /// <summary>
    /// Main initialization of web core, must be called before any UWKViews are created.
    /// </summary>
    public static void Init(bool inactivation)
    {
        if (sInstance != null)
            return;

        Application.runInBackground = true;

        string lang = Application.systemLanguage.ToString ();

        #if UNITY_EDITOR || !UNITY_IPHONE
        if (lang == "Chinese" || lang == "Japanese" || lang == "Korean")
            imeEnabled = true;
        #endif

        GameObject go = new GameObject ("UWKCore");

        UnityEngine.Object.DontDestroyOnLoad (go);

        UWKCore core = go.AddComponent<UWKCore> ();

        sInstance = core;
        #if UNITY_EDITOR
        activation = inactivation;
        #endif
        core.init ();
    }
Example #16
0
 /// <summary>
 /// Clears all user cookies
 /// </summary>
 public static void ClearCookies()
 {
     UWKCore.ClearCookies();
 }
Example #17
0
    /// <summary>
    /// Initializes the UWKWebView, registers default delagates, and creates textures for the page and icon
    /// to lack of constructor parameters
    /// </summary>
    void Awake()
    {
        // ensure core is up
        UWKCore.Init();

        if (createMode)
        {
            URL           = createURL;
            MaxWidth      = createMaxWidth;
            MaxHeight     = createMaxHeight;
            CurrentWidth  = MaxWidth;
            CurrentHeight = MaxHeight;
        }

        if (MaxWidth < 64)
        {
            MaxWidth = 64;
        }

        if (MaxHeight < 64)
        {
            MaxHeight = 64;
        }

        if (CurrentWidth > MaxWidth)
        {
            CurrentWidth = MaxWidth;
        }
        if (CurrentHeight > MaxHeight)
        {
            CurrentHeight = MaxHeight;
        }

        maxWidth  = MaxWidth;
        maxHeight = MaxHeight;

        // default delegate handlers
        LoadFinished       += loadFinished;
        URLChanged         += urlChanged;
        TitleChanged       += titleChanged;
        JSConsole          += jsConsole;
        JSMessageReceived  += jsMessageReceived;
        LoadProgress       += loadProgress;
        ContentSizeChanged += contentSizeChanged;
        NewViewRequested   += newViewRequested;

        TextureFormat format = TextureFormat.ARGB32;

        if (SystemInfo.graphicsDeviceVersion.IndexOf("Direct3D 11") != -1)
        {
            format = TextureFormat.BGRA32;
        }

        // note that on Direct3D11 shared gpu textures, mipmapping is not allowed
        WebTexture = new Texture2D(MaxWidth, MaxHeight, format, false);

        Color32[] colors = new Color32[MaxWidth * MaxHeight];

        for (int i = 0; i < MaxWidth * MaxHeight; i++)
        {
            colors[i].r = colors[i].g = colors[i].b = colors[i].a = 0;
        }

        WebTexture.SetPixels32(colors);
        WebTexture.Apply();

        ID = UWKCore.CreateView(this, MaxWidth, MaxHeight, "", WebTexture.GetNativeTexturePtr());
    }
Example #18
0
 void Start()
 {
     // Create the view
     View = UWKCore.CreateView("BasicWebGUI", URL, Width, Height);
 }