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); } }
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); } } }
public static PluginMsgHandler GetInstanceForReceiver(PluginMsgReceiver receiver) { if (_instance == null) { GameObject handlerObject = new GameObject(DEFAULT_NAME); _instance = handlerObject.AddComponent <PluginMsgHandler>(); } return(_instance); }
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."); } }
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); }
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(); }
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(); } } }
protected void Start() { nReceiverId = PluginMsgHandler.getInst().RegisterAndGetReceiverId(this); }
public override void OnPluginMsgDirect(JsonObject jsonMsg) { PluginMsgHandler.getInst().StartCoroutine(this.HandlePluginMessageOnNextFrame(jsonMsg)); }
public override void OnPluginMsgDirect(JsonObject jsonMsg) { PluginMsgHandler.getInst().StartCoroutine(PluginsMessageRoutine(jsonMsg)); }
protected JsonObject SendPluginMsg(JsonObject jsonMsg) { return(PluginMsgHandler.getInst().SendMsgToPlugin(nReceiverId, jsonMsg)); }
protected void OnDestroy() { PluginMsgHandler.getInst().RemoveReceiver(nReceiverId); }
void OnDestroy() { this.FinalizeHandler(); _instance = null; }
private void OnDestroy() { FinalizeHandler(); _instance = null; }
protected JsonObject SendPluginMsg(JsonObject jsonMsg) { return(PluginMsgHandler.GetInstanceForReceiver(this).SendMsgToPlugin(_receiverId, jsonMsg)); }
protected virtual void OnDestroy() { PluginMsgHandler.GetInstanceForReceiver(this).RemoveReceiver(_receiverId); }
protected virtual void Start() { _receiverId = PluginMsgHandler.GetInstanceForReceiver(this).RegisterAndGetReceiverId(this); }
public override void OnPluginMsgDirect(JsonObject jsonMsg) { PluginMsgHandler.GetInstanceForReceiver(this).StartCoroutine(PluginsMessageRoutine(jsonMsg)); }
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(); }