Skip to content

Commit

Permalink
搜索后的定位
Browse files Browse the repository at this point in the history
  • Loading branch information
akof1314 committed Sep 17, 2018
1 parent 8777273 commit 44291ea
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class Style
public GUIContent help = new GUIContent("帮助");
public GUIContent about = new GUIContent("关于");
public GUIContent exportCsv = new GUIContent("导出 CSV");
public GUIContent forceText = new GUIContent("Asset Serialization must be ForceText");
public GUIContent assetReferenceTitle = new GUIContent("检查列表");
public GUIContent assetReferenceAsset = new GUIContent("资源目录", "存放资源的文件夹路径");
public GUIContent assetReferenceAssetCommon = new GUIContent("公共资源目录", "整理资源时所放置的公共文件夹路径");
Expand All @@ -33,6 +34,7 @@ public class Style
public GUIContent dependenciesWaiting = new GUIContent("等待进行资源被引用查找");
public GUIContent dependenciesNothing = new GUIContent("资源文件夹没有任何数据");
public GUIContent dependenciesHeaderContent2 = new GUIContent("被引用的路径");
public GUIContent dependenciesDelete = new GUIContent("删除选中资源");

public GUIContent referenceTitle = new GUIContent("引用查找");
public GUIContent referenceWaiting = new GUIContent("等待进行引用查找");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,24 @@ static void ShowWindow()
private AssetDanshariSetting m_AssetDanshariSetting;
private Vector2 m_ScrollViewVector2;
private ReorderableList m_ReorderableList;
private bool m_IsForceText;

private void Awake()
{
titleContent.text = "资源断舍离";
}

private void OnEnable()
{
Init();
}

private void OnGUI()
{
Init();
var style = AssetDanshariStyle.Get();

if (!m_IsForceText)
{
EditorGUILayout.LabelField(style.forceText);
return;
}

EditorGUILayout.BeginHorizontal(EditorStyles.toolbar);
GUILayout.FlexibleSpace();
Rect toolBtnRect = GUILayoutUtility.GetRect(style.help, EditorStyles.toolbarDropDown, GUILayout.ExpandWidth(false));
Expand All @@ -53,6 +56,12 @@ private void Init()
{
if (m_AssetDanshariSetting == null)
{
m_IsForceText = EditorSettings.serializationMode == SerializationMode.ForceText;
if (!m_IsForceText)
{
return;
}

m_AssetDanshariSetting = AssetDatabase.LoadAssetAtPath<AssetDanshariSetting>(
"Assets/Editor/AssetDanshari/AssetDanshariSetting.asset");
if (m_AssetDanshariSetting == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,51 @@ protected override void ContextClickedItem(int id)
{
menu.AddItem(AssetDanshariStyle.Get().locationContext, false, OnContextSetActiveItem, id);
menu.AddItem(AssetDanshariStyle.Get().explorerContext, false, OnContextExplorerActiveItem, item);
menu.AddSeparator(String.Empty);
}

if (!IsSelectionContainsReverseItem())
{
menu.AddSeparator(String.Empty);
AddContextMoveComm(menu);
menu.AddSeparator(String.Empty);
menu.AddItem(AssetDanshariStyle.Get().dependenciesDelete, false, OnContextDeleteThisItem);
}

if (menu.GetItemCount() > 0)
{
menu.ShowAsContext();
}
}

private void OnContextDeleteThisItem()
{
if (!HasSelection())
{
return;
}

var style = AssetDanshariStyle.Get();
if (!EditorUtility.DisplayDialog(String.Empty, style.sureStr + style.dependenciesDelete.text,
style.sureStr, style.cancelStr))
{
return;
}

var selects = GetSelection();
foreach (var select in selects)
{
var assetInfo = GetItemAssetInfo(FindItem(select, rootItem));
if (assetInfo == null || assetInfo.deleted)
{
continue;
}

if (AssetDatabase.DeleteAsset(assetInfo.fileRelativePath))
{
assetInfo.deleted = true;
}
}
Repaint();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,6 @@ protected override void ContextClickedItem(int id)
{
menu.AddItem(AssetDanshariStyle.Get().locationContext, false, OnContextSetActiveItem, id);
menu.AddItem(AssetDanshariStyle.Get().explorerContext, false, OnContextExplorerActiveItem, item);
menu.AddSeparator(String.Empty);
}

if (!IsSelectionContainsReverseItem())
{
AddContextMoveComm(menu);
}

if (menu.GetItemCount() > 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,12 @@ protected virtual void DrawGUI(GUIContent waiting, GUIContent nothing, bool expa
{
DrawToolbarExpandCollapse();
}
EditorGUI.BeginChangeCheck();
m_AssetTreeView.searchString = m_SearchField.OnToolbarGUI(m_AssetTreeView.searchString);
if (EditorGUI.EndChangeCheck() && GUIUtility.keyboardControl == 0)
{
m_AssetTreeView.SetFocusAndEnsureSelectedItem();
}
if (GUILayout.Button(style.exportCsv, EditorStyles.toolbarButton, GUILayout.Width(70f)))
{
m_AssetTreeModel.ExportCsv();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -370,16 +370,29 @@ protected virtual bool OnWatcherImportedAssetsEvent(string[] importedAssets, boo
continue;
}

var assetInfo2 = m_Model.GenAssetInfo(importedAsset);
assetInfo.AddChild(assetInfo2);

var item2 = new AssetTreeViewItem<AssetTreeModel.AssetInfo>(assetInfo2.id, -1, assetInfo2.displayName, assetInfo2);
if (assetInfo2.isFolder)
// 查找是否原先已经有了(被删除再导入)
var item2 = FindItemByAssetPath(item, importedAsset);
if (item2 != null)
{
var assetInfo2 = GetItemAssetInfo(item2);
if (assetInfo2 != null)
{
assetInfo2.added = true;
}
}
else
{
item2.icon = AssetDanshariStyle.Get().folderIcon;
var assetInfo2 = m_Model.GenAssetInfo(importedAsset);
assetInfo.AddChild(assetInfo2);

item2 = new AssetTreeViewItem<AssetTreeModel.AssetInfo>(assetInfo2.id, -1, assetInfo2.displayName, assetInfo2);
if (assetInfo2.isFolder)
{
item2.icon = AssetDanshariStyle.Get().folderIcon;
}
assetInfo2.added = true;
item.AddChild(item2);
}
assetInfo2.added = true;
item.AddChild(item2);
}
SetupDepthsFromParentsAndChildren(rootItem);
SortTreeViewNaturalCompare(rootItem);
Expand Down

0 comments on commit 44291ea

Please sign in to comment.