예제 #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);
        }
    }
예제 #2
0
 protected virtual void OnDestroy()
 {
     if (nReceiverId != null)
     {
         PluginMsgHandler.getInst().RemoveReceiver((int)nReceiverId);
     }
 }
    void Awake()
    {
        // Don't destroy on load and make sure there is only one instance existing. Without this the
        // events didn't seem to work after a scene reload.
        if (instance != null)
        {
            Destroy(gameObject);
            return;
        }
        instance = gameObject;

        // If instantiated in a non-root object (e.g. Zenject ProjectContext subcontainer),
        // Don't use DontDestroyOnLoad
        if (gameObject.transform.parent == null)
        {
            DontDestroyOnLoad(gameObject);
        }

        int tempRandom = (int)UnityEngine.Random.Range(0, 10000.0f);

        this.name = DEFAULT_NAME + tempRandom.ToString();

        if (ENABLE_WRITE_LOG)
        {
            string fileName = Application.persistentDataPath + "/unity_app.log";
            fileWriter = File.CreateText(fileName);
            fileWriter.WriteLine("[LogWriter] Initialized");
            Debug.Log(string.Format("log location {0}", fileName));
        }
        inst = this;
        this.InitializeHandler();
    }
    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);
            }
        }
    }
예제 #5
0
 public static PluginMsgHandler GetInstanceForReceiver(PluginMsgReceiver receiver)
 {
     if (_instance == null)
     {
         GameObject handlerObject = new GameObject(DEFAULT_NAME);
         _instance = handlerObject.AddComponent <PluginMsgHandler>();
     }
     return(_instance);
 }
예제 #6
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.");
     }
 }
예제 #7
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);
    }
예제 #8
0
    void Awake()
    {
        int tempRandom = (int)UnityEngine.Random.Range(0, 10000.0f);

        this.name = DEFAULT_NAME + tempRandom.ToString();

        if (ENABLE_WRITE_LOG)
        {
            string fileName = Application.persistentDataPath + "/unity_app.log";
            fileWriter = File.CreateText(fileName);
            fileWriter.WriteLine("[LogWriter] Initialized");
            Debug.Log(string.Format("log location {0}", fileName));
        }
        inst = this;
        this.InitializeHandler();
    }
예제 #9
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();
            }
        }
    }
예제 #10
0
 protected void Start()
 {
     nReceiverId = PluginMsgHandler.getInst().RegisterAndGetReceiverId(this);
 }
예제 #11
0
 public override void OnPluginMsgDirect(JsonObject jsonMsg)
 {
     PluginMsgHandler.getInst().StartCoroutine(this.HandlePluginMessageOnNextFrame(jsonMsg));
 }
예제 #12
0
 public override void OnPluginMsgDirect(JsonObject jsonMsg)
 {
     PluginMsgHandler.getInst().StartCoroutine(PluginsMessageRoutine(jsonMsg));
 }
예제 #13
0
 protected JsonObject SendPluginMsg(JsonObject jsonMsg)
 {
     return(PluginMsgHandler.getInst().SendMsgToPlugin(nReceiverId, jsonMsg));
 }
예제 #14
0
 protected void OnDestroy()
 {
     PluginMsgHandler.getInst().RemoveReceiver(nReceiverId);
 }
예제 #15
0
 void OnDestroy()
 {
     this.FinalizeHandler();
     _instance = null;
 }
예제 #16
0
 private void OnDestroy()
 {
     FinalizeHandler();
     _instance = null;
 }
예제 #17
0
 protected JsonObject SendPluginMsg(JsonObject jsonMsg)
 {
     return(PluginMsgHandler.GetInstanceForReceiver(this).SendMsgToPlugin(_receiverId, jsonMsg));
 }
예제 #18
0
 protected virtual void OnDestroy()
 {
     PluginMsgHandler.GetInstanceForReceiver(this).RemoveReceiver(_receiverId);
 }
예제 #19
0
 protected virtual void Start()
 {
     _receiverId = PluginMsgHandler.GetInstanceForReceiver(this).RegisterAndGetReceiverId(this);
 }
예제 #20
0
 public override void OnPluginMsgDirect(JsonObject jsonMsg)
 {
     PluginMsgHandler.GetInstanceForReceiver(this).StartCoroutine(PluginsMessageRoutine(jsonMsg));
 }
예제 #21
0
    void Awake()
    {
        int tempRandom = (int) UnityEngine.Random.Range(0, 10000.0f);
        this.name = DEFAULT_NAME + tempRandom.ToString();

        if (ENABLE_WRITE_LOG)
        {
            string fileName = Application.persistentDataPath + "/unity_app.log";
            fileWriter = File.CreateText(fileName);
            fileWriter.WriteLine("[LogWriter] Initialized");
            Debug.Log(string.Format("log location {0}", fileName));
        }
        inst = this;
        this.InitializeHandler();
    }