a亚洲精品_精品国产91乱码一区二区三区_亚洲精品在线免费观看视频_欧美日韩亚洲国产综合_久久久久久久久久久成人_在线区

首頁 > 編程 > C > 正文

Unity編輯器下重啟的方法

2020-02-24 14:30:43
字體:
來源:轉載
供稿:網友

我們的產品在上線之前都需要進行各種檢測,順利通過檢測后就能進行產品包裝了,我們將提示錯誤的資源名稱和路徑,那么Unity編輯器下重啟的方法大家知道嗎?武林技術頻道小編為你分享。

Unity編輯器下重啟的方法

我們項目AssetBundle打包走的是全自動化流程,打包之前要進行各種資源檢測,如果檢測順利通過,則進入打包,否則提示錯誤資源名稱及路徑,打包中斷!有時候即使資源檢測通過也會打包崩潰,初步斷定是Unity的內存爆了,因為Unity在編輯器下打開工程中的資源不會釋放掉,所以內存一直在占用,打包時要進行一系列資源依賴分析,我們也知道,如果資源量非常大時候,Unity要保存資源依賴的堆棧,所以會有內存崩掉的風險,所以我就想著,打包之前重啟下Unity,讓Unity釋放掉一些沒用的內存。完成這個工作,有以下幾個步驟:

1.獲取Unity的安裝路徑,實現方法有兩種:

  方法一:簡單粗暴,E://Unity 5.5.2//Unity//Editor//Unity.exe,不具有通用性。

  方法二:通過注冊包表獲取安裝路徑,獲取操作如下:

private static string GetUnityPath()  {    #region 通過注冊便獲取Unity安裝路徑    var regKey = @"Unity package file/DefaultIcon";    RegistryKey registryKey = Registry.ClassesRoot.OpenSubKey(regKey);    string pathName = (string)registryKey.GetValue(null); // "(Default)"     if (string.IsNullOrEmpty(pathName))    {      return null;    }    int index = pathName.LastIndexOf(",");    if (index != -1)    {      var exepath = pathName.Substring(0, index).Replace("/"", string.Empty);      var binpath = Path.GetDirectoryName(exepath);       var di = new DirectoryInfo(binpath);      if (di.Parent != null)      {        return di.Parent.FullName;      }    }    return null;      #endregion  }

?第二步:創建一個新的Unity進程。

static void StartPeocess(string applicationPath){  Process po = new Process();  po.StartInfo.FileName = applicationPath;  po.Start();}

第三步:殺掉之前舊的進程

string[] args = unityPath.Split('//');Process[] pro = Process.GetProcessesByName(args[args.Length - 1].Split('.')[0]);//Unityforeach (var item in pro){  UnityEngine.Debug.Log(item.MainModule);  item.Kill();}

?好了,這樣基本上就搞定了!

完整代碼:

using Microsoft.Win32;using System.Collections;using System.Collections.Generic;using System.Diagnostics;using System.IO;using UnityEditor;using UnityEngine;public class ReStartUnityTools : MonoBehaviour{  public static string UnityExePath = "E://Unity 5.5.2//Unity//Editor//Unity.exe";  [MenuItem("Tools/ReStartUnity(重啟Unity)")]  public static void ReStartUnity()  {    string unityPath = UnityExePath;// GetUnityPath();公司電腦通過注冊表是可以的,家里電腦不行,你們可以用這個函數試下,實在不行先寫上Unity安裝路徑吧    StartPeocess(unityPath);    string[] args = unityPath.Split('//');    Process[] pro = Process.GetProcessesByName(args[args.Length - 1].Split('.')[0]);//Unity    foreach (var item in pro)    {      UnityEngine.Debug.Log(item.MainModule);      item.Kill();    }  }  private static string GetUnityPath()  {    #region 通過注冊便獲取Unity安裝路徑    var regKey = @"Unity package file/DefaultIcon";    RegistryKey registryKey = Registry.ClassesRoot.OpenSubKey(regKey);    string pathName = (string)registryKey.GetValue(null); // "(Default)"     if (string.IsNullOrEmpty(pathName))    {      return null;    }    int index = pathName.LastIndexOf(",");    if (index != -1)    {      var exepath = pathName.Substring(0, index).Replace("/"", string.Empty);      var binpath = Path.GetDirectoryName(exepath);  //       var di = new DirectoryInfo(binpath);      if (di.Parent != null)      {        return di.Parent.FullName;      }    }    return null;      #endregion  }  static void StartPeocess(string applicationPath)  {    Process po = new Process();    po.StartInfo.FileName = applicationPath;    po.Start();  }}

運行結果:

上面是武林技術頻道小編介紹的Unity編輯器下重啟的方法,大家學習的怎樣了呢?大家可以按照上文的代碼操作試下,如有疑問歡迎給武林技術頻道進行留言。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 福利二区| 久久精品视频亚洲 | 国产在线一区二区三区视频 | 国产精品久久久久久久免费大片 | 欧美电影一区二区三区 | 精品一区二区网站 | 亚洲天堂电影网 | 久久精精品 | 久久机热 | 日韩综合一区 | 欧美日韩亚洲视频 | 国产成人久久 | 91精品国产乱码久久久久久久久 | 亚洲午夜精品一区二区三区他趣 | 国产主播福利 | 中文字幕一区二区三区日韩精品 | 亚洲高清在线观看视频 | 毛片av片 | 久久久久久久国产 | 午夜精品亚洲日日做天天做 | 三级av| 久久艹视频| www97影院| 成人福利在线 | 日韩av电影免费 | 精品一区二区国产 | 成人在线黄色 | 一区二区日韩精品 | 免费国产成人 | 精品一区二区三区免费 | 在线日韩视频 | 亚洲黄色一区二区 | 欧美成在线观看 | 欧美视频一区二区三区 | 国产免费看| 国产亚洲综合视频 | 欧美一区久久 | 九色91视频 | 天天草草草 | 婷婷精品久久久久久久久久不卡 | 黄色在线免费观看 |