using System.Collections; using System.Collections.Generic; using UnityEngine; using LitJson; using System.IO; using UnityEngine.UI; public class DebugUtility : Singleton { GameObject debugRoot; bool m_DebugAccount = false; public bool debugAccount // 是否开启debug模式 { get { return m_DebugAccount; } private set { if (m_DebugAccount != value) { m_DebugAccount = value; // if (m_DebugAccount) // { // RunTimeExceptionUtility.Instance.Init(); // } } } } public int debugBranch = -1; //服务端设置白名单:1.可打开debug模式 2. 可提前登录维护服;缺点需要运维人员配合但安全 //其他参考: 客户端自己设置的debug模式,增加debug文件;缺点:ios无法操作 // 聊天设置分支同时会开启debug模式,优点:任何情况下可以独立操作,不安全但无实质性影响 public bool isWhiteListAccount { get; set; } public void Init() { isWhiteListAccount = false; if (VersionConfig.Get().debugVersion) { debugAccount = true; } else { var parentDirectory = Directory.GetParent(Application.persistentDataPath); debugAccount = File.Exists(parentDirectory + "/Debug"); } if (LocalSave.GetString("#@#BrancH") != string.Empty) { var branch = LocalSave.GetString("#@#BrancH"); int tmpbranch; int.TryParse(LocalSave.GetString("#@#BrancH").Substring(1), out tmpbranch); if (branch.StartsWith("d") && tmpbranch != 0) { debugBranch = tmpbranch; debugAccount = true; } else if (branch.StartsWith("r") && tmpbranch != 0) { debugBranch = tmpbranch; debugAccount = false; } } if (debugAccount) { if (Application.isMobilePlatform) { var parentDirectory = Directory.GetParent(Application.persistentDataPath); if (File.Exists(parentDirectory + "/Debug")) { var content = File.ReadAllText(parentDirectory + "/Debug"); if (!string.IsNullOrEmpty(content)) { var json = JsonMapper.ToObject(File.ReadAllText(parentDirectory + "/Debug")); debugBranch = json.branch; } } } } } public void CreateDebugRoot() { if (debugRoot == null) { var prefab = BuiltInLoader.LoadPrefab("UIRootDebug"); debugRoot = GameObject.Instantiate(prefab); MonoBehaviour.DontDestroyOnLoad(debugRoot); debugRoot.name = "UIRootDebug"; } } public class DebugBranch { public int branch = -1; } }