using UnityEngine;
using System.Collections.Generic;
using UnityEditor;
using System.Text.RegularExpressions;
using System.IO;
using System.Text;
public class ReimportUnityEngineUI
[MenuItem(“Assets/Reimport UI Assemblies”, false, 100)]
public static void ReimportUI()
#if UNITY_4_6
var path = EditorApplication.applicationContentsPath + “/UnityExtensions/Unity/GUISystem/{0}/{1}”;
var version = Regex.Match( Application.unityVersion,@”^[0-9]+\.[0-9]+\.[0-9]+”).Value;
#else
var path = EditorApplication.applicationContentsPath + “/UnityExtensions/Unity/GUISystem/{1}”;
var version = string.Empty;
#endif
string engineDll = string.Format(path, version, “UnityEngine.UI.dll”);
string editorDll = string.Format(path, version, “Editor/UnityEditor.UI.dll”);
ReimportDll(engineDll);
ReimportDll(editorDll);
static void ReimportDll(string path)
if (File.Exists(path))
AssetDatabase.ImportAsset(path, ImportAssetOptions.ForceUpdate | ImportAssetOptions.DontDownloadFromCacheServer);
Debug.LogError(string.Format(“DLL not found {0}”, path));
补充:Unity材质丢失?用脚本自动解决吧!
unity HDRP的editor脚本来处理材质丢失问题
最近初学houdini,发现houdini digital asset导入到unity HDRP中材质出错,平时从max导fbx文件到unity中,也常常发现一些材质丢失,不支持,于是我写了一个unity的editor脚本来处理这种事情,
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
public class resetMat : MonoBehaviour//直接将脚本复制到asset文件夹中即可在工具栏发现该工具
public GameObject ob;
[MenuItem("Gq_Tools/修复材质球shader丢失")]
static void StartRun1()
var objs = Selection.objects;
foreach (var obj in objs)
var go = obj as GameObject;
var rs = go.GetComponentsInChildren<Renderer>();
foreach (var r in rs)
Material [] shaderArr = new Material[r.materials.Length];
shaderArr = r.materials;
print(" DDDDD" + shaderArr.Length);
for (int i=0;i<shaderArr.Length;i++)
shaderArr[i].shader=Shader.Find("HDRP/Lit");
[MenuItem("Gq_Tools/将选中物体都赋予同一材质球")]
static void StartRun2()
Material newmat = new Material(Shader.Find("HDRP/Lit"));
newmat.color = new Color(255, 228, 0, 1);
var objs = Selection.objects;
foreach (var obj in objs)//for每个选中的物体
var go = obj as GameObject;
var rs = go.GetComponentsInChildren<Renderer>();//连带子物体
foreach (var r in rs)//每个物体及子物体的renderer
Material[] matArr = new Material[r.materials.Length];
matArr = r.materials;
r.material = newmat;
[MenuItem("Gq_Tools/将所有丢失材质都强制赋予一个共用的材质")]
static void StartRun3()
{ Material newmat = new Material(Shader.Find("HDRP/Lit"));
var objs = Selection.objects;
foreach (var obj in objs)
var go = obj as GameObject;
var rs = go.GetComponentsInChildren<Renderer>();
foreach (var r in rs)//每个物体及子物体的renderer组件
// Material[] matArr = new Material[r.sharedMaterials.Length];
// matArr = r.materials;
if (r.sharedMaterial==null)//如果有丢失材质球的坑
print("丢失材质");
r.sharedMaterial = newmat;
else { print("没有丢失"); }