-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathGroupsView.cs
More file actions
117 lines (96 loc) · 3.56 KB
/
GroupsView.cs
File metadata and controls
117 lines (96 loc) · 3.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
//
// Addressables Build Layout Explorer for Unity. Copyright (c) 2021 Peter Schraut (www.console-dev.de). See LICENSE.md
// https://github.com/pschraut/UnityAddressablesBuildLayoutExplorer
//
using System.Collections.Generic;
using UnityEditor;
using UnityEditor.IMGUI.Controls;
using UnityEngine;
namespace Oddworm.EditorFramework.BuildLayoutExplorer
{
[BuildLayoutView]
public class GroupsView : BuildLayoutView
{
GroupTreeView m_TreeView;
SearchField m_SearchField;
public override void Awake()
{
base.Awake();
viewMenuOrder = 10;
m_TreeView = new GroupTreeView(window);
m_TreeView.selectedItemChanged += OnSelectedItemChanged;
m_SearchField = new SearchField(window);
}
public override void OnDestroy()
{
base.OnDestroy();
m_TreeView.selectedItemChanged -= OnSelectedItemChanged;
}
void OnSelectedItemChanged(TreeViewItem selectedItem)
{
if (selectedItem == null)
return;
var name = selectedItem.displayName;
var asset = AssetDatabase.LoadAssetAtPath<ScriptableObject>($"Assets/AddressableAssetsData/AssetGroups/{name}.asset");
if (asset != null)
Selection.activeObject = asset;
}
public override void Rebuild(RichBuildLayout buildLayout)
{
base.Rebuild(buildLayout);
m_TreeView.SetBuildLayout(buildLayout);
}
public override void OnGUI()
{
using (new EditorGUILayout.VerticalScope(Styles.viewStyle))
{
using (new EditorGUILayout.HorizontalScope())
{
EditorGUILayout.LabelField(new GUIContent(" Groups", Styles.groupIcon), EditorStyles.boldLabel);
if (m_SearchField.OnToolbarGUI(GUILayout.ExpandWidth(true)))
m_TreeView.Search(m_SearchField.text);
}
var rect = GUILayoutUtility.GetRect(10, 10, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true));
m_TreeView.OnGUI(rect);
}
}
public override bool CanNavigateTo(object target)
{
if (target is RichBuildLayout.Group)
return true;
return base.CanNavigateTo(target);
}
public override void NavigateTo(object target)
{
var bundle = target as RichBuildLayout.Group;
if (bundle == null)
return;
var item = m_TreeView.FindItem(bundle);
if (item == null)
return;
m_TreeView.SetSelection(new[] { item.id }, TreeViewSelectionOptions.RevealAndFrame | TreeViewSelectionOptions.FireSelectionChanged);
m_TreeView.SetFocus();
}
public override void SetBookmark(NavigationBookmark bookmark)
{
var bm = bookmark as Bookmark;
if (bm == null)
{
Debug.LogError($"Cannot set bookmark, because the argument '{nameof(bookmark)}' is of the wrong type or null.");
return;
}
m_TreeView.SetState(bm.groupsState);
m_TreeView.SetFocus();
}
public override NavigationBookmark GetBookmark()
{
var bm = new Bookmark();
bm.groupsState = m_TreeView.GetState();
return bm;
}
class Bookmark : NavigationBookmark
{
public BuildLayoutTreeViewState groupsState;
}
}
}