Przeglądaj źródła

增加一个脚本用来移动Library/PackageCache下的cn.etetet包到Packages目录下
这里有个问题很奇怪,如果在Unity编辑器下调用Directory.Move方法去移动会报这是同一个目录的错误
所以我只能写个powershell脚本来执行,大家在下载完et包,手动点一下ET->MoveToPackages
暂未找到更好的办法

tanghai 1 rok temu
rodzic
commit
d7082edb8a

+ 11 - 0
Packages/cn.etetet.init/Editor/GitDependencyResolver/DependencyResolver.cs

@@ -2,6 +2,7 @@ using System;
 using System.Collections.Generic;
 using System.IO;
 using System.Linq;
+using ET;
 using MongoDB.Bson.Serialization;
 using MongoDB.Bson.Serialization.Attributes;
 using UnityEditor;
@@ -22,6 +23,16 @@ namespace Hibzz.DependencyResolver
     [InitializeOnLoad]
     public class DependencyResolver
     {
+        [MenuItem("ET/MoveToPackages")]
+        static void MoveToPackage()
+        {
+#if UNITY_EDITOR_WIN
+            ProcessHelper.Run("powershell.exe", $"-NoExit -ExecutionPolicy Bypass -File \"Scripts/MoveToPackages.ps1\"");
+#else
+            ProcessHelper.Run("pwsh", $"-NoExit -ExecutionPolicy Bypass -File \"Scripts/MoveToPackages.ps1\"");
+#endif
+        }
+        
         static AddAndRemoveRequest packageInstallationRequest;
 
         // called by the attribute [InitializeOnLoad]

+ 104 - 0
Packages/cn.etetet.init/Editor/GitDependencyResolver/ProcessHelper.cs

@@ -0,0 +1,104 @@
+using System;
+using System.Diagnostics;
+using System.Runtime.InteropServices;
+using System.Threading.Tasks;
+using Debug = UnityEngine.Debug;
+using Path = System.IO.Path;
+
+namespace ET
+{
+    public static class ProcessHelper
+    {
+        public static System.Diagnostics.Process Run(string exe, string arguments, string workingDirectory = ".", bool waitExit = false)
+        {
+            //Log.Debug($"Process Run exe:{exe} ,arguments:{arguments} ,workingDirectory:{workingDirectory}");
+            try
+            {
+                bool redirectStandardOutput = false;
+                bool redirectStandardError = false;
+                bool useShellExecute = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
+                
+                if (waitExit)
+                {
+                    redirectStandardOutput = true;
+                    redirectStandardError = true;
+                    useShellExecute = false;
+                }
+                
+                ProcessStartInfo info = new ProcessStartInfo
+                {
+                    FileName = exe,
+                    Arguments = arguments,
+                    CreateNoWindow = true,
+                    UseShellExecute = useShellExecute,
+                    WorkingDirectory = workingDirectory,
+                    RedirectStandardOutput = redirectStandardOutput,
+                    RedirectStandardError = redirectStandardError,
+                };
+
+                System.Diagnostics.Process process = System.Diagnostics.Process.Start(info);
+
+                if (waitExit)
+                {
+                    WaitExitAsync(process);
+                }
+
+                return process;
+            }
+            catch (Exception e)
+            {
+                throw new Exception($"dir: {Path.GetFullPath(workingDirectory)}, command: {exe} {arguments}", e);
+            }
+        }
+        
+        private static async Task WaitExitAsync(System.Diagnostics.Process process)
+        {
+            await process.WaitForExitAsync();
+#if UNITY
+            Debug.Log($"process exit, exitcode: {process.ExitCode} {process.StandardOutput.ReadToEnd()} {process.StandardError.ReadToEnd()}");
+#endif
+        }
+        
+#if UNITY
+        private static async Task WaitForExitAsync(this System.Diagnostics.Process self)
+        {
+            if (!self.HasExited)
+            {
+                return;
+            }
+
+            try
+            {
+                self.EnableRaisingEvents = true;
+            }
+            catch (InvalidOperationException)
+            {
+                if (self.HasExited)
+                {
+                    return;
+                }
+                throw;
+            }
+
+            var tcs = new TaskCompletionSource<bool>();
+
+            void Handler(object s, EventArgs e) => tcs.TrySetResult(true);
+            
+            self.Exited += Handler;
+
+            try
+            {
+                if (self.HasExited)
+                {
+                    return;
+                }
+                await tcs.Task;
+            }
+            finally
+            {
+                self.Exited -= Handler;
+            }
+        }
+#endif
+    }
+}

+ 3 - 0
Packages/cn.etetet.init/Editor/GitDependencyResolver/ProcessHelper.cs.meta

@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: ccaaea073a3b40a2846475a3370549cf
+timeCreated: 1718016690

+ 6 - 0
Packages/packages-lock.json

@@ -1,5 +1,11 @@
 {
   "dependencies": {
+    "cn.etetet.init": {
+      "version": "file:cn.etetet.init",
+      "depth": 0,
+      "source": "embedded",
+      "dependencies": {}
+    },
     "com.unity.ai.navigation": {
       "version": "1.1.5",
       "depth": 0,

+ 0 - 0
CodeLinker.ps1 → Scripts/CodeLinker.ps1


+ 18 - 0
Scripts/MoveToPackages.ps1

@@ -0,0 +1,18 @@
+foreach($dir in Get-ChildItem "Library/PackageCache")
+{
+    if (!($dir -is [System.IO.DirectoryInfo]))
+    {
+        continue
+    }
+
+    if ($dir.Name.StartsWith("cn.etetet"))
+    {
+        $baseName = $dir.Name.Substring(0, $dir.Name.indexOf("@"))
+             
+        Move-Item "Library/PackageCache/$dir" "Packages/$baseName"
+        Write-Host "move Library/PackageCache/$dir to Packages/$baseName"
+    }  
+}
+
+Write-Host "move finish!"
+#Read-Host -Prompt "Press Enter to exit"

+ 0 - 0
Publish-linux-x64.ps1 → Scripts/Publish-linux-x64.ps1