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. [转载]Oracle修改用户表所属表空间的步骤

    1 .修改表的空间alter table TABLE_NAME move tablespace TABLESPACENAME 查询当前用户下的所有表选择'alter table'|| table_na ...

  2. What Would you Find out about MS908CV ?

    The Autel MaxiSYS commercial car diagnostics scan device, No. MS908CV, performs increased technique ...

  3. kubernetes install for centos

    官方的文档写的很清楚 https://kubernetes.io/docs/getting-started-guides/centos/centos_manual_config/ 如果已经安装过doc ...

  4. TensorFlow 分布式实践

    此wiki主要介绍分布式环境使用的一些条件,一直所要注意的内容: 确保在此之前阅读过TensorFlow for distributed 1.集群描述 当前tensorflow 的版本(0.8.0), ...

  5. 关于reduce输出write方法

    关于hadoop一些自定义输出 code>OutputFormat</code> describes the output-specification for a * Map-Red ...

  6. ads查询结果中文显示方框问题

    刚安装aqua data studio查询结果中文会变成小方框 选择File -->Options 找到General  -->Appearance,把Editor Font , Text ...

  7. 爬虫之牛掰的scrapy框架

    一. Scrapy简介及安装 http://python.jobbole.com/86405/ Scrapy的详细介绍   1.简介   2.安装     1.window上安装:         先 ...

  8. P3203 [HNOI2010]弹飞绵羊(LCT)

    P3203 [HNOI2010]弹飞绵羊 LCT板子 用一个$p[i]$数组维护每个点指向的下个点. 每次修改时cut*1+link*1就解决了 被弹出界时新设一个点,权为0,作为终点表示出界点.其他 ...

  9. JVM垃圾回收算法及分代垃圾收集器

    一.垃圾收集器的分类 1.次收集器 Scavenge GC,指发生在新生代的GC,因为新生代的Java对象大多都是朝生夕死,所以Scavenge GC非常频繁,一般回收速度也比较快.当Eden空间不足 ...

  10. Springboot项目修改html后不需要重启---springboot项目的热部署

    一.spring-boot-devtools 在pom中直接引入依赖 <dependency> <groupId>org.springframework.boot</gr ...