Explorar o código

Static字段需要添加StaticField标签 (#402)

* Static字段需要添加StaticField标签
susices %!s(int64=3) %!d(string=hai) anos
pai
achega
4cf9854706
Modificáronse 47 ficheiros con 198 adicións e 27 borrados
  1. 1 0
      DotNet/Core/DotNet.Core.csproj
  2. 1 0
      DotNet/Tool/Template.txt
  3. 1 1
      Share/Analyzer/Analyzer/AddChildTypeAnalyzer.cs
  4. 1 1
      Share/Analyzer/Analyzer/ETTaskAnalyzer.cs
  5. 1 1
      Share/Analyzer/Analyzer/EntityComponentAnalyzer.cs
  6. 1 1
      Share/Analyzer/Analyzer/EntityFiledAccessAnalyzer.cs
  7. 63 0
      Share/Analyzer/Analyzer/StaticFieldDeclarationAnalyzer.cs
  8. 9 1
      Share/Analyzer/Config/AnalyzeAssembly.cs
  9. 2 0
      Share/Analyzer/Config/Definition.cs
  10. 9 7
      Share/Analyzer/Config/DiagnosticIds.cs
  11. 27 11
      Share/Analyzer/Config/DiagnosticRules.cs
  12. 3 3
      Unity/Assets/Bundles/Config/UnitConfigCategory.bytes
  13. 1 0
      Unity/Assets/Scripts/Codes/Model/Generate/Client/Config/AIConfig.cs
  14. 1 0
      Unity/Assets/Scripts/Codes/Model/Generate/Client/Config/UnitConfig.cs
  15. 1 0
      Unity/Assets/Scripts/Codes/Model/Generate/Server/Config/AIConfig.cs
  16. 1 0
      Unity/Assets/Scripts/Codes/Model/Generate/Server/Config/StartMachineConfig.cs
  17. 1 0
      Unity/Assets/Scripts/Codes/Model/Generate/Server/Config/StartProcessConfig.cs
  18. 1 0
      Unity/Assets/Scripts/Codes/Model/Generate/Server/Config/StartSceneConfig.cs
  19. 1 0
      Unity/Assets/Scripts/Codes/Model/Generate/Server/Config/StartZoneConfig.cs
  20. 1 0
      Unity/Assets/Scripts/Codes/Model/Generate/Server/Config/UnitConfig.cs
  21. 1 0
      Unity/Assets/Scripts/Codes/Model/Server/Module/Actor/ActorMessageDispatcherComponent.cs
  22. 1 0
      Unity/Assets/Scripts/Codes/Model/Server/Module/Actor/ActorMessageSenderComponent.cs
  23. 1 0
      Unity/Assets/Scripts/Codes/Model/Server/Module/ActorLocation/LocationProxyComponent.cs
  24. 1 0
      Unity/Assets/Scripts/Codes/Model/Server/Module/DB/DBManagerComponent.cs
  25. 1 0
      Unity/Assets/Scripts/Codes/Model/Server/Module/MessageInner/NetInnerComponent.cs
  26. 1 0
      Unity/Assets/Scripts/Codes/Model/Server/Module/RobotCase/RobotCaseComponent.cs
  27. 1 0
      Unity/Assets/Scripts/Codes/Model/Server/Module/RobotCase/RobotCaseDispatcherComponent.cs
  28. 1 0
      Unity/Assets/Scripts/Codes/Model/Share/Module/AI/AIDispatcherComponent.cs
  29. 1 0
      Unity/Assets/Scripts/Codes/Model/Share/Module/Config/ConfigComponent.cs
  30. 1 0
      Unity/Assets/Scripts/Codes/Model/Share/Module/CoroutineLock/CoroutineLockComponent.cs
  31. 1 0
      Unity/Assets/Scripts/Codes/Model/Share/Module/Message/NetThreadComponent.cs
  32. 1 0
      Unity/Assets/Scripts/Codes/Model/Share/Module/Message/OpcodeHelper.cs
  33. 1 0
      Unity/Assets/Scripts/Codes/Model/Share/Module/Message/OpcodeTypeComponent.cs
  34. 1 0
      Unity/Assets/Scripts/Codes/Model/Share/Module/Recast/NavmeshComponent.cs
  35. 1 0
      Unity/Assets/Scripts/Codes/Model/Share/Module/Recast/PathfindingComponent.cs
  36. 1 0
      Unity/Assets/Scripts/Codes/Model/Share/Module/Scene/ClientSceneManagerComponent.cs
  37. 1 0
      Unity/Assets/Scripts/Codes/ModelView/Client/Demo/Global/GlobalComponent.cs
  38. 1 0
      Unity/Assets/Scripts/Codes/ModelView/Client/Module/UI/UIEventComponent.cs
  39. 2 0
      Unity/Assets/Scripts/Core/Entity/Game.cs
  40. 2 0
      Unity/Assets/Scripts/Core/Helper/RandomHelper.cs
  41. 1 0
      Unity/Assets/Scripts/Core/JsonHelper.cs
  42. 1 0
      Unity/Assets/Scripts/Core/Network/KChannel.cs
  43. 2 1
      Unity/Assets/Scripts/Core/Network/KService.cs
  44. 36 0
      Unity/Assets/Scripts/Core/Object/StaticFieldAttribute.cs
  45. 3 0
      Unity/Assets/Scripts/Core/Object/StaticFieldAttribute.cs.meta
  46. 1 0
      Unity/Assets/Scripts/Core/Singleton.cs
  47. 5 0
      Unity/Assets/Scripts/Editor/AssetPostProcessor/OnGenerateCSProjectProcessor.cs

+ 1 - 0
DotNet/Core/DotNet.Core.csproj

@@ -34,6 +34,7 @@
     </ItemGroup>
     
     <ItemGroup>
+      <ProjectReference Include="..\..\Share\Analyzer\Share.Analyzer.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false"/>
       <ProjectReference Include="..\ThirdParty\DotNet.ThirdParty.csproj" />
     </ItemGroup>
 

+ 1 - 0
DotNet/Tool/Template.txt

@@ -9,6 +9,7 @@ namespace ET
     [Config]
     public partial class (ConfigName)Category : ProtoObject, IMerge
     {
+        [StaticField]
         public static (ConfigName)Category Instance;
 		
         [ProtoIgnore]

+ 1 - 1
Share/Analyzer/Analyzer/AddChildTypeAnalyzer.cs

@@ -27,7 +27,7 @@ namespace ET.Analyzer
 
         private void AnalyzeMemberAccessExpression(SyntaxNodeAnalysisContext context)
         {
-            if (!AnalyzerHelper.IsAssemblyNeedAnalyze(context.Compilation.AssemblyName, AnalyzeAssembly.All))
+            if (!AnalyzerHelper.IsAssemblyNeedAnalyze(context.Compilation.AssemblyName, AnalyzeAssembly.AllModelHotfix))
             {
                 return;
             }

+ 1 - 1
Share/Analyzer/Analyzer/ETTaskAnalyzer.cs

@@ -26,7 +26,7 @@ namespace ET.Analyzer
 
         private void AnalyzeMemberAccessExpression(SyntaxNodeAnalysisContext context)
         {
-            if (!AnalyzerHelper.IsAssemblyNeedAnalyze(context.Compilation.AssemblyName, AnalyzeAssembly.All))
+            if (!AnalyzerHelper.IsAssemblyNeedAnalyze(context.Compilation.AssemblyName, AnalyzeAssembly.AllModelHotfix))
             {
                 return;
             }

+ 1 - 1
Share/Analyzer/Analyzer/EntityComponentAnalyzer.cs

@@ -26,7 +26,7 @@ namespace ET.Analyzer
 
         private void AnalyzeMemberAccessExpression(SyntaxNodeAnalysisContext context)
         {
-            if (!AnalyzerHelper.IsAssemblyNeedAnalyze(context.Compilation.AssemblyName, AnalyzeAssembly.All))
+            if (!AnalyzerHelper.IsAssemblyNeedAnalyze(context.Compilation.AssemblyName, AnalyzeAssembly.AllModelHotfix))
             {
                 return;
             }

+ 1 - 1
Share/Analyzer/Analyzer/EntityFiledAccessAnalyzer.cs

@@ -38,7 +38,7 @@ namespace ET.Analyzer
 
         private void AnalyzeMemberAccessExpression(SyntaxNodeAnalysisContext context)
         {
-            if (!AnalyzerHelper.IsAssemblyNeedAnalyze(context.Compilation.AssemblyName, AnalyzeAssembly.All))
+            if (!AnalyzerHelper.IsAssemblyNeedAnalyze(context.Compilation.AssemblyName, AnalyzeAssembly.AllModelHotfix))
             {
                 return;
             }

+ 63 - 0
Share/Analyzer/Analyzer/StaticFieldDeclarationAnalyzer.cs

@@ -0,0 +1,63 @@
+using System.Collections.Immutable;
+using System.Linq;
+using Microsoft.CodeAnalysis;
+using Microsoft.CodeAnalysis.Diagnostics;
+
+namespace ET.Analyzer
+{
+    [DiagnosticAnalyzer(LanguageNames.CSharp)]
+    public class StaticFieldDeclarationAnalyzer : DiagnosticAnalyzer
+    {
+        
+        public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics =>ImmutableArray.Create(StaticFieldDeclarationAnalyzerRule.Rule);
+        
+        public override void Initialize(AnalysisContext context)
+        {
+            if (!AnalyzerGlobalSetting.EnableAnalyzer)
+            {
+                return;
+            }
+            
+            context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None);
+            context.EnableConcurrentExecution();
+            context.RegisterSymbolAction(this.Analyzer, SymbolKind.NamedType);
+        }
+        
+        private void Analyzer(SymbolAnalysisContext context)
+        {
+            if (!AnalyzerHelper.IsAssemblyNeedAnalyze(context.Compilation.AssemblyName, AnalyzeAssembly.All))
+            {
+                return;
+            }
+
+            if (!(context.Symbol is INamedTypeSymbol namedTypeSymbol))
+            {
+                return;
+            }
+
+            foreach (ISymbol? memberSymbol in namedTypeSymbol.GetMembers())
+            {
+                // 筛选出非Const字段成员
+                if (memberSymbol is IFieldSymbol fieldSymbol && fieldSymbol.IsStatic&& !fieldSymbol.IsConst)
+                {
+                    bool hasAttr = fieldSymbol.GetAttributes().Any(x => x.AttributeClass?.ToString() == Definition.StaticFieldAttribute);
+                    if (!hasAttr)
+                    {
+                        ReportDiagnostic(fieldSymbol);
+                    }
+                } 
+            }
+
+            void ReportDiagnostic(ISymbol symbol)
+            {
+                foreach (SyntaxReference? declaringSyntaxReference in symbol.DeclaringSyntaxReferences)
+                {
+                    Diagnostic diagnostic = Diagnostic.Create(StaticFieldDeclarationAnalyzerRule.Rule, declaringSyntaxReference.GetSyntax()?.GetLocation(), symbol.Name);
+                    context.ReportDiagnostic(diagnostic);
+                }
+            }
+        }
+        
+    }
+}
+

+ 9 - 1
Share/Analyzer/Config/AnalyzeAssembly.cs

@@ -2,10 +2,14 @@
 {
     public static class AnalyzeAssembly
     {
+        public const string AppsCore = "Core";
+        
         public const string AppsModel = "Model";
 
         public const string AppsHotfix = "Hotfix";
 
+        public const string UnityCore = "Unity.Core";
+
         public const string UnityModel = "Unity.Model";
 
         public const string UnityHotfix = "Unity.Hotfix";
@@ -18,6 +22,10 @@
 
         public static readonly string[] AllModel = { AppsModel, UnityModel, UnityModelView };
 
-        public static readonly string[] All = { AppsModel, AppsHotfix, UnityModel, UnityHotfix, UnityModelView, UnityHotfixView };
+        public static readonly string[] AllModelHotfix = { AppsModel, AppsHotfix, UnityModel, UnityHotfix, UnityModelView, UnityHotfixView };
+        
+        public static readonly string[] All = { AppsCore, AppsModel, AppsHotfix, UnityCore, UnityModel, UnityHotfix, UnityModelView, UnityHotfixView };
+        
+        
     }
 }

+ 2 - 0
Share/Analyzer/Config/Definition.cs

@@ -27,6 +27,8 @@
         public const string ComponentOfAttribute = "ET.ComponentOfAttribute";
         
         public const string EnableAccessEntiyChildAttribute = "ET.EnableAccessEntiyChildAttribute";
+
+        public const string StaticFieldAttribute = "ET.StaticFieldAttribute";
     }
 }
 

+ 9 - 7
Share/Analyzer/Config/DiagnosticIds.cs

@@ -2,19 +2,19 @@
 {
     public static class DiagnosticIds
     {
-        public const string AddChildTypeAnalyzerRuleId = "ET00001";
+        public const string AddChildTypeAnalyzerRuleId = "ET0001";
 
-        public const string EntityFiledAccessAnalyzerRuleId = "ET00002";
+        public const string EntityFiledAccessAnalyzerRuleId = "ET0002";
 
-        public const string EntityClassDeclarationAnalyzerRuleId = "ET00003";
+        public const string EntityClassDeclarationAnalyzerRuleId = "ET0003";
 
-        public const string HotfixProjectFieldDeclarationAnalyzerRuleId = "ET00004";
+        public const string HotfixProjectFieldDeclarationAnalyzerRuleId = "ET0004";
 
-        public const string ClassDeclarationInHotfixAnalyzerRuleId = "ET00005";
+        public const string ClassDeclarationInHotfixAnalyzerRuleId = "ET0005";
         
-        public const string EntityMethodDeclarationAnalyzerRuleId = "ET00006";
+        public const string EntityMethodDeclarationAnalyzerRuleId = "ET0006";
 
-        public const string EntityComponentAnalyzerRuleId = "ET00007";
+        public const string EntityComponentAnalyzerRuleId = "ET0007";
         
         public const string ETTaskInSyncMethodAnalyzerRuleId = "ET0008";
         
@@ -30,5 +30,7 @@
 
         public const string DisableUseChildComponentInEntityAnalyzerRuleId = "ET0014";
 
+        public const string StaticFieldDeclarationAnalyzerRule = "ET0015";
+
     }
 }

+ 27 - 11
Share/Analyzer/Config/DiagnosticRules.cs

@@ -9,7 +9,7 @@ namespace ET.Analyzer
         private const string MessageFormat = "方法: {0} 在非异步方法体内使用时需要添加.Coroutine()后缀";
 
         private const string Description = "ETTask方法调用在非异步方法体内使用错误.";
-            
+
         public static readonly DiagnosticDescriptor Rule =
                 new DiagnosticDescriptor(DiagnosticIds.ETTaskInSyncMethodAnalyzerRuleId,
                     Title,
@@ -19,7 +19,7 @@ namespace ET.Analyzer
                     true,
                     Description);
     }
-    
+
     public static class ETTaskInAsyncMethodAnalyzerRule
     {
         private const string Title = "ETTask方法调用在异步方法体内使用错误";
@@ -27,7 +27,7 @@ namespace ET.Analyzer
         private const string MessageFormat = "方法: {0} 在异步方法体内使用时需要添加await前缀 或 .Coroutine()后缀";
 
         private const string Description = "ETTask方法调用在异步方法体内使用错误.";
-            
+
         public static readonly DiagnosticDescriptor Rule =
                 new DiagnosticDescriptor(DiagnosticIds.ETTaskInAsyncMethodAnalyzerRuleId,
                     Title,
@@ -45,7 +45,7 @@ namespace ET.Analyzer
         private const string MessageFormat = "类: {0} Id字段: {1}的值: {2} 不在约束的区间内, 请修改";
 
         private const string Description = "唯一Id字段数值区间约束.";
-        
+
         public static readonly DiagnosticDescriptor Rule =
                 new DiagnosticDescriptor(DiagnosticIds.UniqueIdRangeAnalyzerRuleId,
                     Title,
@@ -63,7 +63,7 @@ namespace ET.Analyzer
         private const string MessageFormat = "类: {0} Id字段: {1}的值: {2} 与其他Id字段值重复, 请修改";
 
         private const string Description = "唯一Id字段禁止重复.";
-        
+
         public static readonly DiagnosticDescriptor Rule =
                 new DiagnosticDescriptor(DiagnosticIds.UniqueIdDuplicateAnalyzerRuleId,
                     Title,
@@ -81,7 +81,7 @@ namespace ET.Analyzer
         private const string MessageFormat = "Type: {0} 不允许作为实体: {1} 的AddChild函数参数类型! 若要允许该类型作为参数,请使用ChildOfAttribute对child实体类标记父级类型";
 
         private const string Description = "AddChild方法类型约束错误.";
-        
+
         public static readonly DiagnosticDescriptor Rule =
                 new DiagnosticDescriptor(DiagnosticIds.AddChildTypeAnalyzerRuleId,
                     Title,
@@ -91,7 +91,7 @@ namespace ET.Analyzer
                     true,
                     Description);
     }
-    
+
     public static class DisableAccessEntityChildAnalyzerRule
     {
         private const string Title = "禁止在Entity类中直接调用Child和Component";
@@ -99,7 +99,7 @@ namespace ET.Analyzer
         private const string MessageFormat = "禁止在Entity类中直接调用Child和Component";
 
         private const string Description = "禁止在Entity类中直接调用Child和Component.";
-        
+
         public static readonly DiagnosticDescriptor Rule =
                 new DiagnosticDescriptor(DiagnosticIds.DisableUseChildComponentInEntityAnalyzerRuleId,
                     Title,
@@ -117,7 +117,7 @@ namespace ET.Analyzer
         private const string MessageFormat = "组件类型: {0} 不允许作为实体: {1} 的组件类型! 若要允许该类型作为参数,请使用ComponentOfAttribute对组件类标记父级实体类型";
 
         private const string Description = "实体类添加或获取组件类型错误.";
-        
+
         public static readonly DiagnosticDescriptor Rule =
                 new DiagnosticDescriptor(DiagnosticIds.EntityComponentAnalyzerRuleId,
                     Title,
@@ -127,6 +127,22 @@ namespace ET.Analyzer
                     true,
                     Description);
     }
-    
-    
+
+    public static class StaticFieldDeclarationAnalyzerRule
+    {
+        private const string Title = "Static字段声明需要标记标签";
+
+        private const string MessageFormat = "Static字段声明 {0} 需要标记标签";
+
+        private const string Description = "Static字段声明需要标记标签.";
+
+        public static readonly DiagnosticDescriptor Rule =
+                new DiagnosticDescriptor(DiagnosticIds.StaticFieldDeclarationAnalyzerRule,
+                    Title,
+                    MessageFormat,
+                    DiagnosticCategories.All, 
+                    DiagnosticSeverity.Error,
+                    true,
+                    Description);
+    }
 }

+ 3 - 3
Unity/Assets/Bundles/Config/UnitConfigCategory.bytes

@@ -1,4 +1,4 @@
 
-/é	米克尔"带有强力攻击技能(0²
-1ê
-米克尔2"带有强力攻击技能2(0–
+1é	米克尔"带有强力攻击技能(0²8D
+3ê
+米克尔2"带有强力攻击技能2(0–8N

+ 1 - 0
Unity/Assets/Scripts/Codes/Model/Generate/Client/Config/AIConfig.cs

@@ -9,6 +9,7 @@ namespace ET
     [Config]
     public partial class AIConfigCategory : ProtoObject, IMerge
     {
+        [StaticField]
         public static AIConfigCategory Instance;
 		
         [ProtoIgnore]

+ 1 - 0
Unity/Assets/Scripts/Codes/Model/Generate/Client/Config/UnitConfig.cs

@@ -9,6 +9,7 @@ namespace ET
     [Config]
     public partial class UnitConfigCategory : ProtoObject, IMerge
     {
+        [StaticField]
         public static UnitConfigCategory Instance;
 		
         [ProtoIgnore]

+ 1 - 0
Unity/Assets/Scripts/Codes/Model/Generate/Server/Config/AIConfig.cs

@@ -9,6 +9,7 @@ namespace ET
     [Config]
     public partial class AIConfigCategory : ProtoObject, IMerge
     {
+        [StaticField]
         public static AIConfigCategory Instance;
 		
         [ProtoIgnore]

+ 1 - 0
Unity/Assets/Scripts/Codes/Model/Generate/Server/Config/StartMachineConfig.cs

@@ -9,6 +9,7 @@ namespace ET
     [Config]
     public partial class StartMachineConfigCategory : ProtoObject, IMerge
     {
+        [StaticField]
         public static StartMachineConfigCategory Instance;
 		
         [ProtoIgnore]

+ 1 - 0
Unity/Assets/Scripts/Codes/Model/Generate/Server/Config/StartProcessConfig.cs

@@ -9,6 +9,7 @@ namespace ET
     [Config]
     public partial class StartProcessConfigCategory : ProtoObject, IMerge
     {
+        [StaticField]
         public static StartProcessConfigCategory Instance;
 		
         [ProtoIgnore]

+ 1 - 0
Unity/Assets/Scripts/Codes/Model/Generate/Server/Config/StartSceneConfig.cs

@@ -9,6 +9,7 @@ namespace ET
     [Config]
     public partial class StartSceneConfigCategory : ProtoObject, IMerge
     {
+        [StaticField]
         public static StartSceneConfigCategory Instance;
 		
         [ProtoIgnore]

+ 1 - 0
Unity/Assets/Scripts/Codes/Model/Generate/Server/Config/StartZoneConfig.cs

@@ -9,6 +9,7 @@ namespace ET
     [Config]
     public partial class StartZoneConfigCategory : ProtoObject, IMerge
     {
+        [StaticField]
         public static StartZoneConfigCategory Instance;
 		
         [ProtoIgnore]

+ 1 - 0
Unity/Assets/Scripts/Codes/Model/Generate/Server/Config/UnitConfig.cs

@@ -9,6 +9,7 @@ namespace ET
     [Config]
     public partial class UnitConfigCategory : ProtoObject, IMerge
     {
+        [StaticField]
         public static UnitConfigCategory Instance;
 		
         [ProtoIgnore]

+ 1 - 0
Unity/Assets/Scripts/Codes/Model/Server/Module/Actor/ActorMessageDispatcherComponent.cs

@@ -22,6 +22,7 @@ namespace ET.Server
     [ComponentOf(typeof(Scene))]
     public class ActorMessageDispatcherComponent: Entity, IAwake, IDestroy, ILoad
     {
+        [StaticField]
         public static ActorMessageDispatcherComponent Instance;
 
         public readonly Dictionary<Type, List<ActorMessageDispatcherInfo>> ActorMessageHandlers = new();

+ 1 - 0
Unity/Assets/Scripts/Codes/Model/Server/Module/Actor/ActorMessageSenderComponent.cs

@@ -5,6 +5,7 @@ namespace ET.Server
     [ComponentOf(typeof(Scene))]
     public class ActorMessageSenderComponent: Entity, IAwake, IDestroy
     {
+        [StaticField]
         public static long TIMEOUT_TIME = 40 * 1000;
 
         public static ActorMessageSenderComponent Instance { get; set; }

+ 1 - 0
Unity/Assets/Scripts/Codes/Model/Server/Module/ActorLocation/LocationProxyComponent.cs

@@ -3,6 +3,7 @@
     [ComponentOf(typeof(Scene))]
     public class LocationProxyComponent: Entity, IAwake, IDestroy
     {
+        [StaticField()]
         public static LocationProxyComponent Instance;
     }
 }

+ 1 - 0
Unity/Assets/Scripts/Codes/Model/Server/Module/DB/DBManagerComponent.cs

@@ -4,6 +4,7 @@ namespace ET.Server
     
     public class DBManagerComponent: Entity, IAwake, IDestroy
     {
+        [StaticField]
         public static DBManagerComponent Instance;
         
         public DBComponent[] DBComponents = new DBComponent[IdGenerater.MaxZone];

+ 1 - 0
Unity/Assets/Scripts/Codes/Model/Server/Module/MessageInner/NetInnerComponent.cs

@@ -25,6 +25,7 @@ namespace ET.Server
     {
         public AService Service;
 
+        [StaticField]
         public static NetInnerComponent Instance;
 
         public int SessionStreamDispatcherType { get; set; }

+ 1 - 0
Unity/Assets/Scripts/Codes/Model/Server/Module/RobotCase/RobotCaseComponent.cs

@@ -6,6 +6,7 @@ namespace ET.Server
     [ComponentOf(typeof(Scene))]
     public class RobotCaseComponent: Entity, IAwake, IDestroy
     {
+        [StaticField]
         public static RobotCaseComponent Instance;
         public Dictionary<int, RobotCase> RobotCases = new Dictionary<int, RobotCase>();
         public int N = 10000;

+ 1 - 0
Unity/Assets/Scripts/Codes/Model/Server/Module/RobotCase/RobotCaseDispatcherComponent.cs

@@ -5,6 +5,7 @@ namespace ET.Server
     [ComponentOf(typeof(Scene))]
     public class RobotCaseDispatcherComponent: Entity, IAwake, ILoad
     {
+        [StaticField]
         public static RobotCaseDispatcherComponent Instance;
         
         public Dictionary<int, IRobotCase> Dictionary = new Dictionary<int, IRobotCase>();

+ 1 - 0
Unity/Assets/Scripts/Codes/Model/Share/Module/AI/AIDispatcherComponent.cs

@@ -5,6 +5,7 @@ namespace ET
     [ComponentOf(typeof(Scene))]
     public class AIDispatcherComponent: Entity, IAwake, IDestroy, ILoad
     {
+        [StaticField]
         public static AIDispatcherComponent Instance;
         
         public Dictionary<string, AAIHandler> AIHandlers = new Dictionary<string, AAIHandler>();

+ 1 - 0
Unity/Assets/Scripts/Codes/Model/Share/Module/Config/ConfigComponent.cs

@@ -20,6 +20,7 @@ namespace ET
             public string ConfigName;
         }
         
+        [StaticField]
         public static ConfigComponent Instance;
 		
         public Dictionary<Type, object> AllConfig = new Dictionary<Type, object>();

+ 1 - 0
Unity/Assets/Scripts/Codes/Model/Share/Module/CoroutineLock/CoroutineLockComponent.cs

@@ -181,6 +181,7 @@ namespace ET
     [ComponentOf(typeof(Scene))]
     public class CoroutineLockComponent: Entity, IAwake, IUpdate, IDestroy
     {
+        [StaticField]
         public static CoroutineLockComponent Instance;
 
         public List<CoroutineLockQueueType> list = new List<CoroutineLockQueueType>(CoroutineLockType.Max);

+ 1 - 0
Unity/Assets/Scripts/Codes/Model/Share/Module/Message/NetThreadComponent.cs

@@ -5,6 +5,7 @@ namespace ET
     [ComponentOf(typeof(Scene))]
     public class NetThreadComponent: Entity, IAwake, ILateUpdate, IDestroy
     {
+        [StaticField]
         public static NetThreadComponent Instance;
         
         public const int checkInteral = 2000;

+ 1 - 0
Unity/Assets/Scripts/Codes/Model/Share/Module/Message/OpcodeHelper.cs

@@ -4,6 +4,7 @@ namespace ET
 {
     public static class OpcodeHelper
     {
+        [StaticField]
         private static readonly HashSet<ushort> ignoreDebugLogMessageSet = new HashSet<ushort>
         {
             OuterOpcode.C2G_Ping,

+ 1 - 0
Unity/Assets/Scripts/Codes/Model/Share/Module/Message/OpcodeTypeComponent.cs

@@ -101,6 +101,7 @@ namespace ET
     [ComponentOf(typeof(Scene))]
     public class OpcodeTypeComponent: Entity, IAwake, IDestroy
     {
+        [StaticField]
         public static OpcodeTypeComponent Instance;
         
         public HashSet<ushort> outrActorMessage = new HashSet<ushort>();

+ 1 - 0
Unity/Assets/Scripts/Codes/Model/Share/Module/Recast/NavmeshComponent.cs

@@ -6,6 +6,7 @@ namespace ET
     [ComponentOf(typeof(Scene))]
     public class NavmeshComponent: Entity, IAwake
     {
+        [StaticField]
         public static NavmeshComponent Instance;
         
         public struct RecastFileLoader: ICallback

+ 1 - 0
Unity/Assets/Scripts/Codes/Model/Share/Module/Recast/PathfindingComponent.cs

@@ -10,6 +10,7 @@ namespace ET
     {
         public const int FindRandomNavPosMaxRadius = 15000;  // 随机找寻路点的最大半径
         
+        [StaticField]
         public static float[] extents = {15, 10, 15};
         
         public string Name;

+ 1 - 0
Unity/Assets/Scripts/Codes/Model/Share/Module/Scene/ClientSceneManagerComponent.cs

@@ -5,6 +5,7 @@ namespace ET
     [ComponentOf(typeof(Scene))]
     public class ClientSceneManagerComponent: Entity, IAwake, IDestroy
     {
+        [StaticField]
         public static ClientSceneManagerComponent Instance;
         public Dictionary<int, Scene> ClientScenes = new Dictionary<int, Scene>();
     }

+ 1 - 0
Unity/Assets/Scripts/Codes/ModelView/Client/Demo/Global/GlobalComponent.cs

@@ -5,6 +5,7 @@ namespace ET.Client
     [ComponentOf(typeof(Scene))]
     public class GlobalComponent: Entity, IAwake
     {
+        [StaticField]
         public static GlobalComponent Instance;
         
         public Transform Global;

+ 1 - 0
Unity/Assets/Scripts/Codes/ModelView/Client/Module/UI/UIEventComponent.cs

@@ -10,6 +10,7 @@ namespace ET.Client
 	[ComponentOf(typeof(Scene))]
 	public class UIEventComponent: Entity, IAwake
 	{
+		[StaticField]
 		public static UIEventComponent Instance;
 		
 		public Dictionary<string, AUIEvent> UIEvents = new Dictionary<string, AUIEvent>();

+ 2 - 0
Unity/Assets/Scripts/Core/Entity/Game.cs

@@ -5,7 +5,9 @@ namespace ET
 {
     public static class Game
     {
+        [StaticField]
         private static readonly Dictionary<Type, ISingleton> singletonTypes = new Dictionary<Type, ISingleton>();
+        [StaticField]
         private static readonly Stack<ISingleton> singletons = new Stack<ISingleton>();
 
         public static T AddSingleton<T>() where T: Singleton<T>, new()

+ 2 - 0
Unity/Assets/Scripts/Core/Helper/RandomHelper.cs

@@ -6,8 +6,10 @@ namespace ET
 {
     public static class RandomHelper
     {
+        [StaticField]
         private static readonly Random random = new Random(Guid.NewGuid().GetHashCode());
 
+        [StaticField]
         private static readonly byte[] byte8 = new byte[8];
 
         public static ulong RandUInt64()

+ 1 - 0
Unity/Assets/Scripts/Core/JsonHelper.cs

@@ -4,6 +4,7 @@ namespace ET
 {
     public static class JsonHelper
     {
+        [StaticField]
         private static readonly MongoDB.Bson.IO.JsonWriterSettings logDefineSettings = new MongoDB.Bson.IO.JsonWriterSettings() { OutputMode = MongoDB.Bson.IO.JsonOutputMode.RelaxedExtendedJson };
         
         public static string ToJson(object message)

+ 1 - 0
Unity/Assets/Scripts/Core/Network/KChannel.cs

@@ -15,6 +15,7 @@ namespace ET
 	
 	public class KChannel : AChannel
 	{
+		[StaticField]
 		public static readonly Dictionary<IntPtr, KChannel> KcpPtrChannels = new Dictionary<IntPtr, KChannel>();
 		
 		public KService Service;

+ 2 - 1
Unity/Assets/Scripts/Core/Network/KService.cs

@@ -51,7 +51,8 @@ namespace ET
             //Kcp.KcpSetLog(KcpLog);
             Kcp.KcpSetoutput(KcpOutput);
         }
-
+        
+        [StaticField]
         private static readonly byte[] logBuffer = new byte[1024];
 
 #if ENABLE_IL2CPP

+ 36 - 0
Unity/Assets/Scripts/Core/Object/StaticFieldAttribute.cs

@@ -0,0 +1,36 @@
+using System;
+
+namespace ET
+{
+    /// <summary>
+    /// 静态字段需加此标签
+    /// valueToAssign: 初始化时的字段值
+    /// assignNewTypeInstance: 从默认构造函数初始化
+    /// </summary>
+    [AttributeUsage(AttributeTargets.Field)]
+    public class StaticFieldAttribute: Attribute
+    {
+        public readonly object valueToAssign;
+
+        public readonly bool assignNewTypeInstance;
+        
+        public StaticFieldAttribute()
+        {
+            this.valueToAssign  = null;
+            this.assignNewTypeInstance = false;
+        }
+        
+        public StaticFieldAttribute(object valueToAssign )
+        {
+            this.valueToAssign  = valueToAssign ;
+            this.assignNewTypeInstance = false;
+        }
+        
+        public StaticFieldAttribute(bool assignNewTypeInstance)
+        {
+            this.valueToAssign  = null;
+            this.assignNewTypeInstance = assignNewTypeInstance;
+        }
+    }
+}
+

+ 3 - 0
Unity/Assets/Scripts/Core/Object/StaticFieldAttribute.cs.meta

@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: b8f63d66747f41e687b47fedf3271efc
+timeCreated: 1661086305

+ 1 - 0
Unity/Assets/Scripts/Core/Singleton.cs

@@ -10,6 +10,7 @@ namespace ET
     
     public abstract class Singleton<T>: ISingleton, IDisposable where T: Singleton<T>, new()
     {
+        [StaticField]
         private static T instance;
 
         public static T Instance

+ 5 - 0
Unity/Assets/Scripts/Editor/AssetPostProcessor/OnGenerateCSProjectProcessor.cs

@@ -82,6 +82,11 @@ namespace ET
                     @"Assets\Scripts\Codes\Plugins\*\ModelView\Client\**\*.cs Share\Plugins\$([System.String]::new(%(RecursiveDir)).Replace('ModelView\Client',''))%(FileName)%(Extension)"
                     );
             }
+
+            if (path.EndsWith("Unity.Core.csproj"))
+            {
+                return GenerateCustomProject(path, content);
+            }
             return content;
         }