Beispiel #1
0
        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;

            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();
        }
Beispiel #2
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");

                // 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);
                }
            }
        }
Beispiel #3
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);
        }
Beispiel #4
0
 public override void OnPluginMsgDirect(JsonObject jsonMsg)
 {
     PluginMsgHandler.getInst().StartCoroutine(PluginsMessageRoutine(jsonMsg));
 }
Beispiel #5
0
 protected virtual void Start()
 {
     nReceiverId = PluginMsgHandler.getInst().RegisterAndGetReceiverId(this);
 }
Beispiel #6
0
 protected JsonObject SendPluginMsg(JsonObject jsonMsg)
 {
     return(PluginMsgHandler.getInst().SendMsgToPlugin(nReceiverId, jsonMsg));
 }
Beispiel #7
0
 protected virtual void OnDestroy()
 {
     PluginMsgHandler.getInst().RemoveReceiver(nReceiverId);
 }