Prechádzať zdrojové kódy

添加HybridCLR 自动安装

baxi 2 týždňov pred
rodič
commit
a53ed6f7ba

+ 1 - 0
CHANGELOG.md

@@ -2,6 +2,7 @@
 
 ## Unreleased — Hot Patch
 
+- Automatically install the missing HybridCLR UPM Git package after import, preserve existing installations, and expose installation status and retry in AppSettings.
 - Resolve the current UPM package name when normalizing Xcode Frameworks/Libraries paths, removing the come.runtimes.hot wrapper after export.
 - Keep Sources as Editor-only C# templates; synchronize them into HexaCrazy.Runtime without the marked outer UNITY_EDITOR envelope.
 - Add DownloadUrl, manifest validation, verified cache, AOT metadata loading and automatic patched initialization.

+ 11 - 1
Documentation~/HotPatch.md

@@ -2,13 +2,23 @@
 
 Resources are split into three AssetBundles: AOT, hot-update assembly, and game scene. Original resources contain all three bundles. Update resources contain only the assembly and scene bundles. AOT is fixed in the installed application and is never updated from the server.
 
+## Package installation
+
+Install AppRuntimes through Package Manager using its Git URL. Once the Editor finishes importing, an independent Editor assembly checks for `com.code-philosophy.hybridclr`. If missing, it uses Unity Package Manager to add `https://gitee.com/focus-creative-games/hybridclr_unity.git#v9.0.3` to the project's dependencies. It preserves an existing HybridCLR package, including Git, registry, embedded, and local installations.
+
+Unity does not support Git dependencies inside a package's `package.json`; Git URLs must be project dependencies. The installer therefore uses `Client.Add` instead of declaring an invalid package dependency or editing another project's manifest directly. See [Unity Git dependencies](https://docs.unity3d.com/6000.3/Documentation/Manual/upm-git.html).
+
+Installation runs asynchronously after compilation and import finish. A failed attempt does not repeat on every domain reload. Open AppSettings and select **Retry HybridCLR Installation**, or add the URL manually through Package Manager. The official GitHub alternative is `https://github.com/focus-creative-games/hybridclr_unity.git#v9.0.3`. Projects with existing script compilation errors may need this manual installation before Editor initialization can run. Wait for installation and compilation before clicking Save.
+
+Adding the UPM package and running `HybridCLR/Installer` are separate steps. **一键打包资源** still performs Installer setup and Generate/All when needed; the package import step does not build a Player or modify IL2CPP. See [HybridCLR installation](https://www.hybridclr.cn/docs/basic/install).
+
 ## Configuration
 
 In `AppSettings/Open Settings`, select the hot-update asmdef, enter the **Game Scene Name** and **DownloadUrl**, then click Save. The current configuration is `HexaCrazy.Runtime` / `HexaCrazy`. The scene name excludes `.unity` and must be unique under Assets. Selecting an assembly synchronizes the HybridCLR hot-update settings.
 
 DownloadUrl accepts a resource directory (automatically appending `manifest.json`) or a complete manifest URL. When accessing a local IIS server from a phone, use the computer's LAN IP address or domain name instead of `localhost`. HTTP debugging requires HTTP to be enabled in Player Settings; use HTTPS for releases.
 
-The game scene is provided by its bundle and excluded from the Player scene list. Build commands remove the configured game scene from both the global scene list and the active Build Profile, while preserving Launch and other scenes. Keep the game scene's own MonoBehaviours. Launch does not look up or call `HexSceneEntry.Enter`.
+The game scene is provided by its bundle and excluded from the Player scene list. Resource builds first normalize the global scene list and any active Build Profile override to a single enabled Launch scene. Other entries are removed from the list; scene assets are retained. Keep the game scene's own MonoBehaviours. Launch loads the configured scene without a separate game-entry call.
 
 ## Bundle strategy
 

+ 1 - 0
Editor/AppRuntimes.Editor.asmdef

@@ -3,6 +3,7 @@
   "rootNamespace": "",
   "references": [
     "AppRuntimes",
+    "AppRuntimes.PackageSetup.Editor",
     "UniWebView-CSharp.Editor",
     "AppRuntimes.Base",
     "AppRuntimes.Sources.Editor"

+ 14 - 0
Editor/AppSettingsWindow.cs

@@ -97,6 +97,7 @@ public sealed class AppSettingsWindow : EditorWindow
     private void DrawWindow()
     {
         scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition);
+        DrawHybridCLRSetup();
         EditorGUILayout.LabelField("Facebook", EditorStyles.boldLabel);
         if (facebook == null)
             EditorGUILayout.HelpBox("FacebookSettings.asset was not found in Resources.", MessageType.Error);
@@ -140,6 +141,19 @@ public sealed class AppSettingsWindow : EditorWindow
         EditorGUILayout.EndScrollView();
     }
 
+    private void DrawHybridCLRSetup()
+    {
+        if (HybridCLRPackageSetup.IsInstalled) return;
+        var installing = HybridCLRPackageSetup.IsInstalling;
+        var message = installing ? "Installing the HybridCLR package. Wait for installation and compilation to finish." :
+            "The HybridCLR package is required. Retry installation or add the following Git URL in Package Manager:\n" + HybridCLRPackageSetup.PackageUrl;
+        if (!string.IsNullOrEmpty(HybridCLRPackageSetup.LastError)) message += "\n" + HybridCLRPackageSetup.LastError;
+        EditorGUILayout.HelpBox(message, installing ? MessageType.Info : MessageType.Warning);
+        using (new EditorGUI.DisabledScope(installing || EditorApplication.isCompiling || EditorApplication.isPlayingOrWillChangePlaymode || BuildPipeline.isBuildingPlayer))
+            if (GUILayout.Button("Retry HybridCLR Installation")) HybridCLRPackageSetup.RetryInstallation();
+        if (installing) Repaint();
+    }
+
     private void DrawS3Settings()
     {
         showS3Settings = EditorGUILayout.Foldout(showS3Settings, "S3 上传配置(仅本机)", true);

+ 8 - 0
Editor/PackageSetup.meta

@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: bca5d8c30dcac3e46bb608c18b537309
+folderAsset: yes
+DefaultImporter:
+  externalObjects: {}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 8 - 0
Editor/PackageSetup/AppRuntimes.PackageSetup.Editor.asmdef

@@ -0,0 +1,8 @@
+{
+  "name": "AppRuntimes.PackageSetup.Editor",
+  "references": [],
+  "includePlatforms": ["Editor"],
+  "overrideReferences": true,
+  "precompiledReferences": [],
+  "autoReferenced": true
+}

+ 7 - 0
Editor/PackageSetup/AppRuntimes.PackageSetup.Editor.asmdef.meta

@@ -0,0 +1,7 @@
+fileFormatVersion: 2
+guid: a309ca78b741f4641a2cc8dbdb340e0d
+AssemblyDefinitionImporter:
+  externalObjects: {}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 95 - 0
Editor/PackageSetup/HybridCLRPackageSetup.cs

@@ -0,0 +1,95 @@
+using System;
+using System.Linq;
+using UnityEditor;
+using UnityEditor.PackageManager;
+using UnityEditor.PackageManager.Requests;
+using UnityEngine;
+
+[InitializeOnLoad]
+public static class HybridCLRPackageSetup
+{
+    public const string PackageName = "com.code-philosophy.hybridclr";
+    public const string PackageUrl = "https://gitee.com/focus-creative-games/hybridclr_unity.git#v9.0.3";
+    const string AttemptedKey = "AppRuntimes.HybridCLR.PackageAttempted";
+    const string ErrorKey = "AppRuntimes.HybridCLR.PackageError";
+    static AddRequest request;
+    static bool scheduled;
+    static double nextCheck;
+
+    public static bool IsInstalled => UnityEditor.PackageManager.PackageInfo.GetAllRegisteredPackages().Any(package => package.name == PackageName);
+    public static bool IsInstalling => request != null || scheduled && !IsInstalled;
+    public static string LastError => SessionState.GetString(ErrorKey, "");
+
+    static HybridCLRPackageSetup() => Schedule();
+
+    public static void RetryInstallation()
+    {
+        if (request != null || IsInstalled) return;
+        SessionState.EraseBool(AttemptedKey);
+        SessionState.EraseString(ErrorKey);
+        Schedule();
+    }
+
+    static void Schedule()
+    {
+        scheduled = true;
+        nextCheck = EditorApplication.timeSinceStartup + 1;
+        EditorApplication.update -= Update;
+        EditorApplication.update += Update;
+    }
+
+    static void StopChecking()
+    {
+        scheduled = false;
+        EditorApplication.update -= Update;
+    }
+
+    static void Update()
+    {
+        if (request != null)
+        {
+            if (!request.IsCompleted) return;
+            var completed = request;
+            request = null;
+            StopChecking();
+            if (completed.Status == StatusCode.Success)
+            {
+                SessionState.EraseString(ErrorKey);
+                Debug.Log("[AppRuntimes] HybridCLR package installed. Wait for compilation, then configure AppSettings and build resources.");
+            }
+            else ReportFailure(completed.Error?.message ?? "Package Manager did not return an error message.");
+            return;
+        }
+        if (EditorApplication.timeSinceStartup < nextCheck || EditorApplication.isCompiling || EditorApplication.isUpdating ||
+            EditorApplication.isPlayingOrWillChangePlaymode || BuildPipeline.isBuildingPlayer) return;
+        if (IsInstalled)
+        {
+            SessionState.EraseString(ErrorKey);
+            StopChecking();
+            return;
+        }
+        if (SessionState.GetBool(AttemptedKey, false))
+        {
+            StopChecking();
+            return;
+        }
+        SessionState.SetBool(AttemptedKey, true);
+        try
+        {
+            Debug.Log("[AppRuntimes] Installing the missing HybridCLR package: " + PackageUrl);
+            request = Client.Add(PackageUrl);
+        }
+        catch (Exception exception)
+        {
+            StopChecking();
+            ReportFailure(exception.Message);
+        }
+    }
+
+    static void ReportFailure(string message)
+    {
+        SessionState.SetString(ErrorKey, message);
+        Debug.LogWarning("[AppRuntimes] HybridCLR package installation failed: " + message +
+            "\nOpen AppSettings and retry, or add this Git URL in Package Manager: " + PackageUrl);
+    }
+}

+ 2 - 0
Editor/PackageSetup/HybridCLRPackageSetup.cs.meta

@@ -0,0 +1,2 @@
+fileFormatVersion: 2
+guid: fe9a0cb0483b5094e92d93015d00e6e2

+ 2 - 0
README.md

@@ -2,6 +2,8 @@
 
 Unity AppRuntimes package with a HybridCLR hot patch module.
 
+After importing AppRuntimes through Package Manager, the Editor automatically installs the missing `com.code-philosophy.hybridclr` package from the official Git mirror at `v9.0.3`. Existing HybridCLR installations are preserved. AppSettings shows installation status and a retry button if installation fails. See [package installation](Documentation~/HotPatch.md#package-installation) for details.
+
 AppSettings includes 上传资源 for recursive S3 uploads. See the [S3 upload guide](Documentation~/S3Upload.md) for local credentials, destination paths, and manifest publication order.
 
 The [Hot Patch guide](Documentation~/HotPatch.md) covers the Sources wrapper, original and update resource builds, DownloadUrl, and incremental resource updates.

+ 2 - 2
package.json

@@ -2,7 +2,7 @@
   "name": "come.runtimes.hot",
   "version": "1.0.2",
   "displayName": "AppRuntimes",
-  "description": "Shared AppRuntimes library with bundled UniTask, UniWebView, Facebook SDK, External Dependency Manager and GUPS.",
+  "description": "Shared AppRuntimes library with HybridCLR package setup, bundled UniTask, UniWebView, Facebook SDK, External Dependency Manager and GUPS.",
   "unity": "6000.3",
   "author": {
     "name": "AppRuntimes"
@@ -23,4 +23,4 @@
       "path": "Samples~/AppStartup"
     }
   ]
-}
+}