So I’m trying my hand at Editor scripting and I’ve come up with a simple script to bookmark project files. It works exactly how I’d like it to, except for one thing: The array containing the bookmarks is lost when switching in and out of play mode.
Any help in resolving this issue (and any other suggestions for this script) would be much appreciated -
class ProjectBookmark extends EditorWindow {
private var bookmarkArray : Array;
private var scrollPos : Vector2;
@MenuItem ("Window/Bookmark Project Files")
static function Init () {
var window : ProjectBookmark = EditorWindow.GetWindow(ProjectBookmark);
}
function OnGUI () {
if (!bookmarkArray) bookmarkArray = new Array();
GUILayout.Label ("Bookmark Project Files", EditorStyles.boldLabel);
if (GUILayout.Button("Bookmark", GUILayout.MaxWidth(100))) saveBookmark();
GUILayout.Label("Bookmarks:", EditorStyles.boldLabel);
scrollPos = GUILayout.BeginScrollView(scrollPos);
for (path in bookmarkArray){
if (GUILayout.Button(path.name, GUILayout.MaxWidth(100))) restoreSelection(path);
}
GUILayout.EndScrollView();
}
function saveBookmark(){
var o : Object = Selection.activeObject;
if (AssetDatabase.Contains(o)){
bookmarkArray.Unshift(o);
}
else Debug.Log("not an asset - must choose something from the project view");
}
function restoreSelection(o : Object){
Selection.activeObject = o;
EditorGUIUtility.PingObject(o);
}
}