using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
using Snxxz.UI;
|
using LitJson;
|
using System.IO;
|
|
[XLua.LuaCallCSharp]
|
public class DebugUtility : Singleton<DebugUtility>
|
{
|
const string url = "http://pub.game.2460web.com:11000/dbg_player/?";
|
|
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; 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 (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<DebugBranch>(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;
|
}
|
}
|
|
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<string, string>();
|
tables["channel"] = VersionConfig.Get().appId;
|
tables["player"] = ModelCenter.Instance.GetModel<LoginModel>().sdkLoginResult.account;
|
|
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<DebugAuthority>(_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;
|
}
|
|
}
|