Bläddra i källkod

添加Debug工具

taochangchun 1 vecka sedan
förälder
incheckning
2447cac329
35 ändrade filer med 6001 tillägg och 70 borttagningar
  1. 1 1
      Editor/CreateScript/Template/UIBaseScript.txt
  2. 4 0
      Editor/Inspector/MianInspector.cs
  3. 31 0
      Editor/Inspector/UIBehaviourInspector.cs
  4. 8 0
      Editor/Tool/Preference.cs
  5. 1 0
      Editor/Tool/PreferenceExecutor.cs
  6. 1 1
      Editor/UserInfo/UserData.asset.meta
  7. 3432 0
      Resources/UI/Console.prefab
  8. 2 3
      Editor/Data/PreferenceData.asset.meta
  9. 1628 0
      Resources/UI/DebugPanel.prefab
  10. 7 0
      Resources/UI/DebugPanel.prefab.meta
  11. BIN
      Resources/gantanhao.png
  12. 147 0
      Resources/gantanhao.png.meta
  13. BIN
      Resources/调试图标.png
  14. 147 0
      Resources/调试图标.png.meta
  15. 8 0
      Runtime/Scripts/Debug/Component.meta
  16. 12 0
      Runtime/Scripts/Debug/Component/BaseComponent.cs
  17. 11 0
      Runtime/Scripts/Debug/Component/BaseComponent.cs.meta
  18. 155 0
      Runtime/Scripts/Debug/Component/Console.cs
  19. 11 0
      Runtime/Scripts/Debug/Component/Console.cs.meta
  20. 22 0
      Runtime/Scripts/Debug/Component/ConsoleLog.cs
  21. 11 0
      Runtime/Scripts/Debug/Component/ConsoleLog.cs.meta
  22. 32 0
      Runtime/Scripts/Debug/DebugComponent.cs
  23. 11 0
      Runtime/Scripts/Debug/DebugComponent.cs.meta
  24. 14 1
      Runtime/Scripts/Debug/DebugPanel.Designer.cs
  25. 62 4
      Runtime/Scripts/Debug/DebugPanel.cs
  26. 42 0
      Runtime/Scripts/Debug/DragIcon.cs
  27. 11 0
      Runtime/Scripts/Debug/DragIcon.cs.meta
  28. 22 2
      Runtime/Scripts/Main/Main.cs
  29. 2 0
      Runtime/Scripts/Net/NetHelper.cs
  30. 23 8
      Runtime/Scripts/Resource/ResourceManager.cs
  31. 21 2
      Runtime/Scripts/UI/BasePanel.cs
  32. 67 47
      Runtime/Scripts/UI/FixScreenRatio.cs
  33. 15 0
      Runtime/Scripts/UI/UIBehaviour.cs
  34. 4 1
      Runtime/Scripts/UI/UIManager.cs
  35. 36 0
      Runtime/Scripts/Utility/GlobalTool.cs

+ 1 - 1
Editor/CreateScript/Template/UIBaseScript.txt

@@ -28,7 +28,7 @@ public partial class #ClassName :BasePanel
28 28
         base.OnEnter(args);
29 29
     }
30 30
 
31
-    public override void OnExit(IPanelData args = null)
31
+    public override void OnExit(IPanelData args = null,bool isDestroy=false)
32 32
     {
33 33
         base.OnExit(args);
34 34
     }

+ 4 - 0
Editor/Inspector/MianInspector.cs

@@ -11,10 +11,12 @@ public class MianInspector:TEditor
11 11
 {
12 12
     private SerializedProperty _doNotDestroy;
13 13
     private SerializedProperty _ManagerList;
14
+    private SerializedProperty _IsEnableDebug;
14 15
     private ReorderableList _managerReorderable;
15 16
 
16 17
     private GUIContent dndGC = new GUIContent("跳场景不销毁");
17 18
     private GUIContent mListGC = new GUIContent("管理器注册表");
19
+    private GUIContent dbGC = new GUIContent("启用Debug工具");
18 20
     List<BaseManager> monos = new List<BaseManager>();
19 21
     List<Type> magTypes;
20 22
 
@@ -22,6 +24,7 @@ public class MianInspector:TEditor
22 24
     {
23 25
         _doNotDestroy = serializedObject.FindProperty("doNotDestroy");
24 26
         _ManagerList = serializedObject.FindProperty("m_ManagerList");
27
+        _IsEnableDebug = serializedObject.FindProperty("IsEnableDebug");
25 28
         _managerReorderable = new ReorderableList(serializedObject, _ManagerList);
26 29
 
27 30
         magTypes = GlobalTool.GetTypesInRunTimeAssemblies(type =>
@@ -81,6 +84,7 @@ public class MianInspector:TEditor
81 84
         serializedObject.Update();
82 85
         EditorGUILayout.PropertyField(_doNotDestroy,dndGC);
83 86
         _managerReorderable.DoLayoutList();
87
+        EditorGUILayout.PropertyField(_IsEnableDebug,dbGC);
84 88
         serializedObject.ApplyModifiedProperties();
85 89
     }
86 90
 }

+ 31 - 0
Editor/Inspector/UIBehaviourInspector.cs

@@ -20,6 +20,8 @@ namespace TFramework
20 20
         SerializedProperty parnetPanel;
21 21
         Component[] behaviours;
22 22
         ReorderableList variableList;
23
+        SerializedProperty useResInfos;
24
+        ReorderableList useResList;
23 25
 
24 26
         List<string> anims = new List<string>();
25 27
         int select = 0;
@@ -41,6 +43,7 @@ namespace TFramework
41 43
             isScriptUse = serializedObject.FindProperty("isScriptUse");
42 44
             variableInfos = serializedObject.FindProperty("variableInfos");
43 45
             parnetPanel = serializedObject.FindProperty("parnetPanel");
46
+            useResInfos = serializedObject.FindProperty("useResInfos");
44 47
 
45 48
             if (string.IsNullOrEmpty(m_id.stringValue))
46 49
             {
@@ -226,6 +229,33 @@ namespace TFramework
226 229
                 AssetDatabase.Refresh();
227 230
                 ReorderableList.defaultBehaviours.DoRemoveButton(list);
228 231
             };
232
+
233
+            useResList = new ReorderableList(serializedObject, useResInfos, false, true, true, true);
234
+            useResList.drawHeaderCallback = rect =>
235
+            {
236
+                GUI.Label(rect, "使用资源列表");
237
+            };
238
+            useResList.drawElementCallback = (rect, index, isActive, isFocused) =>
239
+            {
240
+                SerializedProperty property = useResInfos.GetArrayElementAtIndex(index);
241
+                SerializedProperty resObj = property.FindPropertyRelative("resObj");
242
+                SerializedProperty resName = property.FindPropertyRelative("resName");
243
+                float width = rect.width / 2;
244
+                rect.width = 63;
245
+                GUI.Label(rect, "资源名:");
246
+                rect.x += 63;
247
+                rect.width = width - 63;
248
+                resName.stringValue = EditorGUI.TextField(rect, resName.stringValue);
249
+                
250
+                rect.x += rect.width + 3;
251
+                rect.width = 43;
252
+                GUI.Label(rect, "资源:");
253
+                rect.x += 43;
254
+                rect.width = width - 40;
255
+                resObj.objectReferenceValue = EditorGUI.ObjectField(rect, resObj.objectReferenceValue, typeof(Object), true);
256
+            };
257
+
258
+
229 259
             if (!string.IsNullOrEmpty(parnetPanel.stringValue))
230 260
                 scriptText = AssetDatabase.LoadAssetAtPath<TextAsset>(scriptPathDic[parnetPanel.stringValue]).text;
231 261
         }
@@ -275,6 +305,7 @@ namespace TFramework
275 305
                     variableList.DoLayoutList();
276 306
                 }
277 307
             }
308
+            useResList.DoLayoutList();
278 309
             serializedObject.ApplyModifiedProperties();
279 310
         }
280 311
     }

+ 8 - 0
Editor/Tool/Preference.cs

@@ -28,10 +28,17 @@ namespace TFramework
28 28
         private void OnEnable()
29 29
         {
30 30
             preferenceData = AssetDatabase.LoadAssetAtPath<PreferenceData>(DATAPATH);
31
+            if(preferenceData == null )
32
+            {
33
+                preferenceData = CreateInstance<PreferenceData>();
34
+                AssetDatabase.CreateAsset(preferenceData, DATAPATH);
35
+                AssetDatabase.SaveAssets();
36
+            }
31 37
         }
32 38
 
33 39
         private void OnGUI()
34 40
         {
41
+            if (preferenceData == null) return;
35 42
             using(new EditorGUILayout.HorizontalScope())
36 43
             {
37 44
                 GUILayout.Label("自动保存");
@@ -81,6 +88,7 @@ namespace TFramework
81 88
 
82 89
         private void SaveData()
83 90
         {
91
+            if (preferenceData == null) return;
84 92
             EditorUtility.SetDirty(preferenceData);
85 93
             AssetDatabase.SaveAssets();
86 94
         }

+ 1 - 0
Editor/Tool/PreferenceExecutor.cs

@@ -46,6 +46,7 @@ namespace TFramework
46 46
         [RuntimeInitializeOnLoadMethod]
47 47
         private static void OnEditorRunTime()
48 48
         {
49
+            if (preferenceData == null) return;
49 50
             if (preferenceData.m_isAlwaysFormAssignScene)
50 51
                 if (!string.IsNullOrEmpty(preferenceData.m_assignScene) && SceneManager.GetActiveScene().path != preferenceData.m_assignScene)
51 52
                 {

+ 1 - 1
Editor/UserInfo/UserData.asset.meta

@@ -1,5 +1,5 @@
1 1
 fileFormatVersion: 2
2
-guid: 8c9bb4c17e498c64795a47665878144c
2
+guid: be8d41c132cdeb04bbf228513b4e7f03
3 3
 NativeFormatImporter:
4 4
   externalObjects: {}
5 5
   mainObjectFileID: 11400000

Filskillnaden har hållts tillbaka eftersom den är för stor
+ 3432 - 0
Resources/UI/Console.prefab


+ 2 - 3
Editor/Data/PreferenceData.asset.meta

@@ -1,8 +1,7 @@
1 1
 fileFormatVersion: 2
2
-guid: e6cf376989d7df349858d35d364f9378
3
-NativeFormatImporter:
2
+guid: 84359794051c0d5479df5bec1a9d6078
3
+PrefabImporter:
4 4
   externalObjects: {}
5
-  mainObjectFileID: 11400000
6 5
   userData: 
7 6
   assetBundleName: 
8 7
   assetBundleVariant: 

Filskillnaden har hållts tillbaka eftersom den är för stor
+ 1628 - 0
Resources/UI/DebugPanel.prefab


+ 7 - 0
Resources/UI/DebugPanel.prefab.meta

@@ -0,0 +1,7 @@
1
+fileFormatVersion: 2
2
+guid: 5c53e66f64c90a846bf233e970d55636
3
+PrefabImporter:
4
+  externalObjects: {}
5
+  userData: 
6
+  assetBundleName: 
7
+  assetBundleVariant: 

BIN
Resources/gantanhao.png


+ 147 - 0
Resources/gantanhao.png.meta

@@ -0,0 +1,147 @@
1
+fileFormatVersion: 2
2
+guid: 75a5a3ebeafb90e4cbac695e54f3fc66
3
+TextureImporter:
4
+  internalIDToNameTable: []
5
+  externalObjects: {}
6
+  serializedVersion: 12
7
+  mipmaps:
8
+    mipMapMode: 0
9
+    enableMipMap: 1
10
+    sRGBTexture: 1
11
+    linearTexture: 0
12
+    fadeOut: 0
13
+    borderMipMap: 0
14
+    mipMapsPreserveCoverage: 0
15
+    alphaTestReferenceValue: 0.5
16
+    mipMapFadeDistanceStart: 1
17
+    mipMapFadeDistanceEnd: 3
18
+  bumpmap:
19
+    convertToNormalMap: 0
20
+    externalNormalMap: 0
21
+    heightScale: 0.25
22
+    normalMapFilter: 0
23
+  isReadable: 0
24
+  streamingMipmaps: 0
25
+  streamingMipmapsPriority: 0
26
+  vTOnly: 0
27
+  ignoreMasterTextureLimit: 0
28
+  grayScaleToAlpha: 0
29
+  generateCubemap: 6
30
+  cubemapConvolution: 0
31
+  seamlessCubemap: 0
32
+  textureFormat: 1
33
+  maxTextureSize: 2048
34
+  textureSettings:
35
+    serializedVersion: 2
36
+    filterMode: 1
37
+    aniso: 1
38
+    mipBias: 0
39
+    wrapU: 0
40
+    wrapV: 0
41
+    wrapW: 0
42
+  nPOTScale: 0
43
+  lightmap: 0
44
+  compressionQuality: 50
45
+  spriteMode: 1
46
+  spriteExtrude: 1
47
+  spriteMeshType: 1
48
+  alignment: 0
49
+  spritePivot: {x: 0.5, y: 0.5}
50
+  spritePixelsToUnits: 100
51
+  spriteBorder: {x: 0, y: 0, z: 0, w: 0}
52
+  spriteGenerateFallbackPhysicsShape: 1
53
+  alphaUsage: 1
54
+  alphaIsTransparency: 0
55
+  spriteTessellationDetail: -1
56
+  textureType: 8
57
+  textureShape: 1
58
+  singleChannelComponent: 0
59
+  flipbookRows: 1
60
+  flipbookColumns: 1
61
+  maxTextureSizeSet: 0
62
+  compressionQualitySet: 0
63
+  textureFormatSet: 0
64
+  ignorePngGamma: 0
65
+  applyGammaDecoding: 0
66
+  cookieLightType: 0
67
+  platformSettings:
68
+  - serializedVersion: 3
69
+    buildTarget: DefaultTexturePlatform
70
+    maxTextureSize: 2048
71
+    resizeAlgorithm: 0
72
+    textureFormat: -1
73
+    textureCompression: 1
74
+    compressionQuality: 50
75
+    crunchedCompression: 0
76
+    allowsAlphaSplitting: 0
77
+    overridden: 0
78
+    androidETC2FallbackOverride: 0
79
+    forceMaximumCompressionQuality_BC6H_BC7: 0
80
+  - serializedVersion: 3
81
+    buildTarget: Standalone
82
+    maxTextureSize: 2048
83
+    resizeAlgorithm: 0
84
+    textureFormat: -1
85
+    textureCompression: 1
86
+    compressionQuality: 50
87
+    crunchedCompression: 0
88
+    allowsAlphaSplitting: 0
89
+    overridden: 0
90
+    androidETC2FallbackOverride: 0
91
+    forceMaximumCompressionQuality_BC6H_BC7: 0
92
+  - serializedVersion: 3
93
+    buildTarget: Server
94
+    maxTextureSize: 2048
95
+    resizeAlgorithm: 0
96
+    textureFormat: -1
97
+    textureCompression: 1
98
+    compressionQuality: 50
99
+    crunchedCompression: 0
100
+    allowsAlphaSplitting: 0
101
+    overridden: 0
102
+    androidETC2FallbackOverride: 0
103
+    forceMaximumCompressionQuality_BC6H_BC7: 0
104
+  - serializedVersion: 3
105
+    buildTarget: Android
106
+    maxTextureSize: 2048
107
+    resizeAlgorithm: 0
108
+    textureFormat: -1
109
+    textureCompression: 1
110
+    compressionQuality: 50
111
+    crunchedCompression: 0
112
+    allowsAlphaSplitting: 0
113
+    overridden: 0
114
+    androidETC2FallbackOverride: 0
115
+    forceMaximumCompressionQuality_BC6H_BC7: 0
116
+  - serializedVersion: 3
117
+    buildTarget: WebGL
118
+    maxTextureSize: 2048
119
+    resizeAlgorithm: 0
120
+    textureFormat: -1
121
+    textureCompression: 1
122
+    compressionQuality: 50
123
+    crunchedCompression: 0
124
+    allowsAlphaSplitting: 0
125
+    overridden: 0
126
+    androidETC2FallbackOverride: 0
127
+    forceMaximumCompressionQuality_BC6H_BC7: 0
128
+  spriteSheet:
129
+    serializedVersion: 2
130
+    sprites: []
131
+    outline: []
132
+    physicsShape: []
133
+    bones: []
134
+    spriteID: 5e97eb03825dee720800000000000000
135
+    internalID: 0
136
+    vertices: []
137
+    indices: 
138
+    edges: []
139
+    weights: []
140
+    secondaryTextures: []
141
+    nameFileIdTable: {}
142
+  spritePackingTag: 
143
+  pSDRemoveMatte: 0
144
+  pSDShowRemoveMatteOption: 0
145
+  userData: 
146
+  assetBundleName: 
147
+  assetBundleVariant: 

BIN
Resources/调试图标.png


+ 147 - 0
Resources/调试图标.png.meta

@@ -0,0 +1,147 @@
1
+fileFormatVersion: 2
2
+guid: 6fb18b2b72fa4c44fa4a461226731adc
3
+TextureImporter:
4
+  internalIDToNameTable: []
5
+  externalObjects: {}
6
+  serializedVersion: 12
7
+  mipmaps:
8
+    mipMapMode: 0
9
+    enableMipMap: 1
10
+    sRGBTexture: 1
11
+    linearTexture: 0
12
+    fadeOut: 0
13
+    borderMipMap: 0
14
+    mipMapsPreserveCoverage: 0
15
+    alphaTestReferenceValue: 0.5
16
+    mipMapFadeDistanceStart: 1
17
+    mipMapFadeDistanceEnd: 3
18
+  bumpmap:
19
+    convertToNormalMap: 0
20
+    externalNormalMap: 0
21
+    heightScale: 0.25
22
+    normalMapFilter: 0
23
+  isReadable: 0
24
+  streamingMipmaps: 0
25
+  streamingMipmapsPriority: 0
26
+  vTOnly: 0
27
+  ignoreMasterTextureLimit: 0
28
+  grayScaleToAlpha: 0
29
+  generateCubemap: 6
30
+  cubemapConvolution: 0
31
+  seamlessCubemap: 0
32
+  textureFormat: 1
33
+  maxTextureSize: 2048
34
+  textureSettings:
35
+    serializedVersion: 2
36
+    filterMode: 1
37
+    aniso: 1
38
+    mipBias: 0
39
+    wrapU: 0
40
+    wrapV: 0
41
+    wrapW: 0
42
+  nPOTScale: 0
43
+  lightmap: 0
44
+  compressionQuality: 50
45
+  spriteMode: 1
46
+  spriteExtrude: 1
47
+  spriteMeshType: 1
48
+  alignment: 0
49
+  spritePivot: {x: 0.5, y: 0.5}
50
+  spritePixelsToUnits: 100
51
+  spriteBorder: {x: 0, y: 0, z: 0, w: 0}
52
+  spriteGenerateFallbackPhysicsShape: 1
53
+  alphaUsage: 1
54
+  alphaIsTransparency: 0
55
+  spriteTessellationDetail: -1
56
+  textureType: 8
57
+  textureShape: 1
58
+  singleChannelComponent: 0
59
+  flipbookRows: 1
60
+  flipbookColumns: 1
61
+  maxTextureSizeSet: 0
62
+  compressionQualitySet: 0
63
+  textureFormatSet: 0
64
+  ignorePngGamma: 0
65
+  applyGammaDecoding: 0
66
+  cookieLightType: 0
67
+  platformSettings:
68
+  - serializedVersion: 3
69
+    buildTarget: DefaultTexturePlatform
70
+    maxTextureSize: 512
71
+    resizeAlgorithm: 0
72
+    textureFormat: -1
73
+    textureCompression: 1
74
+    compressionQuality: 50
75
+    crunchedCompression: 0
76
+    allowsAlphaSplitting: 0
77
+    overridden: 0
78
+    androidETC2FallbackOverride: 0
79
+    forceMaximumCompressionQuality_BC6H_BC7: 0
80
+  - serializedVersion: 3
81
+    buildTarget: Standalone
82
+    maxTextureSize: 2048
83
+    resizeAlgorithm: 0
84
+    textureFormat: -1
85
+    textureCompression: 1
86
+    compressionQuality: 50
87
+    crunchedCompression: 0
88
+    allowsAlphaSplitting: 0
89
+    overridden: 0
90
+    androidETC2FallbackOverride: 0
91
+    forceMaximumCompressionQuality_BC6H_BC7: 0
92
+  - serializedVersion: 3
93
+    buildTarget: Server
94
+    maxTextureSize: 2048
95
+    resizeAlgorithm: 0
96
+    textureFormat: -1
97
+    textureCompression: 1
98
+    compressionQuality: 50
99
+    crunchedCompression: 0
100
+    allowsAlphaSplitting: 0
101
+    overridden: 0
102
+    androidETC2FallbackOverride: 0
103
+    forceMaximumCompressionQuality_BC6H_BC7: 0
104
+  - serializedVersion: 3
105
+    buildTarget: Android
106
+    maxTextureSize: 2048
107
+    resizeAlgorithm: 0
108
+    textureFormat: -1
109
+    textureCompression: 1
110
+    compressionQuality: 50
111
+    crunchedCompression: 0
112
+    allowsAlphaSplitting: 0
113
+    overridden: 0
114
+    androidETC2FallbackOverride: 0
115
+    forceMaximumCompressionQuality_BC6H_BC7: 0
116
+  - serializedVersion: 3
117
+    buildTarget: WebGL
118
+    maxTextureSize: 2048
119
+    resizeAlgorithm: 0
120
+    textureFormat: -1
121
+    textureCompression: 1
122
+    compressionQuality: 50
123
+    crunchedCompression: 0
124
+    allowsAlphaSplitting: 0
125
+    overridden: 0
126
+    androidETC2FallbackOverride: 0
127
+    forceMaximumCompressionQuality_BC6H_BC7: 0
128
+  spriteSheet:
129
+    serializedVersion: 2
130
+    sprites: []
131
+    outline: []
132
+    physicsShape: []
133
+    bones: []
134
+    spriteID: 5e97eb03825dee720800000000000000
135
+    internalID: 0
136
+    vertices: []
137
+    indices: 
138
+    edges: []
139
+    weights: []
140
+    secondaryTextures: []
141
+    nameFileIdTable: {}
142
+  spritePackingTag: 
143
+  pSDRemoveMatte: 0
144
+  pSDShowRemoveMatteOption: 0
145
+  userData: 
146
+  assetBundleName: 
147
+  assetBundleVariant: 

+ 8 - 0
Runtime/Scripts/Debug/Component.meta

@@ -0,0 +1,8 @@
1
+fileFormatVersion: 2
2
+guid: 7e93deb34708e464e9dd79d8eb20ef27
3
+folderAsset: yes
4
+DefaultImporter:
5
+  externalObjects: {}
6
+  userData: 
7
+  assetBundleName: 
8
+  assetBundleVariant: 

+ 12 - 0
Runtime/Scripts/Debug/Component/BaseComponent.cs

@@ -0,0 +1,12 @@
1
+using TFramework;
2
+using System.Collections;
3
+using System.Collections.Generic;
4
+using UnityEngine;
5
+
6
+public class BaseComponent : MonoBehaviour
7
+{
8
+    public virtual void Init()
9
+    {
10
+
11
+    }
12
+}

+ 11 - 0
Runtime/Scripts/Debug/Component/BaseComponent.cs.meta

@@ -0,0 +1,11 @@
1
+fileFormatVersion: 2
2
+guid: 22a476855037f934db871f61a6ca86ef
3
+MonoImporter:
4
+  externalObjects: {}
5
+  serializedVersion: 2
6
+  defaultReferences: []
7
+  executionOrder: 0
8
+  icon: {instanceID: 0}
9
+  userData: 
10
+  assetBundleName: 
11
+  assetBundleVariant: 

+ 155 - 0
Runtime/Scripts/Debug/Component/Console.cs

@@ -0,0 +1,155 @@
1
+using TFramework;
2
+using System.Collections;
3
+using System.Collections.Generic;
4
+using UnityEngine;
5
+using UnityEngine.UI;
6
+using System;
7
+
8
+namespace TFramework
9
+{
10
+    public class Console : BaseComponent
11
+    {
12
+        public Toggle m_infoTog;
13
+        public Text m_infoCountText;
14
+        public Toggle m_warningTog;
15
+        public Text m_warningCountText;
16
+        public Toggle m_errorTog;
17
+        public Text m_errorCountText;
18
+        public Button m_clearBtn;
19
+
20
+        public Toggle m_logItem;
21
+        private List<Toggle> m_logItems = new List<Toggle>();
22
+
23
+        public InputField m_logInfoText;
24
+        public Text m_logInfoContent;
25
+
26
+        private List<ConsoleLog> _infoLogs = new List<ConsoleLog>();
27
+        private List<ConsoleLog> _errorLogs = new List<ConsoleLog>();
28
+        private List<ConsoleLog> _warningLogs = new List<ConsoleLog>();
29
+
30
+        private List<ConsoleLog> _logBuffers = new List<ConsoleLog>();
31
+
32
+        string msg;
33
+        bool _isDestroy = false;
34
+        // Start is called before the first frame update
35
+        void Start()
36
+        {
37
+            //m_logInfoText.onValueChanged.AddListener(st =>
38
+            //{
39
+            //    if (st != msg)
40
+            //        m_logInfoText.text = msg;
41
+            //});
42
+        }
43
+
44
+        public override void Init()
45
+        {
46
+            base.Init();
47
+            Clear();
48
+            Application.logMessageReceived += OnLogMessageReceived;
49
+            m_clearBtn.onClick.AddListener(Clear);
50
+
51
+            m_infoTog.onValueChanged.AddListener(isOn => Refresh());
52
+            m_warningTog.onValueChanged.AddListener(isOn => Refresh());
53
+            m_errorTog.onValueChanged.AddListener(isOn => Refresh());
54
+
55
+            Main.Instance.Delay(0.2f, () =>
56
+            {
57
+                m_infoTog.isOn = true;
58
+                m_warningTog.isOn = true;
59
+                m_errorTog.isOn = true;
60
+            });
61
+        }
62
+
63
+        private void Refresh()
64
+        {
65
+            m_logItems.ForEach(i => i.SetActive(false));
66
+            msg = string.Empty;
67
+            m_logInfoText.text = string.Empty;
68
+            _logBuffers.Clear();
69
+            if(m_infoTog.isOn)
70
+                _logBuffers.AddRange(_infoLogs);
71
+            if(m_warningTog.isOn)
72
+                _logBuffers.AddRange(_warningLogs);
73
+            if( m_errorTog.isOn)
74
+                _logBuffers.AddRange(_errorLogs);
75
+
76
+            _logBuffers.Sort((a,b)=>a.Time.CompareTo(b.Time));
77
+
78
+            for (int i = 0; i < _logBuffers.Count; i++)
79
+            {
80
+                if (m_logItems.Count <= i)
81
+                {
82
+                    m_logItems.Add(m_logItem.Clone(m_logItem.transform.parent));
83
+                }
84
+                int index = i;
85
+                m_logItems[i].gameObject.SetActive(true);
86
+                m_logItems[i].GetChildComponent<Text>("Label").text = $"<color={(_logBuffers[i].Type == LogType.Log ? "white" : (_logBuffers[i].Type==LogType.Warning?"yellow":"red"))}>{_logBuffers[i].Name}</color>";
87
+                m_logItems[i].onValueChanged.RemoveAllListeners();
88
+                m_logItems[i].onValueChanged.AddListener (isOn =>
89
+                {
90
+                    if (isOn)
91
+                    {
92
+                        msg = $"<color={(_logBuffers[index].Type == LogType.Log ? "white" : (_logBuffers[index].Type == LogType.Warning ? "yellow" : "red"))}>{_logBuffers[index].Message}</color>\n{_logBuffers[index].StackTrace}";
93
+                        m_logInfoContent.text = $"{_logBuffers[index].Message}\n{_logBuffers[index].StackTrace}";
94
+                        m_logInfoText.text = msg;
95
+                    }
96
+                });
97
+            }
98
+        }
99
+
100
+        private void OnLogMessageReceived(string condition, string stackTrace, LogType type)
101
+        {
102
+            ConsoleLog log = new ConsoleLog();
103
+            log.Time = DateTime.Now;
104
+            log.Message = condition;
105
+            log.StackTrace = stackTrace;
106
+            if (type == LogType.Assert)
107
+            {
108
+                log.Type = LogType.Error;
109
+                _errorLogs.Add(log);
110
+            }
111
+            else if (type == LogType.Exception || type == LogType.Error)
112
+            {
113
+                log.Type = LogType.Error;
114
+                _errorLogs.Add(log);
115
+            }
116
+            else if (type == LogType.Warning)
117
+            {
118
+                log.Type = LogType.Warning;
119
+               _warningLogs.Add(log);
120
+            }
121
+            else if (type == LogType.Log)
122
+            {
123
+                log.Type = LogType.Log;
124
+                _infoLogs.Add(log);
125
+            }
126
+            log.Name = string.Format("[{0}] [{1}] {2}", log.Type, log.Time.ToString("HH:mm:ss"), log.Message);
127
+            if (_isDestroy||m_errorCountText==null||m_infoCountText==null|m_warningCountText==null) return;
128
+            m_errorCountText.text = _errorLogs.Count < 99 ? _errorLogs.Count.ToString() : "99+";
129
+            m_infoCountText.text = _infoLogs.Count < 99 ? _infoLogs.Count.ToString() : "99+";
130
+            m_warningCountText.text = _warningLogs.Count < 99 ? _warningLogs.Count.ToString() : "99+";
131
+            Refresh();
132
+        }
133
+
134
+        private void Clear()
135
+        {
136
+            _infoLogs.Clear();
137
+            _warningLogs.Clear();
138
+            _errorLogs.Clear();
139
+            m_errorCountText.text = string.Empty;
140
+            m_infoCountText.text = string.Empty;
141
+            m_warningCountText.text = string.Empty;
142
+            m_logItems.ForEach(i=>i.SetActive(false));
143
+            m_logInfoText.text = string.Empty;
144
+            m_infoCountText.text = string.Empty;
145
+        }
146
+
147
+
148
+        private void OnDestroy()
149
+        {
150
+            _isDestroy = true;
151
+            Application.logMessageReceived -= OnLogMessageReceived;
152
+        }
153
+    }
154
+
155
+}

+ 11 - 0
Runtime/Scripts/Debug/Component/Console.cs.meta

@@ -0,0 +1,11 @@
1
+fileFormatVersion: 2
2
+guid: 78099562789a0c14ea9526215f292ed4
3
+MonoImporter:
4
+  externalObjects: {}
5
+  serializedVersion: 2
6
+  defaultReferences: []
7
+  executionOrder: 0
8
+  icon: {instanceID: 0}
9
+  userData: 
10
+  assetBundleName: 
11
+  assetBundleVariant: 

+ 22 - 0
Runtime/Scripts/Debug/Component/ConsoleLog.cs

@@ -0,0 +1,22 @@
1
+using TFramework;
2
+using System.Collections;
3
+using System.Collections.Generic;
4
+using UnityEngine;
5
+using System;
6
+
7
+namespace TFramework
8
+{
9
+    public class ConsoleLog:IReference
10
+    {
11
+        public string Name;
12
+        public DateTime Time;
13
+        public LogType Type;
14
+        public string Message;
15
+        public string StackTrace;
16
+
17
+        public void Reset()
18
+        {
19
+            throw new System.NotImplementedException();
20
+        }
21
+    }
22
+}

+ 11 - 0
Runtime/Scripts/Debug/Component/ConsoleLog.cs.meta

@@ -0,0 +1,11 @@
1
+fileFormatVersion: 2
2
+guid: 4409ebf2dc200b84caf57cb44f5977c5
3
+MonoImporter:
4
+  externalObjects: {}
5
+  serializedVersion: 2
6
+  defaultReferences: []
7
+  executionOrder: 0
8
+  icon: {instanceID: 0}
9
+  userData: 
10
+  assetBundleName: 
11
+  assetBundleVariant: 

+ 32 - 0
Runtime/Scripts/Debug/DebugComponent.cs

@@ -0,0 +1,32 @@
1
+using TFramework;
2
+using UnityEngine;
3
+using System;
4
+using Object = UnityEngine.Object;
5
+using System.Collections.Generic;
6
+
7
+
8
+namespace TFramework
9
+{
10
+    public class DebugComponent : MonoBehaviour
11
+    {
12
+        [Serializable]
13
+        public struct ComponentInfo
14
+        {
15
+            public string m_name;
16
+            public BaseComponent m_prefab;
17
+        }
18
+
19
+        [SerializeField]
20
+        ComponentInfo[] m_components;
21
+
22
+        public ComponentInfo[] Components => m_components;
23
+
24
+        private int _curIndex;
25
+
26
+        public void Awake()
27
+        {
28
+
29
+        }
30
+
31
+    }
32
+}

+ 11 - 0
Runtime/Scripts/Debug/DebugComponent.cs.meta

@@ -0,0 +1,11 @@
1
+fileFormatVersion: 2
2
+guid: 4ff9dc173186e314995ab1bc66401cc8
3
+MonoImporter:
4
+  externalObjects: {}
5
+  serializedVersion: 2
6
+  defaultReferences: []
7
+  executionOrder: 0
8
+  icon: {instanceID: 0}
9
+  userData: 
10
+  assetBundleName: 
11
+  assetBundleVariant: 

+ 14 - 1
Runtime/Scripts/Debug/DebugPanel.Designer.cs

@@ -1,4 +1,5 @@
1
-using System.Collections;
1
+using UnityEngine.UI;
2
+using System.Collections;
2 3
 using System.Collections.Generic;
3 4
 using UnityEngine;
4 5
 using TFramework;
@@ -6,11 +7,23 @@ using TFramework;
6 7
 public partial class DebugPanel :BasePanel
7 8
 {
8 9
     #region 组件变量
10
+    private Text FPS_Text;
11
+    private Button CloseBtn_Button;
12
+    private Toggle ItmeBar_Toggle;
13
+    private RectTransform Max_RectTransform;
14
+    private DebugComponent Content_DebugComponent;
15
+    private DragIcon Min_DragIcon;
9 16
     #endregion
10 17
 
11 18
     public override void OnInit()
12 19
     {
13 20
         base.OnInit();
21
+        Min_DragIcon = GetComponentInUIID<DragIcon>("Min_126B08D6222D");
22
+        Content_DebugComponent = GetComponentInUIID<DebugComponent>("Content_126B08D69D47");
23
+        Max_RectTransform = GetComponentInUIID<RectTransform>("Max_126B08D60A6A");
24
+        ItmeBar_Toggle = GetComponentInUIID<Toggle>("ItmeBar_126B08D602FA");
25
+        CloseBtn_Button = GetComponentInUIID<Button>("CloseBtn_126B08D60287");
26
+        FPS_Text = GetComponentInUIID<Text>("FPS_126B08D60241");
14 27
         Init();
15 28
     }
16 29
 }

+ 62 - 4
Runtime/Scripts/Debug/DebugPanel.cs

@@ -1,7 +1,8 @@
1 1
 using System.Collections;
2 2
 using System.Collections.Generic;
3
-using UnityEngine;
4 3
 using TFramework;
4
+using UnityEngine;
5
+using UnityEngine.UI;
5 6
 
6 7
 public class DebugPanelData : PanelData
7 8
 {
@@ -15,12 +16,61 @@ public class DebugPanelData : PanelData
15 16
  加载方式(对应前面路径)
16 17
  UI作用域(决定该UI面板挂载在那个Canvas下)
17 18
  */
18
-[UIResource("#","#.assetbundle","Assets/../#.prefab",ResLoadMode.Resourece,UIManager.DEFAULTDOMAIN)]
19
+[UIResource("UI/DebugPanel",UIManager.DEFAULTDOMAIN)]
19 20
 public partial class DebugPanel :BasePanel
20 21
 {
22
+    public override bool StickyTopic => true;
23
+
24
+    FPS fPS = new FPS();
25
+
26
+    private List<BaseComponent> m_componentsList = new List<BaseComponent>();
27
+
28
+
21 29
     public void Init()
22 30
     {
23
-        
31
+        fPS.onUpdateFPS = (f) => FPS_Text.text =  $"<color={(f<60?"red": "#00FF1A")}>{f.ToString("F2")}</color>";
32
+        CloseBtn_Button.onClick.AddListener(() =>
33
+        {
34
+            Max_RectTransform.SetActive(false);
35
+            Min_DragIcon.SetActive(true);
36
+        });
37
+
38
+        Min_DragIcon.onClick = () =>
39
+        {
40
+            Max_RectTransform.SetActive(true);
41
+            Min_DragIcon.SetActive(false);
42
+        };
43
+
44
+        for (int i = 0; i < Content_DebugComponent.Components.Length; i++)
45
+        {
46
+            m_componentsList.Add(Content_DebugComponent.Components[i].m_prefab.Clone(Content_DebugComponent.transform));
47
+            m_componentsList[i].Init();
48
+        }
49
+
50
+        for (int i = 0; i < Content_DebugComponent.Components.Length; i++)
51
+        {
52
+            if (ItmeBar_Toggle.transform.parent.childCount <= i)
53
+            {
54
+                ItmeBar_Toggle.Clone(ItmeBar_Toggle.transform.parent,true);
55
+            }
56
+            ItmeBar_Toggle.transform.parent.GetChild(i).GetChildComponent<Text>("Label").text = Content_DebugComponent.Components[i].m_name;
57
+            int index = i;
58
+            ItmeBar_Toggle.transform.parent.GetChild(i).GetComponent<Toggle>().onValueChanged.AddListener(isOn =>
59
+            {
60
+                if (isOn)
61
+                {
62
+                   ChangeView(index);
63
+                }
64
+            });
65
+            ItmeBar_Toggle.transform.parent.GetChild(i).SetActive(true);
66
+        } 
67
+    }
68
+
69
+
70
+    public void ChangeView(int index)
71
+    {
72
+        m_componentsList.ForEach(c => c.SetActive(false));
73
+        m_componentsList[index].SetActive(true);
24 74
     }
25 75
 
26 76
     public override void OnEnter(IPanelData args = null)
@@ -28,8 +78,16 @@ public partial class DebugPanel :BasePanel
28 78
         base.OnEnter(args);
29 79
     }
30 80
 
31
-    public override void OnExit(IPanelData args = null)
81
+    public override void OnExit(IPanelData args = null, bool isDestroy = false)
32 82
     {
83
+        if(isDestroy)
84
+        {
85
+            for (int i = 0; i < m_componentsList.Count;)
86
+            {
87
+                GameObject.Destroy(m_componentsList[i]);
88
+                m_componentsList.Remove(m_componentsList[i]);
89
+            }
90
+        }
33 91
         base.OnExit(args);
34 92
     }
35 93
 }

+ 42 - 0
Runtime/Scripts/Debug/DragIcon.cs

@@ -0,0 +1,42 @@
1
+using TFramework;
2
+using UnityEngine;
3
+using UnityEngine.EventSystems;
4
+
5
+public class DragIcon : MonoBehaviour, IDragHandler, IBeginDragHandler, IEndDragHandler, IPointerClickHandler
6
+{
7
+    public TAction onClick;
8
+    private bool _isDrag;
9
+
10
+    private RectTransform _selfRect;
11
+    private Canvas _canvas;
12
+
13
+    private void Start()
14
+    {
15
+        _selfRect = GetComponent<RectTransform>();
16
+        _canvas = GetComponentInParent<Canvas>();
17
+    }
18
+
19
+    public void OnBeginDrag(PointerEventData eventData)
20
+    {
21
+        
22
+    }
23
+
24
+    public void OnDrag(PointerEventData eventData)
25
+    {
26
+        _isDrag = true;
27
+        _selfRect.anchoredPosition += eventData.delta / _canvas.scaleFactor;
28
+    }
29
+
30
+    public void OnEndDrag(PointerEventData eventData)
31
+    {
32
+        
33
+    }
34
+
35
+    public void OnPointerClick(PointerEventData eventData)
36
+    {
37
+        if (!_isDrag)
38
+            onClick?.Invoke();
39
+        else
40
+            _isDrag = false;
41
+    }
42
+}

+ 11 - 0
Runtime/Scripts/Debug/DragIcon.cs.meta

@@ -0,0 +1,11 @@
1
+fileFormatVersion: 2
2
+guid: f87f04fcbd3210746a0c14a6da52c573
3
+MonoImporter:
4
+  externalObjects: {}
5
+  serializedVersion: 2
6
+  defaultReferences: []
7
+  executionOrder: 0
8
+  icon: {instanceID: 0}
9
+  userData: 
10
+  assetBundleName: 
11
+  assetBundleVariant: 

+ 22 - 2
Runtime/Scripts/Main/Main.cs

@@ -16,7 +16,7 @@ namespace TFramework
16 16
         [SerializeField]
17 17
         internal List<BaseManager> m_ManagerList = new List<BaseManager>();
18 18
 
19
-        //public bool IsEnableDebug;
19
+        public bool IsEnableDebug;
20 20
 
21 21
         /// <summary>
22 22
         /// 供非Mono脚本使用Update事件
@@ -31,7 +31,8 @@ namespace TFramework
31 31
         // Start is called before the first frame update
32 32
         void Start()
33 33
         {
34
-            
34
+            if (IsEnableDebug)
35
+                GetMagr<UIManager>().OpenUI<DebugPanel>();
35 36
         }
36 37
 
37 38
         // Update is called once per frame
@@ -40,6 +41,25 @@ namespace TFramework
40 41
             onUpdate?.Invoke();
41 42
         }
42 43
 
44
+        private void OnValidate()
45
+        {
46
+            if(IsEnableDebug)
47
+            {
48
+                if(m_ManagerList.Count <= 0||m_ManagerList.Find(m=>m is UIManager)==null)
49
+                {
50
+                    Log.Error("启用Debug工具失败,Debug工具依赖UIManager,请先注册UIManager");
51
+                    IsEnableDebug = false;
52
+                }
53
+            }
54
+        }
55
+
56
+        protected override void OnDestroy()
57
+        {
58
+            if (IsEnableDebug)
59
+                GetMagr<UIManager>().CloseUI<DebugPanel>(true);
60
+            base.OnDestroy();
61
+        }
62
+
43 63
         /// <summary>
44 64
         /// 获取指定类型管理器
45 65
         /// </summary>

+ 2 - 0
Runtime/Scripts/Net/NetHelper.cs

@@ -141,5 +141,7 @@ namespace TFramework
141 141
             m_headerKey = headerKey;
142 142
             m_headerValue = headerValue;
143 143
         }
144
+
145
+        public static Header DefaultJsonHeader = new Header("Content-Type", "application/json");
144 146
     }
145 147
 }

+ 23 - 8
Runtime/Scripts/Resource/ResourceManager.cs

@@ -1,6 +1,8 @@
1
+using Cysharp.Threading.Tasks;
1 2
 using System;
2 3
 using System.Collections;
3 4
 using System.Collections.Generic;
5
+using System.Threading.Tasks;
4 6
 using UnityEngine;
5 7
 using UnityEngine.SceneManagement;
6 8
 
@@ -51,7 +53,9 @@ namespace TFramework
51 53
 #if UNITY_EDITOR
52 54
                 if (AssetConfig.RuntimeMode == UpdateMode.Editor)
53 55
                     return UnityEditor.AssetDatabase.LoadAssetAtPath<T>(assetPath);
56
+
54 57
 #endif
58
+                assetBundleName = assetBundleName.ToLower();
55 59
                 if (AssetBundleManifest == null)
56 60
                 {
57 61
                     if (!AssetBundles.ContainsKey(AssetConfig.AssetBundleManifestName))
@@ -134,8 +138,8 @@ namespace TFramework
134 138
                 else
135 139
                 {
136 140
                     //等待相关依赖资源的加载
137
-                    yield return LoadDependenciesAssetBundleAsync(resHandle.AssetBundleName);
138
-                    yield return LoadAssetBundleAsync(resHandle.AssetBundleName, resHandle.OnLoading);
141
+                    yield return LoadDependenciesAssetBundleAsync(resHandle.AssetBundleName.ToLower());
142
+                    yield return LoadAssetBundleAsync(resHandle.AssetBundleName.ToLower(), resHandle.OnLoading);
139 143
                     if (AssetBundles.ContainsKey(resHandle.AssetBundleName.ToLower()))
140 144
                     {
141 145
                         //asset = AssetBundles[resHandle.AssetBundleName].LoadAsset<T>(resHandle.AssetPath);
@@ -222,7 +226,7 @@ namespace TFramework
222 226
             }
223 227
             else
224 228
             {
225
-                yield return LoadDependenciesAssetBundleAsync(assetBundleName);
229
+                yield return LoadDependenciesAssetBundleAsync(assetBundleName.ToLower());
226 230
 #if UNITY_EDITOR
227 231
                 if (AssetConfig.RuntimeMode == UpdateMode.Editor)
228 232
                 {
@@ -240,13 +244,14 @@ namespace TFramework
240 244
                 }
241 245
                 else
242 246
                 {
243
-                    yield return LoadAssetBundleAsync(assetBundleName, OnLoading);
247
+                    yield return LoadAssetBundleAsync(assetBundleName.ToLower(), OnLoading);
244 248
                     AsyncOperation ao = SceneManager.LoadSceneAsync(scenePath, loadSceneMode);
245 249
                     while (!ao.isDone)
246 250
                     {
247 251
                         OnLoading?.Invoke(ao.progress);
248 252
                         yield return null;
249 253
                     }
254
+                    Debug.Log($"加载场景{scenePath}完成");
250 255
                 }
251 256
 #else
252 257
                     yield return LoadAssetBundleAsync(assetBundleName, OnLoading);
@@ -258,6 +263,7 @@ namespace TFramework
258 263
                     }
259 264
 #endif
260 265
             }
266
+            Debug.Log($"加载场景{scenePath}完成");
261 267
             OnLoading?.Invoke(1);
262 268
             OnLoadOver?.Invoke(SceneManager.GetSceneByPath(scenePath));
263 269
             CurrentScene = SceneManager.GetActiveScene();
@@ -305,6 +311,7 @@ namespace TFramework
305 311
         /// <returns></returns>
306 312
         public Coroutine UnloadSceneAsync(Scene scene, TAction<float> OnUnloading = null, TAction OnUnloadOver = null)
307 313
         {
314
+            Debug.Log($"卸载场景{scene.name}");
308 315
             return StartCoroutine(UnloadScene(scene, OnUnloading, OnUnloadOver));
309 316
         }
310 317
 
@@ -329,6 +336,7 @@ namespace TFramework
329 336
             }
330 337
             else
331 338
             {
339
+                assetBundleName = assetBundleName.ToLower();
332 340
                 if (AssetBundles.ContainsKey(assetBundleName))
333 341
                 {
334 342
                     AssetBundles[assetBundleName].Unload(unloadAllLoadedObjects);
@@ -338,6 +346,17 @@ namespace TFramework
338 346
             }
339 347
         }
340 348
 
349
+        public async UniTask UnLoadAllABAssetAsync(bool unloadAllLoadedObjects = false)
350
+        {
351
+            List<string> keys = new List<string>(AssetBundles.Keys);
352
+            for (int i = 0; i < keys.Count; i++)
353
+            {
354
+                Debug.Log($"卸载AB包{keys[i]}");
355
+                await AssetBundles[keys[i]].UnloadAsync(unloadAllLoadedObjects);
356
+                AssetBundles.Remove(keys[i]);
357
+            }
358
+        }
359
+
341 360
         /// <summary>
342 361
         /// 异步加载AB包清单
343 362
         /// </summary>
@@ -353,7 +372,6 @@ namespace TFramework
353 372
                 if (AssetBundleManifest == null)
354 373
                 {
355 374
                     yield return LoadAssetBundleAsync(AssetConfig.AssetBundleManifestName, null);
356
-
357 375
                     if (AssetBundles.ContainsKey(AssetConfig.AssetBundleManifestName))
358 376
                     {
359 377
                         AssetBundleManifest = AssetBundles[AssetConfig.AssetBundleManifestName].LoadAsset<AssetBundleManifest>("AssetBundleManifest");
@@ -373,7 +391,6 @@ namespace TFramework
373 391
         /// <returns>协程迭代器</returns>
374 392
         private IEnumerator LoadAssetBundleAsync(string assetBundleName, TAction<float> onLoading)
375 393
         {
376
-            assetBundleName = assetBundleName.ToLower();
377 394
             if (!AssetBundles.ContainsKey(assetBundleName))
378 395
             {
379 396
                 AssetBundleCreateRequest abRequst = AssetBundle.LoadFromFileAsync(AssetConfig.AssetBundleRootPath + assetBundleName);
@@ -405,7 +422,6 @@ namespace TFramework
405 422
             if (AssetConfig.RuntimeMode != UpdateMode.Editor)
406 423
             {
407 424
                 yield return LoadAssetBundleManifestAsync();
408
-
409 425
                 if (AssetBundleManifest != null)
410 426
                 {
411 427
                     string[] dependencies = AssetBundleManifest.GetAllDependencies(assetBundleName);
@@ -420,7 +436,6 @@ namespace TFramework
420 436
             }
421 437
 #else
422 438
                 yield return LoadAssetBundleManifestAsync();
423
-
424 439
                 if (AssetBundleManifest != null)
425 440
                 {
426 441
                     string[] dependencies = AssetBundleManifest.GetAllDependencies(assetBundleName);

+ 21 - 2
Runtime/Scripts/UI/BasePanel.cs

@@ -6,7 +6,10 @@ using UnityEngine.UI;
6 6
 
7 7
 namespace TFramework
8 8
 {
9
-    public interface IPanelData:IReference { }
9
+    public interface IPanelData:IReference 
10
+    {
11
+        public void Recycle();
12
+    }
10 13
 
11 14
     public class PanelData : IPanelData
12 15
     {
@@ -14,6 +17,8 @@ namespace TFramework
14 17
         {
15 18
             
16 19
         }
20
+
21
+        public void Recycle()=> Main.GetMagr<ReferencePoolManager>().Recycle(this);
17 22
     }
18 23
 
19 24
     public class BasePanel
@@ -24,6 +29,7 @@ namespace TFramework
24 29
         public GameObject UIEntity { get; set; }
25 30
 
26 31
         protected Dictionary<string, UIBehaviour> uiComponents;
32
+        protected Dictionary<GameObject, UIBehaviour> ui2gam;
27 33
 
28 34
         public virtual bool StickyTopic { get; protected set; } = false;
29 35
 
@@ -35,6 +41,7 @@ namespace TFramework
35 41
         public virtual void OnInit()
36 42
         {
37 43
             uiComponents = new Dictionary<string, UIBehaviour>();
44
+            ui2gam = new Dictionary<GameObject, UIBehaviour>();
38 45
             GetAllUIBehaviour();
39 46
         }
40 47
 
@@ -65,7 +72,7 @@ namespace TFramework
65 72
         /// <summary>
66 73
         /// 退出界面 界面关闭
67 74
         /// </summary>
68
-        public virtual void OnExit(IPanelData args = null)
75
+        public virtual void OnExit(IPanelData args = null,bool isDestroy=false)
69 76
         {
70 77
             IsOpen = false;
71 78
         }
@@ -80,7 +87,10 @@ namespace TFramework
80 87
                 if (uiComponents.ContainsKey(item.ID))
81 88
                     throw new UnityException($"在同一个Panel下发现相同的UIBehaviourID:{item.ID}");
82 89
                 else
90
+                {
83 91
                     uiComponents.Add(item.ID, item);
92
+                    ui2gam.Add(item.gameObject, item);
93
+                }
84 94
             }
85 95
         }
86 96
 
@@ -110,6 +120,15 @@ namespace TFramework
110 120
             return GetUIBehaviour(uiId)?.GetComponent(type);
111 121
         }
112 122
 
123
+        protected T GetUseRes<T>(GameObject ui,string resName) where T : UnityEngine.Object
124
+        {
125
+            if (ui2gam.ContainsKey(ui))
126
+                return ui2gam[ui].GetRes(resName) as T;
127
+
128
+            Debug.Log($"对象{ui.name}的资源列表中没有名字为{resName}的资源");
129
+            return null;
130
+        }
131
+
113 132
         /// <summary>
114 133
         /// 切换语言
115 134
         /// </summary>

+ 67 - 47
Runtime/Scripts/UI/FixScreenRatio.cs

@@ -6,81 +6,101 @@
6 6
     UnityVersion: 2021.3.13f1
7 7
     功能:UI适配
8 8
 *****************************************************/
9
-using TFramework;
9
+using System;
10 10
 using System.Collections;
11
-using UnityEngine;
12 11
 using System.Collections.Generic;
12
+using TFramework;
13
+using UnityEngine;
13 14
 using UnityEngine.UI;
14 15
 
15 16
 namespace TFramework
16 17
 {
17 18
     public class FixScreenRatio : MonoBehaviour
18 19
     {
19
-        CanvasScaler canvasScaler;
20
-        float rateW = 1.0f;
21
-        float rateH = 1.0f;
22
-        private int cachedWidth = 0;
23
-        private int cachedHeight = 0;
24
-
25
-        public static float windowRate = 1.0f;
26
-        public static float screenRate = 1.0f;
27
-        public static float width = 1920f;
28
-        public static float height = 1080f;
20
+        public enum Orientation
21
+        {
22
+            Portrait,
23
+            Landscape
24
+        }
29 25
 
30
-        [System.NonSerialized]
31
-        public bool IsUpdatePerFrame = true;
26
+        public float defaultModifier = 0.5f;
27
+        public Vector2 currentRes = new Vector2();
28
+        public Vector2 newRes = new Vector2();
29
+        public float refWidth = 480;
30
+        public float refHeight = 320;
31
+        public Orientation refOrientation = Orientation.Portrait;
32 32
 
33
-        private void Awake()
33
+        void OnEnable()
34 34
         {
35
-            Screen.autorotateToPortrait = false;
36
-            Screen.autorotateToPortraitUpsideDown = false;
37
-
38
-            canvasScaler = GetComponent<CanvasScaler>();
39
-            screenRate = width / height;
35
+            // Initially update scale
36
+            newRes.x = Screen.width;
37
+            newRes.y = Screen.height;
38
+            UpdateScaling();
40 39
         }
41 40
 
42
-        private void Update()
41
+        void Update()
43 42
         {
44
-            if (IsUpdatePerFrame)
43
+            // Update if resolution has changed
44
+            newRes.x = Screen.width;
45
+            newRes.y = Screen.height;
46
+            if (newRes != currentRes)
45 47
             {
46
-                if (cachedWidth != Screen.width || cachedHeight != Screen.height)
47
-                {
48
-                    UpdateWhenScreenChange();
49
-                }
48
+                UpdateScaling();
50 49
             }
51 50
         }
52 51
 
53
-        public void UpdateWhenScreenChange()
52
+        private void OnValidate()
54 53
         {
55
-            cachedWidth = Screen.width;
56
-            cachedHeight = Screen.height;
57
-            Scale();
54
+            UpdateScaling();
58 55
         }
59 56
 
60
-        void Scale()
57
+        /// <summary>
58
+        /// Handles updating of the canvas scale based on device resolution
59
+        /// </summary>
60
+        public virtual void UpdateScaling()
61 61
         {
62
-            rateW = Screen.width / width;
63
-            rateH = Screen.height / height;
62
+            currentRes = newRes;
64 63
 
65
-            if (rateW > rateH)
64
+            // Determine platform specific resolution multiplier
65
+            float multiplier = 1f;
66
+#if UNITY_ANDROID || UNITY_IOS
67
+            switch (refOrientation)
66 68
             {
67
-                //以高度适配
68
-                windowRate = rateH;
69
+                case Orientation.Portrait:
70
+                    multiplier = 1f + ((((float)currentRes.y - refHeight) / refHeight) * defaultModifier);
71
+                    break;
72
+                case Orientation.Landscape:
73
+                    multiplier = 1f + ((((float)currentRes.x - refWidth) / refWidth) * defaultModifier);
74
+                    break;
75
+            }
76
+#else
77
+        // For desktop platforms we scale based on the largest value out of width & height
78
+        if (currentRes.x > currentRes.y)
79
+        {
80
+            multiplier = 1f + ((((float)currentRes.y - refHeight) / refHeight) * defaultModifier);
81
+        }
82
+        else
83
+        {
84
+            multiplier = 1f + ((((float)currentRes.x - refWidth) / refWidth) * defaultModifier);
85
+        }
86
+#endif
69 87
 
70
-                if (canvasScaler != null)
71
-                {
72
-                    canvasScaler.matchWidthOrHeight = 1;
73
-                }
88
+            // Modify multiplier based on initial value.
89
+            if (multiplier < 0.5f) // Ceil to 0.5 if less than 0.5
90
+            {
91
+                multiplier = 0.5f;
92
+            }
93
+            else if (multiplier < 2f) // Calc to the nearest 0.5 if less than 2
94
+            {
95
+                multiplier = Mathf.Max(1f, (float)(Math.Round(((double)multiplier * 2), MidpointRounding.AwayFromZero) / 2));
74 96
             }
75
-            else
97
+            else // Otherwise if larger than 2 then round
76 98
             {
77
-                //以宽度适配
78
-                windowRate = rateW;
79
-                if (canvasScaler != null)
80
-                {
81
-                    canvasScaler.matchWidthOrHeight = 0;
82
-                }
99
+                multiplier = (float)Math.Round(multiplier, MidpointRounding.AwayFromZero);
83 100
             }
101
+
102
+            // Apply new scale factor to canvas 
103
+            GetComponent<CanvasScaler>().scaleFactor = multiplier;
84 104
         }
85 105
     }
86 106
 }

+ 15 - 0
Runtime/Scripts/UI/UIBehaviour.cs

@@ -52,6 +52,9 @@ namespace TFramework
52 52
         [SerializeField]
53 53
         private string parnetPanel;
54 54
 
55
+        [SerializeField]
56
+        private List<UseResInfo> useResInfos;
57
+
55 58
         public override void Start()
56 59
         {
57 60
             base.Start();
@@ -69,6 +72,11 @@ namespace TFramework
69 72
                 uIAnim.DisableAnim(rectTransform);
70 73
         }
71 74
 
75
+        public UnityEngine.Object GetRes(string resName)
76
+        {
77
+            return useResInfos.Find(p => p.resName.Equals(resName))?.resObj;
78
+        }
79
+
72 80
 
73 81
         #region Text
74 82
  
@@ -93,4 +101,11 @@ namespace TFramework
93 101
         public string variableName;
94 102
         public string compentType;
95 103
     }
104
+
105
+    [Serializable]
106
+    public class UseResInfo
107
+    {
108
+        public UnityEngine.Object resObj;
109
+        public string resName;
110
+    }
96 111
 }

+ 4 - 1
Runtime/Scripts/UI/UIManager.cs

@@ -146,6 +146,9 @@ namespace TFramework
146 146
         {
147 147
             BasePanel panel = GetAlreadyHavePanel(type.FullName);
148 148
             if (panel == null) return;
149
+
150
+            if (panel.UIEntity == null) return;
151
+
149 152
             if (panelStack.Peek() == panel)
150 153
                 CloseUI(args);
151 154
             else
@@ -159,7 +162,7 @@ namespace TFramework
159 162
                     if(toPanel.UIEntity!=null)
160 163
                     {
161 164
                         toPanel.UIEntity.SetActive(false);
162
-                        toPanel.OnExit(args);
165
+                        toPanel.OnExit(args,isDestroy);
163 166
                     }
164 167
                     for (int i = panelBuffer.Count - 1; i >= 0; i--)
165 168
                         panelStack.Push(panelBuffer[i]);

+ 36 - 0
Runtime/Scripts/Utility/GlobalTool.cs

@@ -163,6 +163,42 @@ namespace TFramework
163 163
             texture2D.LoadImage(buff);
164 164
             return texture2D;
165 165
         }
166
+
167
+        /// <summary>
168
+        /// 将字节数转换为最合适的存储单位表示
169
+        /// </summary>
170
+        /// <param name="bytes">要转换的字节数</param>
171
+        /// <returns>带有单位的字符串表示,如"1KB"、"2.5MB"等</returns>
172
+        public static string CalculateStorageSize(long bytes)
173
+        {
174
+            // 定义单位换算系数
175
+            const long kb = 1024;
176
+            const long mb = kb * 1024;
177
+            const long gb = mb * 1024;
178
+
179
+            // 根据数值大小选择合适的单位
180
+            if (bytes >= gb)
181
+            {
182
+                double value = (double)bytes / gb;
183
+                // 如果是整数则不显示小数
184
+                return value % 1 == 0 ? $"{(long)value}G" : $"{value:F1}G";
185
+            }
186
+            else if (bytes >= mb)
187
+            {
188
+                double value = (double)bytes / mb;
189
+                return value % 1 == 0 ? $"{(long)value}M" : $"{value:F1}M";
190
+            }
191
+            else if (bytes >= kb)
192
+            {
193
+                double value = (double)bytes / kb;
194
+                return value % 1 == 0 ? $"{(long)value}K" : $"{value:F1}K";
195
+            }
196
+            else
197
+            {
198
+                // 小于1KB的情况直接返回字节数
199
+                return $"{bytes}B";
200
+            }
201
+        }
166 202
         #endregion
167 203
 
168 204
         #region 截屏