| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- namespace SmartBowLib
- {
- /*
- * 接收来自安卓层的信息
- */
- public class MsgReceiver : MonoBehaviour
- {
- private static MsgReceiver _ins;
- public static MsgReceiver ins {
- get {
- if (!_ins) {
- GameObject o = new GameObject("MsgReceiver");
- _ins = o.AddComponent<MsgReceiver>();
- DontDestroyOnLoad(o);
- }
- return _ins;
- }
- }
- public void Log(string info)
- {
- Debug.Log("[MsgReceiver] " + info);
- }
- public void Warn(string info)
- {
- Debug.LogWarning("[MsgReceiver] " + info);
- }
- public void Error(string info)
- {
- Debug.LogError("[MsgReceiver] " + info);
- }
- public void OnMessage(string msg)
- {
- Debug.Log("[MsgReceiver] OnMessage: " + msg);
- int startIndex = 0;
- int len = msg.IndexOf("|");
- string tag = msg.Substring(startIndex, len);
- startIndex += len + 1;
- len = msg.Length - startIndex;
- string content = "";
- if (len > 0) content = msg.Substring(startIndex, len);
- onMessage?.Invoke(tag, content);
- }
- public Action<string, string> onMessage;
- public void OnLocationUpdate(string msg)
- {
- #if UNITY_ANDROID
- GPSTool.OnLocationUpdate();
- #endif
- }
- }
- }
|