框架上传
This commit is contained in:
25
Assets/00.StaryEvo/Editor/OdinTool/MyMenuEditorWindow.cs
Normal file
25
Assets/00.StaryEvo/Editor/OdinTool/MyMenuEditorWindow.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using Sirenix.OdinInspector.Editor;
|
||||
using UnityEditor;
|
||||
|
||||
namespace Stary.Evo.Editor
|
||||
{
|
||||
|
||||
|
||||
public class MyMenuEditorWindow : OdinMenuEditorWindow
|
||||
{
|
||||
[MenuItem("Evo/Utility/优化/一键优化工具")]
|
||||
private static void OpenWindow()
|
||||
{
|
||||
GetWindow<MyMenuEditorWindow>().Show();
|
||||
}
|
||||
|
||||
protected override OdinMenuTree BuildMenuTree()
|
||||
{
|
||||
var tree = new OdinMenuTree();
|
||||
tree.Selection.SupportsMultiSelect = false;
|
||||
tree.Add("一键批量更改Raycast Target选项", new OneKeyChangeRaycastTarget());
|
||||
tree.Add("一键查找重复文件", new OneKeySearchDuplicateFiles());
|
||||
return tree;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6f9dc9117e7bf144b83022ae0e269d99
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
127
Assets/00.StaryEvo/Editor/OdinTool/OneKeyChangeRaycastTarget.cs
Normal file
127
Assets/00.StaryEvo/Editor/OdinTool/OneKeyChangeRaycastTarget.cs
Normal file
@@ -0,0 +1,127 @@
|
||||
/****************************************************
|
||||
文件:OneKeySearchDuplicateFiles.cs
|
||||
作者:张铮
|
||||
邮箱:834207172@qq.com
|
||||
日期:2022/3/7 18:28:50
|
||||
功能:
|
||||
*****************************************************/
|
||||
using Sirenix.OdinInspector;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Stary.Evo.Editor
|
||||
{
|
||||
|
||||
|
||||
[TypeInfoBox("批量选中或者取消对应UI上的Raycast")]
|
||||
public class OneKeyChangeRaycastTarget : SerializedScriptableObject
|
||||
{
|
||||
|
||||
private bool selectRaycastComplete = false;
|
||||
private bool cancelRaycastComplete = false;
|
||||
|
||||
[PreviewField(50)]
|
||||
[OnValueChanged("SelectRaycastListValueChangeCallBack")]
|
||||
[HorizontalGroup("Raycast")]
|
||||
[PropertySpace(10, 10)]
|
||||
[BoxGroup("Raycast/Left", false)]
|
||||
[LabelText("需要选中Raycast拖入进来")]
|
||||
public List<GameObject> SelectRaycastList = new List<GameObject>();
|
||||
|
||||
public void SelectRaycastListValueChangeCallBack()
|
||||
{
|
||||
selectRaycastComplete = false;
|
||||
}
|
||||
|
||||
|
||||
[PreviewField(50)]
|
||||
[OnValueChanged("CancelRaycastListValueChangeCallBack")]
|
||||
[PropertySpace(10, 10)]
|
||||
[BoxGroup("Raycast/Right", false)]
|
||||
[LabelText("需要取消Raycast拖入进来")]
|
||||
public List<GameObject> CancelRaycastList = new List<GameObject>();
|
||||
|
||||
public void CancelRaycastListValueChangeCallBack()
|
||||
{
|
||||
cancelRaycastComplete = false;
|
||||
}
|
||||
|
||||
[HideIf("@selectRaycastComplete==true||SelectRaycastList.Count==0")]
|
||||
[BoxGroup("Raycast/Left")]
|
||||
[Button("勾选所有射线检测", ButtonSizes.Large, ButtonStyle.FoldoutButton)]
|
||||
public void SelectRaycast()
|
||||
{
|
||||
for (int i = 0; i < SelectRaycastList.Count; i++)
|
||||
{
|
||||
if (SelectRaycastList[i] == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
Graphic[] graphicArray = SelectRaycastList[i].GetComponentsInChildren<Graphic>();
|
||||
for (int k = 0; k < graphicArray.Length; k++)
|
||||
{
|
||||
graphicArray[k].raycastTarget = true;
|
||||
EditorUtility.SetDirty(graphicArray[k]);
|
||||
}
|
||||
|
||||
GameObject tempObject = SelectRaycastList[i];
|
||||
bool isPrefabInstance = PrefabUtility.IsPartOfPrefabInstance(tempObject);
|
||||
bool isPrefabAsset = PrefabUtility.IsPartOfPrefabAsset(tempObject);
|
||||
if (isPrefabAsset)
|
||||
{
|
||||
PrefabUtility.SavePrefabAsset(SelectRaycastList[i]);
|
||||
}
|
||||
|
||||
if (isPrefabInstance)
|
||||
{
|
||||
PrefabUtility.ApplyPrefabInstance(SelectRaycastList[i], InteractionMode.UserAction);
|
||||
}
|
||||
}
|
||||
|
||||
selectRaycastComplete = true;
|
||||
AssetDatabase.Refresh();
|
||||
}
|
||||
|
||||
|
||||
[HideIf("@cancelRaycastComplete==true||CancelRaycastList.Count==0")]
|
||||
[BoxGroup("Raycast/Right")]
|
||||
[Button("取消所有射线检测", ButtonSizes.Large, ButtonStyle.FoldoutButton)]
|
||||
public void CancelRaycast()
|
||||
{
|
||||
for (int i = 0; i < CancelRaycastList.Count; i++)
|
||||
{
|
||||
if (CancelRaycastList[i] == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
Graphic[] graphicArray = CancelRaycastList[i].GetComponentsInChildren<Graphic>();
|
||||
for (int k = 0; k < graphicArray.Length; k++)
|
||||
{
|
||||
graphicArray[k].raycastTarget = false;
|
||||
EditorUtility.SetDirty(graphicArray[k]);
|
||||
}
|
||||
|
||||
GameObject tempObject = CancelRaycastList[i];
|
||||
bool isPrefabInstance = PrefabUtility.IsPartOfPrefabInstance(tempObject);
|
||||
bool isPrefabAsset = PrefabUtility.IsPartOfPrefabAsset(tempObject);
|
||||
|
||||
if (isPrefabAsset)
|
||||
{
|
||||
PrefabUtility.SavePrefabAsset(CancelRaycastList[i]);
|
||||
}
|
||||
|
||||
if (isPrefabInstance)
|
||||
{
|
||||
PrefabUtility.ApplyPrefabInstance(CancelRaycastList[i], InteractionMode.UserAction);
|
||||
}
|
||||
}
|
||||
|
||||
cancelRaycastComplete = true;
|
||||
AssetDatabase.Refresh();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0fd00bd6b055f134e8be6fb93a5b5ce4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
186
Assets/00.StaryEvo/Editor/OdinTool/OneKeySearchDuplicateFiles.cs
Normal file
186
Assets/00.StaryEvo/Editor/OdinTool/OneKeySearchDuplicateFiles.cs
Normal file
@@ -0,0 +1,186 @@
|
||||
/****************************************************
|
||||
文件:OneKeySearchDuplicateFiles.cs
|
||||
作者:张铮
|
||||
邮箱:834207172@qq.com
|
||||
日期:2022/3/7 18:28:50
|
||||
功能:
|
||||
*****************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using Sirenix.OdinInspector;
|
||||
using Sirenix.OdinInspector.Editor;
|
||||
using UnityEditor;
|
||||
using System.Threading;
|
||||
|
||||
namespace Stary.Evo.Editor
|
||||
{
|
||||
|
||||
|
||||
public class OneKeySearchDuplicateFiles : SerializedScriptableObject
|
||||
{
|
||||
private bool IsToggled;
|
||||
private int maxCount;
|
||||
private IEnumerator<FileInfo> fileInfoIEnumerator;
|
||||
|
||||
[PropertySpace(10)]
|
||||
[Title("需要搜索的文件夹", "默认为Asset全目录", titleAlignment: TitleAlignments.Split)]
|
||||
[FolderPath(ParentFolder = "Assets", RequireExistingPath = true, AbsolutePath = true)]
|
||||
[LabelText("选择你要搜索的文件夹")]
|
||||
public string targetSearchFolder;
|
||||
|
||||
|
||||
[ShowInInspector] [DictionaryDrawerSettings(KeyLabel = "MD5值", ValueLabel = "文件名称列表")]
|
||||
private Dictionary<string, List<string>> sameMD5Group = new Dictionary<string, List<string>>();
|
||||
|
||||
[ShowInInspector] [DictionaryDrawerSettings(KeyLabel = "文件名称", ValueLabel = "绝对路径列表")]
|
||||
private Dictionary<string, List<string>> sameNameGroup = new Dictionary<string, List<string>>();
|
||||
|
||||
[ShowInInspector]
|
||||
[TitleGroup("重复文件列表")]
|
||||
[HorizontalGroup("重复文件列表/重复文件")]
|
||||
[BoxGroup("重复文件列表/重复文件/MD5值相同", CenterLabel = true)]
|
||||
[PropertyOrder(1000)]
|
||||
[InfoBox("发现相同MD5值文件.", InfoMessageType.Error, "CheckSameMD5ResultGroup")]
|
||||
[ShowIf("$CheckSameMD5ResultGroup")]
|
||||
[DictionaryDrawerSettings(KeyLabel = "MD5值", ValueLabel = "相同MD5值文件名称")]
|
||||
private Dictionary<string, List<string>> sameMD5Result5Group = new Dictionary<string, List<string>>();
|
||||
|
||||
|
||||
[BoxGroup("重复文件列表/重复文件/名称值相同", CenterLabel = true)]
|
||||
[ShowInInspector]
|
||||
[PropertyOrder(1000)]
|
||||
[InfoBox("发现相同名称文件.", InfoMessageType.Error, "CheckSameNameResultGroup")]
|
||||
[ShowIf("$CheckSameNameResultGroup")]
|
||||
[DictionaryDrawerSettings(KeyLabel = "相同文件名称", ValueLabel = "对应绝对路径列表")]
|
||||
private Dictionary<string, List<string>> sameNameResultGroup = new Dictionary<string, List<string>>();
|
||||
|
||||
public bool CheckSameMD5ResultGroup()
|
||||
{
|
||||
return sameMD5Result5Group.Count > 0;
|
||||
}
|
||||
|
||||
private bool CheckSameNameResultGroup()
|
||||
{
|
||||
return sameNameResultGroup.Count > 0;
|
||||
}
|
||||
|
||||
[PropertySpace(10, 20)]
|
||||
[ShowIf("@ IsToggled== false")]
|
||||
[Button("开始搜索", ButtonSizes.Large)]
|
||||
public void StartSearch()
|
||||
{
|
||||
if (string.IsNullOrEmpty(targetSearchFolder))
|
||||
{
|
||||
targetSearchFolder = Application.dataPath;
|
||||
}
|
||||
|
||||
ResetData();
|
||||
DirectoryInfo directoryInfo = new DirectoryInfo(targetSearchFolder);
|
||||
var filesGroup = directoryInfo.EnumerateFiles("*", SearchOption.AllDirectories)
|
||||
.Where(x => x.Extension != ".meta");
|
||||
|
||||
maxCount = filesGroup.Count();
|
||||
fileInfoIEnumerator = filesGroup.GetEnumerator();
|
||||
IsToggled = true;
|
||||
EditorApplication.update += Updte;
|
||||
}
|
||||
|
||||
private void ResetData()
|
||||
{
|
||||
maxCount = 0;
|
||||
MaxCount = 0;
|
||||
sameMD5Group.Clear();
|
||||
sameNameGroup.Clear();
|
||||
sameMD5Result5Group.Clear();
|
||||
sameNameResultGroup.Clear();
|
||||
fileInfoIEnumerator = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 过滤掉没有重复文件的数据
|
||||
/// </summary>
|
||||
private void FilterDictionary()
|
||||
{
|
||||
sameMD5Result5Group = sameMD5Group.Where(x => x.Value.Count > 1).ToDictionary(p => p.Key, p => p.Value);
|
||||
sameNameResultGroup = sameNameGroup.Where(x => x.Value.Count > 1).ToDictionary(p => p.Key, p => p.Value);
|
||||
}
|
||||
|
||||
[ReadOnly]
|
||||
[ProgressBar(0, "maxCount", DrawValueLabel = true, ValueLabelAlignment = TextAlignment.Left,
|
||||
ColorGetter = "GetHealthBarColor", Height = 30)]
|
||||
[ShowInInspector]
|
||||
[HideLabel]
|
||||
[ShowIf("@ IsToggled== true")]
|
||||
public int MaxCount { get; set; } //绘制进度条
|
||||
|
||||
private Color GetHealthBarColor(int value)
|
||||
{
|
||||
maxCount = maxCount == 0 ? 1 : maxCount;
|
||||
return Color.Lerp(Color.red, Color.green, Mathf.Pow((float)value / maxCount, 2));
|
||||
}
|
||||
|
||||
public void Updte()
|
||||
{
|
||||
if (IsToggled)
|
||||
{
|
||||
if (fileInfoIEnumerator.MoveNext())
|
||||
{
|
||||
//获取对应Hash值
|
||||
string hashValue = GetMD5HashFromFile(fileInfoIEnumerator.Current.FullName);
|
||||
if (!sameMD5Group.ContainsKey(hashValue))
|
||||
{
|
||||
sameMD5Group[hashValue] = new List<string>();
|
||||
}
|
||||
|
||||
sameMD5Group[hashValue].Add("名称为:" + fileInfoIEnumerator.Current.Name);
|
||||
|
||||
//获取名称
|
||||
string fileName = fileInfoIEnumerator.Current.Name;
|
||||
|
||||
if (!sameNameGroup.ContainsKey(fileName))
|
||||
{
|
||||
sameNameGroup[fileName] = new List<string>();
|
||||
}
|
||||
|
||||
sameNameGroup[fileName].Add("路径为:" + fileInfoIEnumerator.Current.FullName);
|
||||
|
||||
++MaxCount;
|
||||
}
|
||||
else
|
||||
{
|
||||
EditorApplication.update -= Updte;
|
||||
IsToggled = false;
|
||||
FilterDictionary();
|
||||
Debug.Log("<color=green>注销</color>");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 计算文件MD5值
|
||||
/// </summary>
|
||||
/// <param name="fileFullName"></param>
|
||||
/// <returns></returns>
|
||||
public string GetMD5HashFromFile(string fileFullName)
|
||||
{
|
||||
try
|
||||
{
|
||||
FileStream file = new FileStream(fileFullName, FileMode.Open);
|
||||
System.Security.Cryptography.MD5 md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
|
||||
byte[] retVal = md5.ComputeHash(file);
|
||||
file.Close();
|
||||
return BitConverter.ToString(retVal).ToLower().Replace("-", "");
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 951c77f73e8aa2f47b895be4fe74da46
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user