Files
Main/Assets/Editor/DIY/Custom/CheckZValue.cs
2025-01-25 04:38:09 +08:00

70 lines
2.1 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Collections.Generic;
using System.IO;
using UnityEditor;
using UnityEngine;
namespace Thousandto.Package
{
public class CheckZValue
{
private const string SOURCE_PATH = "Assets/GameAssets/Resources/GameUI/Form";
public static void Check()
{
EditorUtility.DisplayProgressBar("检查transform的Z值", "", 0);
var files = GetUIPrefabs();
var len = (float)files.Length;
for(int i = 0; i < len; ++i)
{
EditorUtility.DisplayProgressBar("检查transform的Z值", Path.GetFileName(files[i]), i / len);
var go = AssetDatabase.LoadAssetAtPath<GameObject>(files[i]);
if (go == null)
continue;
bool isChecked = false;
CheckTransform(go.transform, (_trans) =>
{
if (_trans.GetComponent<UIPanel>() != null)
return;
if (_trans.localPosition.z != 0)
{
var temp = _trans.localPosition;
temp.z = 0;
_trans.localPosition = temp;
isChecked = true;
}
});
if (isChecked)
UnityEngine.Debug.LogError("有改动的UI" + Path.GetFileName(files[i]));
}
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();
EditorUtility.ClearProgressBar();
}
private static string[] GetUIPrefabs()
{
var files = Directory.GetFiles(SOURCE_PATH, "*.prefab", SearchOption.AllDirectories);
return files;
}
private static void CheckTransform(Transform trans, Action<Transform> action)
{
var count = trans.childCount;
for(int i = 0; i < count; ++i)
{
var child = trans.GetChild(i);
if (action != null)
action(child);
CheckTransform(child, action);
}
}
}
}