Skip to content

Commit

Permalink
ヒエラルキーのブックマークウィンドウ変更: Applyボタンを押したときに一番上の項目を選択する機能を追加しました
Browse files Browse the repository at this point in the history
  • Loading branch information
rngtm committed Oct 14, 2017
1 parent 01c05f0 commit 7edf709
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 10 deletions.
1 change: 1 addition & 0 deletions Assets/AssetBookmarker.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion Assets/AssetBookmarker/Core/Scripts/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
///-----------------------------------------
namespace AssetBookmarker
{
using UnityEngine;

/// <summary>
/// 設定
/// </summary>
public static class Config
{
// バージョン情報
public const string VERSION_TEXT = "Asset Bookmarker v2.1";
public const string VERSION_TEXT = "Asset Bookmarker v2.2";

// Menuテキスト
public const string GUI_MENU_TEXT_OPEN_BOOKMARK_PROJECT = "Tools/Asset Bookmarker/Assets";
Expand Down
Binary file modified Assets/AssetBookmarker/Hierarchy/Data/BookmarkData.asset
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
///-----------------------------------------
///-----------------------------------------
/// AssetBookmarker
/// @ 2016 RNGTM(https://github.com/rngtm)
///-----------------------------------------
Expand All @@ -21,6 +21,8 @@ public class HierarchyBookmarkWindow : EditorWindow
/// </summary>
private ReorderableList searchInfoList;

private Vector2 scrollPosition = Vector2.zero;

/// <summary>
/// ウィンドウ描画処理
/// </summary>
Expand All @@ -30,7 +32,9 @@ void OnGUI()
{
this.bookmarkData = DataLoader.LoadData();
}


this.scrollPosition = EditorGUILayout.BeginScrollView(this.scrollPosition);

if (this.searchInfoList == null)
{
this.RebuildSearchInfoList();
Expand All @@ -39,10 +43,11 @@ void OnGUI()
EditorGUILayout.LabelField(Config.GUI_WINDOW_HIERARCHY_TEXT_OVERVIEW);

this.searchInfoList.DoLayoutList();
EditorGUILayout.EndScrollView();

CustomUI.VersionLabel();
}

/// <summary>
/// ReorderableList作成
/// </summary>
Expand Down Expand Up @@ -98,6 +103,11 @@ private ReorderableList CreateSearchInfoList()
{
var data = (SearchInfo)reorderableList.list[index];
SceneHierarchyAccessor.SetSearchFilter(data.Text);

if (!string.IsNullOrEmpty(data.Text))
{
SceneHierarchyAccessor.SelectTop();
}
}

if (GUI.Button(removeButtonRect, Config.GUI_WINDOW_HIERARCHY_TEXT_FILTER_REMOVE_BUTTON))
Expand All @@ -114,7 +124,7 @@ private ReorderableList CreateSearchInfoList()
}
};

reorderableList.drawElementBackgroundCallback = (rect, index, isActive, isFocused) => {};
reorderableList.drawElementBackgroundCallback = (rect, index, isActive, isFocused) => { };

return reorderableList;
}
Expand All @@ -131,7 +141,7 @@ private void DoRemoveButton(int index)
EditorUtility.SetDirty(this.bookmarkData);
};
}

/// <summary>
/// ウィンドウを開く
/// </summary>
Expand All @@ -156,7 +166,7 @@ static void RegisterSelectionToPalette()
EditorUtility.SetDirty(data);
Open();
}

/// <summary>
/// RegisterSelectionToPaletteのValidateメソッド
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
///-----------------------------------------
///-----------------------------------------
/// AssetBookmarker
/// @ 2016 RNGTM(https://github.com/rngtm)
///-----------------------------------------
namespace AssetBookmarker.Hierarchy
{
using System.Collections.Generic;
using System.Reflection;
using UnityEngine;
using UnityEditor;
using UnityEditor.IMGUI.Controls;

/// <summary>
/// SceneHierarchyWindowへのアクセスを行うクラス
Expand All @@ -29,5 +32,36 @@ public static void SetSearchFilter(string filter)
typeWindow.GetMethod("SetSearchFilter", BindingFlags.Instance | BindingFlags.NonPublic)
.Invoke(window, new object[] { filter, mode, setAll });
}

/// <summary>
/// Hierarchyで一番上にある項目を選択
/// </summary>
public static void SelectTop()
{
var rows = GetRows();
if (rows.Count < 2) { return; }

var gameObject = (GameObject)EditorUtility.InstanceIDToObject(rows[1].id);
Selection.activeGameObject = gameObject;
}

/// <summary>
/// ヒエラルキーウィンドウ上の項目の一覧取得
/// </summary>
public static IList<TreeViewItem> GetRows()
{
// Hierarchyウィンドウ取得
var asm = Assembly.Load("UnityEditor.dll");
var typeWindow = asm.GetType("UnityEditor.SceneHierarchyWindow");
var window = EditorWindow.GetWindow(typeWindow);

// GetRows実行
var m_TreeView = typeWindow.GetField("m_TreeView", BindingFlags.Instance | BindingFlags.NonPublic)
.GetValue(window);
var data = m_TreeView.GetType().GetProperty("data", BindingFlags.Instance | BindingFlags.Public)
.GetValue(m_TreeView, null);
return (IList<TreeViewItem>)data.GetType().GetMethod("GetRows", BindingFlags.Instance | BindingFlags.Public)
.Invoke(data, null);
}
}
}
Binary file modified Assets/AssetBookmarker/Project/Data/BookmarkData.asset
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ static void Open()
[MenuItem(Config.GUI_MENU_TEXT_REGISTER_PROJECT, false, 10001)]
static void RegisterSelection()
{
willRegisterAssets = Selection.objects.Where(obj => AssetDatabase.IsMainAsset(obj)).ToArray();
willRegisterAssets = Selection.objects;
Open();
}

Expand Down
2 changes: 1 addition & 1 deletion ProjectSettings/ProjectVersion.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
m_EditorVersion: 5.5.0f3
m_EditorVersion: 2017.2.0f1

0 comments on commit 7edf709

Please sign in to comment.