Просмотр исходного кода

去除MoveComponent中的Action字段

tanghai 3 лет назад
Родитель
Сommit
bb054cbbe2

+ 1 - 1
Apps/Core/Apps.Core.csproj

@@ -13,7 +13,7 @@
       <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
     </PropertyGroup>
 
-    <PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
+    <PropertyGroup Condition=" '$(Configuration)' == 'Release' "> 
       <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
       <DefineConstants>TRACE;APPS</DefineConstants>
       <OutputPath>..\..\Bin\</OutputPath>

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

@@ -36,7 +36,7 @@ namespace ET.Analyzer
             }
             context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None);
             context.EnableConcurrentExecution();
-            //context.RegisterSymbolAction(this.Analyzer, SymbolKind.NamedType);
+            context.RegisterSymbolAction(this.Analyzer, SymbolKind.NamedType);
         }
 
         private void Analyzer(SymbolAnalysisContext context)

+ 18 - 21
Unity/Codes/Hotfix/Module/Move/MoveComponentSystem.cs

@@ -41,7 +41,7 @@ namespace ET
                 self.StartPos = Vector3.zero;
                 self.NeedTime = 0;
                 self.MoveTimer = 0;
-                self.Callback = null;
+                self.tcs = null;
                 self.Targets.Clear();
                 self.Speed = 0;
                 self.N = 0;
@@ -68,17 +68,16 @@ namespace ET
             
             Unit unit = self.GetParent<Unit>();
 
-            using (ListComponent<Vector3> path = ListComponent<Vector3>.Create())
-            {
-                self.MoveForward(true);
+            using ListComponent<Vector3> path = ListComponent<Vector3>.Create();
+            
+            self.MoveForward(true);
                 
-                path.Add(unit.Position); // 第一个是Unit的pos
-                for (int i = self.N; i < self.Targets.Count; ++i)
-                {
-                    path.Add(self.Targets[i]);
-                }
-                self.MoveToAsync(path, speed).Coroutine();
+            path.Add(unit.Position); // 第一个是Unit的pos
+            for (int i = self.N; i < self.Targets.Count; ++i)
+            {
+                path.Add(self.Targets[i]);
             }
+            self.MoveToAsync(path, speed).Coroutine();
             return true;
         }
 
@@ -94,8 +93,7 @@ namespace ET
             self.IsTurnHorizontal = true;
             self.TurnTime = turnTime;
             self.Speed = speed;
-            ETTask<bool> tcs = ETTask<bool>.Create(true);
-            self.Callback = (ret) => { tcs.SetResult(ret); };
+            self.tcs = ETTask<bool>.Create(true);
 
             Game.EventSystem.Publish(self.GetParent<Unit>(), new EventType.MoveStart());
             
@@ -110,7 +108,7 @@ namespace ET
             try
             {
                 cancellationToken?.Add(CancelAction);
-                moveRet = await tcs;
+                moveRet = await self.tcs;
             }
             finally
             {
@@ -182,11 +180,10 @@ namespace ET
                     unit.Position = self.NextTarget;
                     unit.Rotation = self.To;
 
-                    Action<bool> callback = self.Callback;
-                    self.Callback = null;
-
+                    var tcs = self.tcs;
+                    self.tcs = null;
                     self.Clear();
-                    callback?.Invoke(!needCancel);
+                    tcs?.SetResult(!needCancel);
                     return;
                 }
 
@@ -296,11 +293,11 @@ namespace ET
             self.TurnTime = 0;
             self.IsTurnHorizontal = false;
 
-            if (self.Callback != null)
+            if (self.tcs != null)
             {
-                Action<bool> callback = self.Callback;
-                self.Callback = null;
-                callback.Invoke(false);
+                var tcs = self.tcs;
+                self.tcs = null;
+                tcs.SetResult(false);
             }
         }
     }

+ 1 - 1
Unity/Codes/Model/Module/Move/MoveComponent.cs

@@ -58,7 +58,7 @@ namespace ET
 
         public float Speed; // m/s
 
-        public Action<bool> Callback;
+        public ETTask<bool> tcs;
 
         public List<Vector3> Targets = new List<Vector3>();