using UnityEngine;
using System.Collections;
using UnityEditor;
using UnityEngine.UI;
using System.Reflection;
using System.Collections.Generic;
using System.Linq;
using System;

namespace Daemo {

public class EDCheckPrefabRef : BaseEditor
{
static string m_strCurPath;

public static void StartCheckPrefabRef() {
if (Selection.objects != null && Selection.objects.Length > 0 && Selection.objects[0] != null)
{
GameObject obj = Selection.objects[0] as GameObject;
CheckPrefabRef(obj.transform);
}
}

public static void StartCheckDirPrefabRef() {
//HandlelDirections(Application.dataPath + "/Resources", HandleDirectionsAct);
List<GameObject> list = GetAllUIPrefabs();
checkStr = "";
for (int i = 0; i < list.Count; i++) {
CheckPrefabRef(list[i].transform);
}
Debug.LogError(checkStr);
checkStr = "";
}

private static void HandleDirectionsAct(string path) {
if (path.EndsWith(".meta")) {
return;
}
if (path.EndsWith(".prefab")) {
//path = path.Split('.')[0];
path = "Assets"+ SplitPath(path, "Assets");
m_strCurPath = path;
Debug.Log("path:" + path);
GameObject o = AssetDatabase.LoadAssetAtPath<GameObject>(path);
//o = GameObject.Instantiate(o);
CheckPrefabRef(o.transform);
}
}
private static List<GameObject> allPrefabs = new List<GameObject>();
public static List<GameObject> GetAllUIPrefabs() {
allPrefabs.Clear();
HandlelDirections(Application.dataPath + "/Resources/UI", PrefabCallBack);
return allPrefabs;
}
private static void PrefabCallBack(string path)
{
if (path.EndsWith(".meta"))
{
return;
}
if (path.EndsWith(".prefab"))
{
//path = path.Split('.')[0];
path = "Assets" + SplitPath(path, "Assets");
m_strCurPath = path;
GameObject searchObj = AssetDatabase.LoadAssetAtPath<GameObject>(path);
if (searchObj != null)
{
allPrefabs.Add(searchObj);
}

}
}
#region 不规范图片组
private static List<Texture2D> noGoodImgs = new List<Texture2D>();
public static List<Texture2D> goodImgs = new List<Texture2D>();
public static List<Texture2D> packImgs = new List<Texture2D>();
private static Dictionary<int, bool> goodsSizes = new Dictionary<int, bool>();
public static List<Texture2D> GetNoGoodImgs() {
for (int i = 1; i < 12; i++) {
goodsSizes[(1 << i)] = true;
}
noGoodImgs.Clear();
goodImgs.Clear();
packImgs.Clear();
HandlelDirections(Application.dataPath + "/Assets", ImgCallBack);
HandlelDirections(Application.dataPath + "/Resources", ImgCallBack);
return noGoodImgs;
}
private static void ImgCallBack(string path)
{
if (path.EndsWith(".meta"))
{
return;
}
if (path.EndsWith(".png") || path.EndsWith(".jpg"))
{
//path = path.Split('.')[0];
path = "Assets" + SplitPath(path, "Assets");
m_strCurPath = path;
bool isSprite = false;
Sprite sprite = AssetDatabase.LoadAssetAtPath<Sprite>(path);
if (sprite != null) {
if (sprite.packed)
{
isSprite = true;
packImgs.Add(sprite.texture);
//Texture2D img = AssetDatabase.LoadAssetAtPath<Texture2D>(path);
//if (img != null)
//{
// packImgs.Add(img);
//}
}
}
if (!isSprite)
{
Texture2D img = AssetDatabase.LoadAssetAtPath<Texture2D>(path);
if (img != null)
{

if (!goodsSizes.ContainsKey(img.width) || !goodsSizes.ContainsKey(img.height))
{
noGoodImgs.Add(img);
}
else
{
goodImgs.Add(img);
}
}
}
}
}
#endregion
#region 替换字体
private static string nowFontName = string.Empty;
private static bool replaceFontStatus = false;
private static Font replaceFont;
private static int replaceFontIndex = 0;
private static int fontStyleIndex;
public static void ReplaceUIFont(string nowName, Font toFont,int selectIndex) {
nowFontName = nowName;
replaceFontIndex = 1;
replaceFont = toFont;
fontStyleIndex = selectIndex;
EditorUtility.DisplayProgressBar("Replace Fonting", "start", replaceFontIndex);
HandlelDirections(Application.dataPath + "/Resources/UI", FontCallBack);
EditorUtility.ClearProgressBar();
EditorApplication.SaveScene();
}
private static void FontCallBack(string path) {
if (path.EndsWith(".meta"))
{
return;
}
if (path.EndsWith(".prefab"))
{
//path = path.Split('.')[0];
path = "Assets" + SplitPath(path, "Assets");
m_strCurPath = path;
GameObject searchObj = AssetDatabase.LoadAssetAtPath<GameObject>(path);
if (searchObj != null)
{
replaceFontStatus = false;
CheckPrefabFont(searchObj.transform);
if (replaceFontStatus)
{
replaceFontIndex++;
EditorUtility.DisplayProgressBar("replace fonting", path, replaceFontIndex);
Debug.Log("Replace Frefab:" + path);

}
}

}
}
private static void CheckPrefabFont(Transform t)
{
CycleChild(t, CheckFontReplace);
}

static string checkStr;
private static void CheckPrefabRef(Transform t)
{
CycleChild(t, CycleChildAct);
}
private static void CheckFontReplace(Transform t)
{
Text[] texts = t.gameObject.GetComponents<Text>();
for (int i = 0; i < texts.Length; i++)
{
Text text = texts[i];
if (text.font != null && text.font.name == nowFontName)
{
text.font = replaceFont;
if (fontStyleIndex > 1) {
if (fontStyleIndex == 2)
{
text.fontStyle = FontStyle.Normal;
}else if (fontStyleIndex == 3)
{
text.fontStyle = FontStyle.Bold;
}else if (fontStyleIndex == 4)
{
text.fontStyle = FontStyle.Italic;
}else if (fontStyleIndex == 5)
{
text.fontStyle = FontStyle.BoldAndItalic;
}
}
EditorUtility.SetDirty(text);
replaceFontStatus = true;
}
}
}
#endregion
private static void CycleChildAct(Transform t) {
Component[] components = t.gameObject.GetComponents(typeof(MonoBehaviour));
string path = AssetDatabase.GetAssetPath(t.gameObject.GetInstanceID());
foreach (Component m in components)
{
if (m == null)
{
Debug.LogError("path:" + path + " " + t.gameObject.name + " 有空引用脚本");
}
else
{
Type type = m.GetType();
FieldInfo[] infos = type.GetFields();
for (int i = 0; i < infos.Length; i++)
{
if (!infos[i].FieldType.IsSubclassOf(typeof(UnityEngine.Object)))
{
continue;
}
if (infos[i].FieldType == typeof(UGUIToggle)|| infos[i].FieldType == typeof(UGUIButton)
|| infos[i].FieldType == typeof(UGUIToggleGroup)
|| infos[i].FieldType == typeof(UnityEngine.UI.Graphic)) {
continue;
}
if (infos[i].Name == "GlassBackGround"
||infos[i].Name == "redDot"
|| infos[i].Name == "glowEffect"
|| infos[i].Name == "GlassBackGround") {
continue;
}
var hideInInspector = infos[i].GetCustomAttributes(typeof(HideInInspector), false).FirstOrDefault();
var nonSerialized = infos[i].GetCustomAttributes(typeof(NonSerializedAttribute), false).FirstOrDefault();
var ignoreCheck = infos[i].GetCustomAttributes(typeof(IgnoreCheck), false).FirstOrDefault();
if (hideInInspector != null|| nonSerialized != null|| ignoreCheck!=null)
{
continue;
}
if (infos[i].IsPrivate&&infos[i].IsNotSerialized)
{
continue;
}
if (infos[i].IsStatic) {
continue;
}
object o = infos[i].GetValue(m);
if (o == null)
{
Debug.LogError(path + ", ObjName:" + m.name + " 字段名:" + infos[i].Name + " FieldType:" + infos[i].FieldType);
//Debug.LogError(path + ", ObjName:" + m.name + " 字段名:" + infos[i].Name + " 类型名:" + type.Name
// + " MemberType:" + infos[i].MemberType
// + " IsPublic:" + infos[i].IsPublic
// + " IsStatic:" + infos[i].IsStatic
// + " IsNotSerialized:" + infos[i].IsNotSerialized
// + " Attributes:" + infos[i].Attributes
// + " FieldHandle:" + infos[i].FieldHandle
// + " FieldType:" + infos[i].FieldType);
//checkStr = checkStr + path + "," + infos[i].Name + " , " + o + "\n";
}
else
{

string s = o.ToString();
if (s == "null")
{
Debug.LogError(path + ", ObjName:" + m.name + " 字段名:" + infos[i].Name + " FieldType:" + infos[i].FieldType);
//checkStr = checkStr + path + "," + infos[i].Name + " , " + o + "\n";
}
else
{
//Debug.Log(infos[i].Name + " , " + o);
}
}

}
}

}
}

}

}

EDCheckPrefabRef的更多相关文章

  1. ImgQuoteUIWindow

    using System;using UnityEngine;using UnityEngine.UI;using UnityEditor;using System.Collections;using ...

  2. ImgNoGoodWindow

    using System;using System.Collections.Generic;using System.Linq;using System.Text;using UnityEditor; ...

随机推荐

  1. 在Linux 中如何从进程相关的文件描述中恢复数据

    在Linux中误删除了某个文件,但是 ps-ef|grep 文件名 发现某个进程还在使用该文件,那么可以通 过以下方式恢复文件. 例如:创建一个简单文件/tmp/test.txt, 随便向里面写点内容 ...

  2. spark与kafka集成进行实时 nginx代理 这种sdk埋点 原生日志实时解析 处理

    日志格式202.108.16.254^A1546795482.600^A/cntv.gif?appId=3&areaId=8213&srcContId=2535575&area ...

  3. 几张图看明白VAO、VBO、EBO的关系和代码顺序

    0.详细教程可看https://learnopengl-cn.github.io/01%20Getting%20started/04%20Hello%20Triangle/ 1.可以简单地认为VAO的 ...

  4. MyEclipse中项目运行时发生了Tomcat报错:[java.lang.OutOfMemoryError: PermGen space]

    Tomcat内存溢出,异常信息如下: 十一月 26, 2017 1:52:26 下午 org.apache.catalina.core.ContainerBase$ContainerBackgroun ...

  5. 如何使用 lsyncd 实时同步并执行 shell 命令

    修改 lsyncd 的默认配置,不直接执行rsync 进行同步,而是改用自己的脚本. binary 指定我们的脚本 vim /usr/local/lsyncd/etc/lsyncd.conf sett ...

  6. Sort aborted Error in MySQL Error Log

    现象 [ERROR] lines containing "Sort aborted" are present in the MySQL error log file. [Warni ...

  7. $ORACLE_HOME/rdbms/demo示例安装

    需要手工安装p13390677_112040_Linux-x86-64_6of7.zip,或者win32_11gR2_examples.zip.默认不包含. 从Oracle Database 12c ...

  8. 写给大忙人的Elasticsearch架构与概念(未完待续)

    最新版本官方文档https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html文档增删改参考https://www ...

  9. Vue 基础精讲

    Vue 基础精讲 Vue 官方文档:https://cn.vuejs.org/v2/guide/ VUE 实例 每个组件都是一个 vue 的实例. 一个 vue 项目是由实例组成的. vue 实例上有 ...

  10. 如何写好接口(php写app移动端接口示例)

    原文链接:https://blog.csdn.net/xwh670570759/article/details/52130585?utm_source=blogxgwz0