yyl
2 天以前 5d3366f2e0f687995eb7ad2107c4379fe7acd4e8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using LitJson;
using System.IO;
using UnityEngine.UI;
 
 
public class DebugUtility : Singleton<DebugUtility>
{
 
    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<DebugBranch>(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;
    }
 
}