예제 #1
0
    /// <summary>
    /// Internal Plugin -> Unity message receiving
    /// </summary>
    public static void ProcessMessage(ref UWKMessage msg)
    {
        UWKWebView view = null;

        bool msgView = false;

        switch (msg.type)
        {
        case UWKMessageType.UMSG_VIEW_LOADFINISHED:
        case UWKMessageType.UMSG_VIEW_URLCHANGED:
        case UWKMessageType.UMSG_VIEW_TITLECHANGED:
        case UWKMessageType.UMSG_VIEW_LOADPROGRESS:
        case UWKMessageType.UMSG_VIEW_ICONCHANGED:
        case UWKMessageType.UMSG_JAVASCRIPT_CONSOLE:
        case UWKMessageType.UMSG_JAVASCRIPT_MESSAGE:
        case UWKMessageType.UMSG_VIEW_CONTENTSIZECHANGED:
        case UWKMessageType.UMSG_IME_FOCUSIN:
        case UWKMessageType.UMSG_IME_FOCUSOUT:
        case UWKMessageType.UMSG_VIEW_REQUESTNEWVIEW:
            msgView = true;
            break;
        }

        if (msgView)
        {
            if (!viewLookup.TryGetValue(msg.browserID, out view))
            {
                Debug.Log("Warning: Unable to get view for message: " + Enum.GetName(typeof(UWKMessageType), msg.type));
                return;
            }
        }

        switch (msg.type)
        {
        case UWKMessageType.UMSG_VIEW_LOADFINISHED:
            view.LoadFinished(view);
            break;

        case UWKMessageType.UMSG_VIEW_URLCHANGED:
            view.URLChanged(view, UWKPlugin.GetMessageString(ref msg, 0));
            break;

        case UWKMessageType.UMSG_VIEW_TITLECHANGED:
            view.TitleChanged(view, UWKPlugin.GetMessageString(ref msg, 0));
            break;

        case UWKMessageType.UMSG_VIEW_LOADPROGRESS:
            view.LoadProgress(view, msg.iParams[0]);
            break;

        case UWKMessageType.UMSG_VIEW_ICONCHANGED:

            int size = UWKPlugin.GetMsgDataSize(ref msg, 0);

            if (size > 0)
            {
                byte[] bytes = new byte[size];

                if (UWKPlugin.GetMsgDataBytes(ref msg, 0, size, bytes))
                {
                    view.IconChanged(msg.iParams[0], msg.iParams[1], bytes);
                }
            }

            break;

        case UWKMessageType.UMSG_JAVASCRIPT_CONSOLE:
            view.JSConsole(view, UWKPlugin.GetMessageString(ref msg, 0), msg.iParams[0], UWKPlugin.GetMessageString(ref msg, 1));
            break;

        case UWKMessageType.UMSG_JAVASCRIPT_MESSAGE:
            var json = UWKPlugin.GetMessageString(ref msg, 1);
            var dict = UWKJson.Deserialize(json) as Dictionary <string, object>;
            view.JSMessageReceived(view, UWKPlugin.GetMessageString(ref msg, 0), json, dict);
            break;

        case UWKMessageType.UMSG_VIEW_CONTENTSIZECHANGED:
            view.ContentSizeChanged(view, msg.iParams[0], msg.iParams[1]);
            break;

        case UWKMessageType.UMSG_IME_FOCUSIN:
            view.IMEFocusIn(ref msg);
            break;

        case UWKMessageType.UMSG_IME_FOCUSOUT:
            view.IMEFocusOut();
            break;

        case UWKMessageType.UMSG_VIEW_REQUESTNEWVIEW:
            view.NewViewRequested(view, UWKPlugin.GetMessageString(ref msg, 0));
            break;

        case UWKMessageType.UMSG_ACTIVATION_STATE:
            #if UNITY_EDITOR
            if (msg.iParams[0] != 1 && msg.iParams[0] != 5)
            {
                if (sInstance.gameObject.GetComponent <UWKActivation>() == null)
                {
                    sInstance.gameObject.AddComponent <UWKActivation>();
                }
            }
            UWKActivation.SetActivationState(msg.iParams[0]);
            #endif

            break;
        }
    }