예제 #1
0
    private void OnMsgFromPlugin(string jsonPluginMsg)
    {
        if (jsonPluginMsg == null)
        {
            return;
        }

        JsonObject jsonMsg = new JsonObject(jsonPluginMsg);

        string msg = jsonMsg.GetString("msg");

        if (msg.Equals(MSG_SHOW_KEYBOARD))
        {
            bool bShow      = jsonMsg.GetBool("show");
            int  nKeyHeight = (int)(jsonMsg.GetFloat("keyheight") * (float)Screen.height);
            //FileLog(string.Format("keyshow {0} height {1}", bShow, nKeyHeight));
            if (OnShowKeyboard != null)
            {
                OnShowKeyboard(bShow, nKeyHeight);
            }
        }
        else
        {
            int nSenderId = jsonMsg.GetInt("senderId");
            PluginMsgReceiver receiver = PluginMsgHandler.getInst().GetReceiver(nSenderId);
            receiver.OnPluginMsgDirect(jsonMsg);
        }
    }
    private void OnMsgFromPlugin(string jsonPluginMsg)
    {
        if (jsonPluginMsg == null)
        {
            return;
        }

        JsonObject jsonMsg = new JsonObject(jsonPluginMsg);

        string msg = jsonMsg.GetString("msg");

        if (msg.Equals(MSG_SHOW_KEYBOARD))
        {
            bool bShow      = jsonMsg.GetBool("show");
            int  nKeyHeight = (int)(jsonMsg.GetFloat("keyheight") * (float)Screen.height);
            //FileLog(string.Format("keyshow {0} height {1}", bShow, nKeyHeight));
            if (OnShowKeyboard != null)
            {
                OnShowKeyboard(bShow, nKeyHeight);
            }
        }
        else
        {
            int nSenderId = jsonMsg.GetInt("senderId");

            // In some cases the receiver might be already removed, for example if a button is pressed
            // that will destoy the receiver while the input field is focused an end editing message
            // will be sent from the plugin after the receiver is already destroyed on Unity side.
            if (m_dictReceiver.ContainsKey(nSenderId))
            {
                PluginMsgReceiver receiver = PluginMsgHandler.getInst().GetReceiver(nSenderId);
                receiver.OnPluginMsgDirect(jsonMsg);
            }
        }
    }
예제 #3
0
 protected virtual void OnDestroy()
 {
     if (nReceiverId != null)
     {
         PluginMsgHandler.getInst().RemoveReceiver((int)nReceiverId);
     }
 }
예제 #4
0
    private bool CheckErrorJsonRet(JsonObject jsonRet)
    {
        bool   bError   = jsonRet.GetBool("bError");
        string strError = jsonRet.GetString("strError");

        if (bError)
        {
            PluginMsgHandler.getInst().FileLogError(string.Format("NativeEditbox error {0}", strError));
        }
        return(bError);
    }
예제 #5
0
 protected JsonObject SendPluginMsg(JsonObject jsonMsg)
 {
     if (nReceiverId != null)
     {
         return(PluginMsgHandler.getInst().SendMsgToPlugin((int)nReceiverId, jsonMsg));
     }
     else
     {
         throw new System.InvalidOperationException("Attempted to send a NativeEdit plugin msg for a PluginMsgReceiver that has not been initialized.");
     }
 }
예제 #6
0
    private IEnumerator PluginsMessageRoutine(JsonObject jsonMsg)
    {
        // this is to avoid a deadlock for more info when trying to get data from two separate native plugins and handling them in Unity
        yield return(null);

        string msg = jsonMsg.GetString("msg");

        if (msg.Equals(MSG_TEXT_CHANGE))
        {
            string text = jsonMsg.GetString("text");
            this.onTextChange(text);
        }
        else if (msg.Equals(MSG_TEXT_BEGIN_EDIT))
        {
            PluginMsgHandler.getInst().currentSelectedInput = this;
            if (this.OnBeginEditing != null)
            {
                this.OnBeginEditing.Invoke();
            }
        }
        else if (msg.Equals(MSG_TEXT_END_EDIT))
        {
            string text = jsonMsg.GetString("text");
            this.onTextEditEnd(text);
        }
        else if (msg.Equals(MSG_RETURN_PRESSED))
        {
            if (this.unsetFocusOnReturn)
            {
                this.SetFocus(false);
            }
            if (returnPressed != null)
            {
                returnPressed();
            }
            if (OnReturnPressed != null)
            {
                OnReturnPressed.Invoke();
            }
        }
    }
예제 #7
0
 public override void OnPluginMsgDirect(JsonObject jsonMsg)
 {
     PluginMsgHandler.getInst().StartCoroutine(this.HandlePluginMessageOnNextFrame(jsonMsg));
 }
예제 #8
0
 public override void OnPluginMsgDirect(JsonObject jsonMsg)
 {
     PluginMsgHandler.getInst().StartCoroutine(PluginsMessageRoutine(jsonMsg));
 }
예제 #9
0
 protected JsonObject SendPluginMsg(JsonObject jsonMsg)
 {
     return(PluginMsgHandler.getInst().SendMsgToPlugin(nReceiverId, jsonMsg));
 }
예제 #10
0
 protected void OnDestroy()
 {
     PluginMsgHandler.getInst().RemoveReceiver(nReceiverId);
 }
예제 #11
0
 protected void Start()
 {
     nReceiverId = PluginMsgHandler.getInst().RegisterAndGetReceiverId(this);
 }