using vnxbqy.UI;
|
using System.Collections;
|
using System.Collections.Generic;
|
using System.IO;
|
using System.Reflection;
|
using System.Text.RegularExpressions;
|
using UnityEditor;
|
using UnityEngine;
|
using UnityEngine.UI;
|
|
public static class ImageMissTool
|
{
|
static Dictionary<GameObject, List<MissImage>> missImageDict = new Dictionary<GameObject, List<MissImage>>();
|
|
static Vector2 m_ScrollPosition = Vector2.zero;
|
|
static bool viewserialized = true;
|
public static void OnGUI()
|
{
|
ToolsHelper.DisplayFolderPath();
|
|
viewserialized = GUILayout.Toggle(viewserialized, "全部");
|
|
if (GUILayout.Button("查找"))
|
{
|
missImageDict.Clear();
|
if (ToolsHelper.folderPath.Equals(string.Empty))
|
{
|
return;
|
}
|
StartFind();
|
}
|
|
m_ScrollPosition = GUILayout.BeginScrollView(m_ScrollPosition);
|
foreach (var _object in missImageDict.Keys)
|
{
|
bool allserialized = true;
|
var _list = missImageDict[_object];
|
for (int i = 0; i < _list.Count; i++)
|
{
|
if (!_list[i].serialized)
|
{
|
allserialized = false;
|
break;
|
}
|
}
|
|
if (allserialized && !viewserialized)
|
{
|
continue;
|
}
|
|
GUILayout.BeginHorizontal();
|
EditorGUILayout.ObjectField(_object, typeof(UnityEngine.Object), false);
|
GUILayout.FlexibleSpace();
|
GUILayout.EndHorizontal();
|
|
for (int i = 0; i < _list.Count; i++)
|
{
|
if (_list[i].serialized && !viewserialized)
|
{
|
continue;
|
}
|
GUILayout.BeginHorizontal();
|
GUILayout.Label(_list[i].path);
|
if (_list[i].path != string.Empty && GUILayout.Button("Goto"))
|
{
|
var _go = GameObject.Find(_list[i].path);
|
if (_go != null)
|
{
|
Selection.activeGameObject = _go;
|
}
|
}
|
EditorGUILayout.Toggle(_list[i].serialized);
|
GUILayout.FlexibleSpace();
|
GUILayout.EndHorizontal();
|
}
|
GUILayout.Space(5);
|
}
|
GUILayout.EndScrollView();
|
}
|
|
static void StartFind()
|
{
|
string[] _files = Directory.GetFiles(ToolsHelper.folderPath, "*.prefab", SearchOption.AllDirectories);
|
if (_files == null || _files.Length == 0)
|
{
|
return;
|
}
|
var _index = 0;
|
var inspectorModeInfo = typeof(SerializedObject).GetProperty("inspectorMode", BindingFlags.NonPublic | BindingFlags.Instance);
|
EditorApplication.update = delegate ()
|
{
|
var _file = _files[_index];
|
var _prefab = AssetDatabase.LoadAssetAtPath<GameObject>(ToolsHelper.GetRelativeAssetsPath(_file));
|
if (_prefab != null)
|
{
|
var all_text = File.ReadAllText(_file);
|
var images = _prefab.GetComponentsInChildren<Image>(true);
|
if (images != null && images.Length > 0)
|
{
|
for (int i = 0; i < images.Length; i++)
|
{
|
var serializedObject = new SerializedObject(images[i]);
|
inspectorModeInfo.SetValue(serializedObject, InspectorMode.Debug, null);
|
var localIdProp = serializedObject.FindProperty("m_LocalIdentfierInFile");
|
var fieldId = localIdProp.longValue;
|
|
bool isSerialized = ContainGuid(all_text, fieldId.ToString());
|
|
if (images[i].sprite == null && images[i].GetComponent<Mask>() == null)
|
{
|
if (!missImageDict.ContainsKey(_prefab))
|
{
|
missImageDict.Add(_prefab, new List<MissImage>());
|
}
|
missImageDict[_prefab].Add(new MissImage()
|
{
|
path = GetParentName(images[i].transform),
|
serialized = isSerialized,
|
});
|
}
|
}
|
}
|
}
|
bool _isCancel = EditorUtility.DisplayCancelableProgressBar("提取界面丢失图片的组件",
|
StringUtility.Contact(_index, "/", _files.Length), (float)_index / _files.Length);
|
_index++;
|
if (_isCancel || _index >= _files.Length)
|
{
|
EditorUtility.ClearProgressBar();
|
EditorApplication.update = null;
|
_index = 0;
|
}
|
};
|
}
|
|
static string GetParentName(Transform _parent)
|
{
|
if (_parent.parent != null && _parent.GetComponent<WindowInfo>() == null)
|
{
|
return StringUtility.Contact(GetParentName(_parent.parent), "/", _parent.name);
|
}
|
return _parent.name;
|
}
|
|
static bool ContainGuid(string _serializedFile, string _guid)
|
{
|
if (string.IsNullOrEmpty(_serializedFile))
|
{
|
return false;
|
}
|
else
|
{
|
|
var matches = Regex.Matches(_serializedFile, _guid);
|
return matches.Count > 2;
|
}
|
}
|
|
public class MissImage
|
{
|
public string path;
|
public bool serialized;
|
}
|
}
|