2023-04-03 11:04:31 +08:00

130 lines
4.2 KiB
C#

using System.IO;
using System;
using UnityEditor;
using UnityEngine;
using System.Collections.Generic;
using System.Text.RegularExpressions;
namespace BFEditor.Resource
{
public class DependenciesCheckWindow : EditorWindow
{
Vector2 scrollPosition = new Vector2(100, 100);
Action<bool> checkOverAction;
List<BaseDependenciesChecker> allChekers = new List<BaseDependenciesChecker>();
DependenciesCheckWindow()
{
this.titleContent = new GUIContent("资源依赖检查");
DependenciesCheckTool.Clear();
foreach(var checker in DependenciesCheckTool.GetAllCheckers())
{
allChekers.Add(checker);
}
checkOverAction = (bool result) =>
{
if (result)
{
EditorUtility.DisplayDialog("提示", "检查完成,符合标准", "ok");
}
};
}
void OnGUI()
{
DrawButton();
DrawResult();
}
void DrawButton()
{
int count = allChekers.Count;
int column = (int)Math.Ceiling(count / 6.0); //900 / 150 = 6
for(int i = 0; i < column; i++)
{
GUILayout.BeginHorizontal();
for(int j = 0; j < 6; j++)
{
int curIndex = i*6 + j;
if(curIndex < count)
{
allChekers[curIndex].Active = GUILayout.Toggle(allChekers[curIndex].Active, allChekers[curIndex].GetCheckerName(), GUILayout.Width(150));
}
}
GUILayout.EndHorizontal();
}
GUILayout.Space(15);
var style = new GUIStyle(GUI.skin.button);
style.fontSize = 15;
style.alignment = TextAnchor.MiddleCenter;
GUILayout.BeginHorizontal();
if (GUILayout.Button("检查所选", style, GUILayout.Width(100), GUILayout.Height(26)))
{
CheckAll();
}
if (GUILayout.Button("全选", style, GUILayout.Width(100), GUILayout.Height(26)))
{
for(int i = 0; i < allChekers.Count; i++)
{
allChekers[i].Active = true;
}
}
if (GUILayout.Button("取消全选", style, GUILayout.Width(100), GUILayout.Height(26)))
{
for(int i = 0; i < allChekers.Count; i++)
{
allChekers[i].Active = false;
}
}
GUILayout.EndHorizontal();
GUILayout.Space(15);
}
void CheckAll()
{
DependenciesCheckTool.CheckDependenceies(checkOverAction, allChekers);
}
void DrawResult()
{
if(DependenciesCheckTool.CheckedOver)
{
GUILayout.BeginHorizontal();
GUILayout.Label("AB包", GUILayout.Width(450));
GUILayout.Label("不正常依赖", GUILayout.Width(450));
GUILayout.EndHorizontal();
scrollPosition = GUILayout.BeginScrollView(
scrollPosition, GUILayout.Width(900), GUILayout.Height(800));
Dictionary<string, List<string>> abnormalDependenciesDic = DependenciesCheckTool.AbnormalDependenciesDic;
foreach(string bundle in abnormalDependenciesDic.Keys)
{
GUILayout.BeginHorizontal();
GUILayout.TextField(bundle, GUILayout.Width(450));
GUILayout.BeginVertical();
foreach(string dependent in abnormalDependenciesDic[bundle])
{
GUILayout.TextField(dependent);
}
GUILayout.EndVertical();
GUILayout.EndHorizontal();
GUILayout.Label("", GUILayout.Width(100));
}
GUILayout.EndScrollView();
}
}
void OnDestroy()
{
DependenciesCheckTool.Clear();
}
public static void ShowDependenciesCheckWindow()
{
var window = (DependenciesCheckWindow)GetWindowWithRect(typeof(DependenciesCheckWindow),
new Rect(Screen.width / 2, Screen.height / 2, 900, 800));
window.Show();
}
}
}