🌭食用方法
先导入插件包👈,再 把导入的ZYF_AutoRunApp.cs
挂到物体上即可。文章来源地址https://www.toymoban.com/news/detail-851438.html
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
namespace ZYF
{
public class ZYF_AutoRunApp : MonoBehaviour
{
private static string ShortcutName = "zyf.lnk";
private void OnEnable()
{
//Debug.Log(Environment.GetFolderPath(Environment.SpecialFolder.Startup));
if (IsStartup() == false && Application.isEditor == false)
{
ShortcutName = $"{Application.productName}.lnk";
SetupStartup(exePath: System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName,shortCutName: ShortcutName);
}
}
public static void SetupStartup(string exePath ,string shortCutName="xxx.lnk")
{
CreateShortcut(Environment.GetFolderPath(Environment.SpecialFolder.Startup),shortCutName,targetPath:exePath);
}
private bool IsStartup()
{
return System.IO.File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.Startup) + "\\" + ShortcutName);
}
public static bool CreateShortcut(string directory, string shortcurName, string targetPath, string description = null, string iconLocation = null)
{
try
{
if (!Directory.Exists(directory))
{
Directory.CreateDirectory(directory);
}
....
return true;
}
catch
{
}
return false;
}
private static void DeleteOldShortcut(string shortscurPath)
{
if (System.IO.File.Exists(shortscurPath)) {
System.IO.File.Delete(shortscurPath);
Debug.Log($"删除旧的:{shortscurPath}");
}
}
}
}
文章来源:https://www.toymoban.com/news/detail-851438.html
到了这里,关于Unity 创建快捷方式开机自动启动的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!