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(); 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 onMessage; public void OnLocationUpdate(string msg) { #if UNITY_ANDROID GPSTool.OnLocationUpdate(); #endif } } }