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. HDU 2175 汉诺塔IX (递推)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2175 1,2,...,n表示n个盘子.数字大盘子就大.n个盘子放在第1根柱子上.大盘不能放在小盘上.  ...

  2. 案例:Redis在唯品会的大规模应用

    目前在唯品会主要负责redis/hbase的运维和开发支持工作,也参与工具开发工作,本文是在Redis中国用户组给大家分享redis cluster的生产实践. 分享大纲 本次分享内容如下: 1.生产 ...

  3. tomcat 启动时遇到org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs

    当发生这样的错误的时候 org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet ...

  4. HTML(续)

    1.有frame就无body,框架的noresize:设置框架大小不能改变.2.链接在框架中的应用target:有定为目标的功能.<a href = "链接源地址" targ ...

  5. DOS下读取spd信息的汇编程序(通过SMBus)

    汇编程序编写的读取spd信息的代码: ;----------------------------------------------------------- ;功能: 通过SMbus 读取内存的SP ...

  6. Android之xml解析

    利用类下载器解析Xml文件要解析的xml文件<?xml version="1.0" encoding="utf-8"?><info> & ...

  7. Magnum Kubernetes源码分析(二)

    Kubernetes Master Stack kubernetes master的stack的resources主要分为三个部分. master wait handle wait handle主要用 ...

  8. Ubuntu软件操作的相关命令

    Ubuntu软件操作的相关命令 sudo apt-get update ------------------------------- 更新源 sudo apt-get install package ...

  9. c和c++main函数的参数

    1.代码 int main(int argc,char **argv[]) { ; } 2.分析 argc:代码参数个数 argv:二级指针,很多个字符串,这里代表参数列表 3.分析 这个代码最终被编 ...

  10. linux下安装tomcat和jdk

    1.现在的linux服务器一般自带jdk,先查询是否已经安装jdk rpm -qa | grep java rpm -qa | grep jdk 如上则是没有安装,可以直接跳到步骤X,安装jdk.否则 ...