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内核的双链表list_head、散列表hlist_head

    一.双链表list_head 1.基本概念 linux内核提供的标准链表可用于将任何类型的数据结构彼此链接起来. 不是数据内嵌到链表中,而是把链表内嵌到数据对象中. 即:加入链表的数据结构必须包含一个 ...

  2. [转载]oracle的加密和解密

    加密函数 create or replace function encrypt_des(p_text varchar2, p_key varchar2) return varchar2 isv_tex ...

  3. 【移动端】js禁止页面滑动与允许滑动

    禁止页面滑动 通常静止滑动方案:(阻止滑动事件) window.ontouchmove=function(e){ e.preventDefault && e.preventDefaul ...

  4. springmvc的ajax返回406问题

    在springmvc中ajax请求写为XXX.html,如果在controller的如:@RequestMapping(value="/login/doLogin.html",pr ...

  5. python通过sftp远程传输文件

    python提供了一个第三方模块paramiko,通过这个模块可以实现两台机器之间的网络连接,sftp是paramiko的一个方法,使用sftp可以在两台机器之间互相传输 拷贝文件.然而paramik ...

  6. Django设计模式

    单例模式: 建造者模式: 示例: from enum import Enum import time PizzaProgress = Enum('PizzaProgress', 'queued pre ...

  7. fjwc2019 D6T2 密文(trie+贪心)

    #194. 「2019冬令营提高组」密文 设$s[i]$表示前$i$个密文的异或和 容易发现,只要知道$s[0]~s[n](s[0]=0)$就可以知道每一位的值. 转化一下,就变成了在完全图上求最小生 ...

  8. 写给大忙人的spring cloud 1.x学习指南

    这几天抽空搞了下spring cloud 1.x(2.0目前应该来说还不成熟),因为之前项目中使用dubbo以及自研的rpc框架,所以总体下来还是比较顺利,加上spring boot,不算笔记整理,三 ...

  9. Java1的内容(学期总结)

  10. ubuntu18.04 安装新版本openssl

    首先我们应该知道ubuntu18.04内置了1.1.0g版本的openssl: 使用下面的apt命令更新Ubuntu存储库并安装软件包编译的软件包依赖项: sudo apt update sudo a ...