Skip to content

Instantly share code, notes, and snippets.

@jmcguirk
Created March 29, 2013 17:48
Show Gist options
  • Select an option

  • Save jmcguirk/5272382 to your computer and use it in GitHub Desktop.

Select an option

Save jmcguirk/5272382 to your computer and use it in GitHub Desktop.
Ghetto Bookmarking System
using UnityEngine;
using UnityEditor;
using System.Collections;
using System.Collections.Generic;
public class BookmarkMenu : EditorWindow
{
int selectedOption = 0;
[MenuItem("Etc/Bookmarks/Bookmark View")]
static public void SetaBookMark() {
GameObject[] bookmarks;
bookmarks = GameObject.FindGameObjectsWithTag("bookmark");
Object prefab = Resources.Load("Bookmark");
if (bookmarks.Length > 0) {
GameObject bookmark = Instantiate(prefab, Vector3.zero, Quaternion.identity) as GameObject;
// Modify the clone to your heart's content
bookmark.name = "bookmark" + (bookmarks.Length + 1);
bookmark.transform.position = SceneView.lastActiveSceneView.pivot;
bookmark.transform.rotation = SceneView.lastActiveSceneView.rotation;
} else {
GameObject bookmark = Instantiate(prefab, Vector3.zero, Quaternion.identity) as GameObject;
// Modify the clone to your heart's content
bookmark.name = "bookmark1";
}
}
[MenuItem("Etc/Bookmarks/Load Bookmark")]
static public void LoadBookmark() {
//Show existing window instance. If one doesn't exist, make one.
EditorWindow.GetWindow(typeof(BookmarkMenu));
}
void OnGUI() {
GUILayout.Label("Select a bookmark", EditorStyles.boldLabel);
GameObject[] bookmarks = GameObject.FindGameObjectsWithTag("bookmark");
if(bookmarks.Length > 0){
List<string> options = new List<string>();
for(int i = 0; i < bookmarks.Length; i++){
options.Add(bookmarks[i].name);
}
selectedOption = GUILayout.SelectionGrid(selectedOption, options.ToArray(), 2);
applyBookmark(bookmarks[selectedOption]);
}
}
protected void applyBookmark(GameObject bookmark) {
if (bookmark != null && SceneView.lastActiveSceneView != null) {
SceneView.lastActiveSceneView.pivot = bookmark.transform.position;
SceneView.lastActiveSceneView.rotation = bookmark.transform.rotation;
SceneView.RepaintAll();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment