更改文件架构
This commit is contained in:
20
Packages/Common~/Scripts/Win64/BITKit.Win64.asmdef
Normal file
20
Packages/Common~/Scripts/Win64/BITKit.Win64.asmdef
Normal file
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"name": "BITKit.Win64",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:a209c53514018594f9f482516f2a6781",
|
||||
"GUID:f51ebe6a0ceec4240a699833d6309b23",
|
||||
"GUID:be17a8778dbfe454890ed8279279e153",
|
||||
"GUID:14fe60d984bf9f84eac55c6ea033a8f4",
|
||||
"GUID:9400d40641bab5b4a9702f65bf5c6eb5"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
7
Packages/Common~/Scripts/Win64/BITKit.Win64.asmdef.meta
Normal file
7
Packages/Common~/Scripts/Win64/BITKit.Win64.asmdef.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8de800285228f744ab0baba715e4a5c2
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
89
Packages/Common~/Scripts/Win64/RegistryRunAPP.cs
Normal file
89
Packages/Common~/Scripts/Win64/RegistryRunAPP.cs
Normal file
@@ -0,0 +1,89 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Microsoft.Win32;
|
||||
using UnityEngine.Events;
|
||||
using System.Security.Principal;
|
||||
using Cysharp.Threading.Tasks;
|
||||
namespace BITKit
|
||||
{
|
||||
public class RegistryRunAPP : MonoBehaviour
|
||||
{
|
||||
[Header(Constant.Header.Settings)]
|
||||
public string subKey;
|
||||
public string excutablePath;
|
||||
public bool excuteOnStart;
|
||||
[Header(Constant.Header.Events)]
|
||||
public UnityEvent<bool> onSuccess = new();
|
||||
public UnityEvent onfailure = new();
|
||||
public void Excute()
|
||||
{
|
||||
try
|
||||
{
|
||||
Debug.Log("正在启动注册函数");
|
||||
var path = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
|
||||
var result = RegisterAppKey(subKey, path);
|
||||
Debug.Log($"正在注册启动:{subKey}:{path}");
|
||||
if (result)
|
||||
{
|
||||
onSuccess.Invoke(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
onfailure.Invoke();
|
||||
}
|
||||
|
||||
}
|
||||
catch (System.Exception e)
|
||||
{
|
||||
Debug.LogError(e);
|
||||
Debug.LogException(e,this);
|
||||
onfailure.Invoke();
|
||||
}
|
||||
|
||||
}
|
||||
async void Start()
|
||||
{
|
||||
await UniTask.Yield();
|
||||
if (excuteOnStart) Excute();
|
||||
}
|
||||
private static bool RegisterAppKey(string keyName, string value)
|
||||
{
|
||||
#if UNITY_WEBGL
|
||||
Debug.LogWarning("在WebGL上无法注册启动方式");
|
||||
return false;
|
||||
#else
|
||||
try
|
||||
{
|
||||
RegistryKey registryKey = Registry.ClassesRoot;
|
||||
var fKey = registryKey.OpenSubKey(keyName, true)
|
||||
?? registryKey.CreateSubKey(keyName);
|
||||
fKey.SetValue("", value);
|
||||
fKey.SetValue("", keyName);
|
||||
var defaultIconKey = fKey.OpenSubKey("DefaultIcon", true) ?? fKey.CreateSubKey("DefaultIcon");
|
||||
if (defaultIconKey != null)
|
||||
{
|
||||
defaultIconKey.SetValue("", value + ",1");
|
||||
}
|
||||
var shellKey = fKey.OpenSubKey("shell", true) ?? fKey.CreateSubKey("shell");
|
||||
var openKey = shellKey.OpenSubKey("open", true) ?? shellKey.CreateSubKey("open");
|
||||
var commandKey = openKey.OpenSubKey("command", true) ?? openKey.CreateSubKey("command");
|
||||
if (commandKey != null)
|
||||
{
|
||||
commandKey.SetValue("", "\"" + value + "\"" + " \"%1\"");
|
||||
}
|
||||
fKey.SetValue("URL Protocol", value);
|
||||
fKey.Close();
|
||||
Debug.Log("已完成程序启动注册");
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.LogException(ex);
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
11
Packages/Common~/Scripts/Win64/RegistryRunAPP.cs.meta
Normal file
11
Packages/Common~/Scripts/Win64/RegistryRunAPP.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f1244389cfc9d114b9b7ebc6913948d6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user