using System.Collections; using System.Collections.Generic; using UnityEngine; using vnxbqy.UI; using LitJson; using System.IO; using UnityEngine.UI; public class DebugUtility : Singleton { GameObject debugRoot; bool m_DebugAccount = false; public bool debugAccount { get { return m_DebugAccount; } private set { if (m_DebugAccount != value) { m_DebugAccount = value; if (m_DebugAccount) { RunTimeExceptionUtility.Instance.Init(); } } } } public int debugBranch = -1; public bool isWhiteListAccount { get; set; } public bool autoLogin { get; private 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; } } } } if (debugAccount) { DebugEx.EnableLog = LocalSave.GetBool("DesignEnableLog", true); DebugEx.EnableLogWarning = LocalSave.GetBool("DesignEnableLogWarning", true); DebugEx.EnableLogError = LocalSave.GetBool("DesignEnableLogError", true); DebugEx.EnableNetLog = false; } else { DebugEx.EnableLog = false; DebugEx.EnableLogWarning = false; DebugEx.EnableLogError = false; DebugEx.EnableNetLog = false; } autoLogin = Resources.Load("AutoLogin") != null; if (autoLogin) { var update = new LogicUpdate(3f); update.Start(OnAutoLoginUpdate); } } private void OnAutoLoginUpdate() { if (StageLoad.Instance.currentStage is LoginStage) { var loginWin = WindowCenter.Instance.Get(); if (loginWin != null) { var accountIpf = loginWin.transform.FindComponent("InputField", "Container_Account/AccountInput"); if (accountIpf != null) { (accountIpf as InputField).text = StringUtility.Contact("Test_", UnityEngine.Random.Range(10000, 99999)); } var enterGame = loginWin.transform.FindComponent("Button", "Container_EnterGame/LoginButton"); (enterGame as Button).onClick.Invoke(); } } if (StageLoad.Instance.currentStage is CreateRoleStage) { var win = WindowCenter.Instance.Get(); if (win != null) { var enterGame = win.transform.FindComponent("Button", "Container_Right/Btn_CreateRole"); if (enterGame is Button) { (enterGame as Button).onClick.Invoke(); } } } } public void CreateDebugRoot() { if (debugRoot == null) { var prefab = BuiltInLoader.LoadPrefab("UIRootDebug"); debugRoot = GameObject.Instantiate(prefab); MonoBehaviour.DontDestroyOnLoad(debugRoot); debugRoot.name = "UIRootDebug"; } } public void RequestWhiteListAuthority(string _account) { //isWhiteListAccount = false; //var tables = new Dictionary(); //tables["channel"] = VersionConfig.Get().appId; //tables["player"] = ModelCenter.Instance.GetModel().sdkLoginResult.account; //tables["game"] = VersionConfig.Get().gameId; //HttpRequest.Instance.RequestHttpGet(StringUtility.Contact(url, HttpRequest.HashtablaToString(tables)), HttpRequest.defaultHttpContentType, 1, OnDebugAuthority); } private void OnDebugAuthority(bool _ok, string _result) { if (_ok) { var debugAuthority = JsonMapper.ToObject(_result); isWhiteListAccount = debugAuthority.dbg == 1; } } public static void SetLogAble(bool _able) { LocalSave.SetBool("DesignEnableLog", _able); DebugEx.EnableLog = _able; } public static void SetLogWarningAble(bool _able) { LocalSave.SetBool("DesignEnableLogWarning", _able); DebugEx.EnableLogWarning = _able; } public static void SetLogErrorAble(bool _able) { LocalSave.SetBool("DesignEnableLogError", _able); DebugEx.EnableLogError = _able; } public static void SetLogNetAble(bool _able) { DebugEx.EnableNetLog = _able; } struct DebugAuthority { public int dbg; } public class DebugBranch { public int branch = -1; } }