1
This commit is contained in:
@@ -6,7 +6,9 @@
|
||||
"GUID:f51ebe6a0ceec4240a699833d6309b23",
|
||||
"GUID:be17a8778dbfe454890ed8279279e153",
|
||||
"GUID:14fe60d984bf9f84eac55c6ea033a8f4",
|
||||
"GUID:9400d40641bab5b4a9702f65bf5c6eb5"
|
||||
"GUID:9400d40641bab5b4a9702f65bf5c6eb5",
|
||||
"GUID:d525ad6bd40672747bde77962f1c401e",
|
||||
"GUID:49b49c76ee64f6b41bf28ef951cb0e50"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
|
@@ -11,9 +11,9 @@ namespace BITKit
|
||||
public class RegistryRunAPP : MonoBehaviour
|
||||
{
|
||||
[Header(Constant.Header.Settings)]
|
||||
public string subKey;
|
||||
public string excutablePath;
|
||||
public bool excuteOnStart;
|
||||
[SerializeReference,SubclassSelector] private IReference subKey;
|
||||
[SerializeReference,SubclassSelector] private string executablePath;
|
||||
private bool executeOnStart;
|
||||
[Header(Constant.Header.Events)]
|
||||
public UnityEvent<bool> onSuccess = new();
|
||||
public UnityEvent onfailure = new();
|
||||
@@ -23,7 +23,7 @@ namespace BITKit
|
||||
{
|
||||
Debug.Log("正在启动注册函数");
|
||||
var path = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
|
||||
var result = RegisterAppKey(subKey, path);
|
||||
var result = RegisterAppKey(subKey.Value, path);
|
||||
Debug.Log($"正在注册启动:{subKey}:{path}");
|
||||
if (result)
|
||||
{
|
||||
@@ -46,7 +46,7 @@ namespace BITKit
|
||||
async void Start()
|
||||
{
|
||||
await UniTask.Yield();
|
||||
if (excuteOnStart) Excute();
|
||||
if (executeOnStart) Excute();
|
||||
}
|
||||
private static bool RegisterAppKey(string keyName, string value)
|
||||
{
|
||||
|
67
Src/Unity/Scripts/Win64/UnitySubApp.cs
Normal file
67
Src/Unity/Scripts/Win64/UnitySubApp.cs
Normal file
@@ -0,0 +1,67 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
|
||||
namespace BITKit
|
||||
{
|
||||
public class UnitySubApp : MonoBehaviour,IAction
|
||||
{
|
||||
[SerializeReference,SubclassSelector] private IReference path;
|
||||
[SerializeReference,SubclassSelector] private IReference arguments;
|
||||
[SerializeField] private bool isStreamingAssets;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
Execute();
|
||||
}
|
||||
public void Execute()
|
||||
{
|
||||
var StartInfo = new ProcessStartInfo
|
||||
{
|
||||
FileName =isStreamingAssets ? Path.Combine(Application.streamingAssetsPath, path.Value) : path.Value,
|
||||
WorkingDirectory =Environment.CurrentDirectory,
|
||||
UseShellExecute = false,
|
||||
CreateNoWindow = true,
|
||||
RedirectStandardOutput = true,
|
||||
RedirectStandardError =true,
|
||||
StandardErrorEncoding = System.Text.Encoding.GetEncoding("gb2312"),
|
||||
//StandardInputEncoding = System.Text.Encoding.GetEncoding("gb2312"),
|
||||
StandardOutputEncoding = System.Text.Encoding.GetEncoding("gb2312"),
|
||||
};
|
||||
if(arguments != null)
|
||||
{
|
||||
StartInfo.Arguments = arguments.Value;
|
||||
}
|
||||
var process = new Process()
|
||||
{
|
||||
StartInfo = StartInfo,
|
||||
};
|
||||
|
||||
process.OutputDataReceived += (sender, args) =>
|
||||
{
|
||||
BIT4Log.Log<UnitySubApp>(args.Data);
|
||||
};
|
||||
process.ErrorDataReceived += (sender, args) =>
|
||||
{
|
||||
BIT4Log.Warning<UnitySubApp>(args.Data);
|
||||
};
|
||||
|
||||
BIT4Log.Log<UnitySubApp>($"已创建进程:{StartInfo.FileName}");
|
||||
|
||||
process.Start();
|
||||
|
||||
process.BeginErrorReadLine();
|
||||
process.BeginOutputReadLine();
|
||||
|
||||
destroyCancellationToken.Register(()=>
|
||||
{
|
||||
if(process.HasExited is false)
|
||||
process.Kill();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
11
Src/Unity/Scripts/Win64/UnitySubApp.cs.meta
Normal file
11
Src/Unity/Scripts/Win64/UnitySubApp.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ddd3add402b85d442a6401327d8ad500
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user