yyl
2026-03-31 0fa617a09eedf6bdb25eda55fac1d3344859fd93
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using LitJson;
using System.IO;
using UnityEngine.UI;
using Cysharp.Threading.Tasks;
 
 
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;
        VersionConfig.GetAsync().ContinueWith(config =>
        {
            if (config != null && config.debugVersion)
            {
                debugAccount = true;
            }
            else
            {
#if !UNITY_WEBGL
                var parentDirectory = Directory.GetParent(Application.persistentDataPath);
                debugAccount = File.Exists(parentDirectory + "/Debug");
#else
                debugAccount = false;
#endif
            }
 
            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 !UNITY_WEBGL
                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;
                        }
                    }
                }
#endif
            }
        }).Forget();
        
 
 
    }
 
 
    public async UniTask CreateDebugRoot()
    {
        if (debugRoot == null)
        {
            var prefab = await BuiltInLoader.LoadPrefabAsync("UIRootDebug");
            debugRoot = GameObject.Instantiate(prefab);
            MonoBehaviour.DontDestroyOnLoad(debugRoot);
            debugRoot.name = "UIRootDebug";
        }
    }
 
    public async UniTask CreateDebugRootAsync()
    {
        if (debugRoot == null)
        {
            var prefab = await BuiltInLoader.LoadPrefabAsync("UIRootDebug");
            debugRoot = GameObject.Instantiate(prefab);
            MonoBehaviour.DontDestroyOnLoad(debugRoot);
            debugRoot.name = "UIRootDebug";
        }
    }
 
 
    public class DebugBranch
    {
        public int branch = -1;
    }
 
}