// HEADER GUI void HeaderOnGui() { GUIStyle labelstyle = GUI.skin.GetStyle("Label"); labelstyle.alignment = TextAnchor.UpperLeft; labelstyle.fixedWidth = 300; // WINDOW TITLE string libtype = (showClass == 3 ? "3D":"2D"); EditorGUILayout.BeginHorizontal(); labelstyle.fontSize = 24; GUILayout.Label("Archimatix " + libtype + " Library"); labelstyle.fontSize = 12; EditorGUILayout.Space(); if (GUILayout.Button("Refresh")) { ArchimatixEngine.createLibraryFromJSONFiles(); } EditorGUILayout.Space(); if (showClass == 3) { if (GUILayout.Button("Switch to 2D")) { showClass = 2; } } else { if (GUILayout.Button("Switch to 3D")) { showClass = 3; } } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); // SEARCH FIELD GUILayout.Label("Search", richRightLabelStyle); if (string.IsNullOrEmpty(searchString)) { searchString = ""; } EditorGUI.BeginChangeCheck(); GUI.SetNextControlName("TF_SEARCH"); searchString = GUILayout.TextField(searchString, GUILayout.Width(130)); if (EditorGUI.EndChangeCheck()) { string[] words = searchString.Split(' '); ArchimatixEngine.library.filterResultsUsingSearch(new List <string>(words)); lastTextField = "TF_SEARCH"; } if (GUILayout.Button("x", GUILayout.Width(20))) { GUI.FocusControl("dummy"); searchString = ""; ArchimatixEngine.library.filteredResults = null; } GUILayout.FlexibleSpace(); if (viewLayout == ViewLayout.EditList) { if (GUILayout.Button("Grid", GUILayout.Width(100))) { viewLayout = ViewLayout.Grid; } } else { if (GUILayout.Button("Edit", GUILayout.Width(100))) { viewLayout = ViewLayout.EditList; } } EditorGUILayout.EndHorizontal(); }
void OnGUIOld() { Library library = ArchimatixEngine.library; Event e = Event.current; switch (e.type) { case EventType.MouseDown: //Debug.Log("Down"); break; case EventType.DragUpdated: //Debug.Log("Drag and Drop sorting not supported... yet"); break; case EventType.DragPerform: Debug.Log("Drag and Drop sorting not supported... yet"); break; } //showDetailItem.target = EditorGUILayout.ToggleLeft("Show extra fields", showDetailItem.target); GUIStyle labelstyle = GUI.skin.GetStyle("Label"); labelstyle.alignment = TextAnchor.UpperLeft; labelstyle.fixedWidth = 300; //GUILayout.BeginHorizontal(); // WINDOW TITLE string libtype = (showClass == 3 ? "3D":"2D"); EditorGUILayout.BeginHorizontal(); labelstyle.fontSize = 24; GUILayout.Label("Archimatix " + libtype + " Library"); labelstyle.fontSize = 12; EditorGUILayout.Space(); if (GUILayout.Button("Refresh")) { ArchimatixEngine.createLibraryFromJSONFiles(); } EditorGUILayout.Space(); if (showClass == 3) { if (GUILayout.Button("Switch to 2D")) { showClass = 2; } } else { if (GUILayout.Button("Switch to 3D")) { showClass = 3; } } EditorGUILayout.EndHorizontal(); //GUILayout.FlexibleSpace(); //GUILayout.Space(10); //GUILayout.EndHorizontal(); //labelstyle.fontSize = 9; //GUILayout.Space(16); // SCROLL_VIEW GUIStyle shadowDown = new GUIStyle(); shadowDown.normal.background = bgTex; GUIStyle shadowUp = new GUIStyle(); shadowUp.normal.background = bgTexUp; // BEGIN FILTER BAR EditorGUILayout.BeginHorizontal(); GUILayout.BeginVertical(GUILayout.Width(100), GUILayout.Height(25)); GUILayout.EndVertical(); GUILayout.Space(20); // FILTERS EditorGUI.BeginChangeCheck(); showFilters.target = EditorGUILayout.ToggleLeft("Show Filters", showFilters.target); if (EditorGUI.EndChangeCheck()) { ArchimatixEngine.library.isFiltered = showFilters.target; } GUILayout.FlexibleSpace(); // SEARCH GUILayout.Label("Search"); EditorGUI.BeginChangeCheck(); GUI.SetNextControlName("TF_SEARCH"); searchString = GUILayout.TextField(searchString, GUILayout.Width(130)); if (EditorGUI.EndChangeCheck()) { string[] words = searchString.Split(' '); ArchimatixEngine.library.filterResultsUsingSearch(new List <string>(words)); lastTextField = "TF_SEARCH"; } if (GUILayout.Button("x", GUILayout.Width(20))) { GUI.FocusControl("dummy"); searchString = ""; ArchimatixEngine.library.filteredResults = null; } if (Event.current.type == EventType.KeyDown && (Event.current.keyCode == KeyCode.Return)) { GUI.FocusControl(lastTextField); e.Use(); } GUILayout.Space(20); EditorGUILayout.EndHorizontal(); // \ END FILTER BAR if (EditorGUILayout.BeginFadeGroup(showFilters.faded) && ArchimatixEngine.library.categories != null) { // COLUMN LABELS GUILayout.BeginHorizontal(); foreach (KeyValuePair <string, List <string> > kv in ArchimatixEngine.library.categories) { GUILayout.Label(kv.Key, GUILayout.Width(130)); } GUILayout.EndHorizontal(); GUILayout.Label(" ", shadowDown); filtersScrollPosition = EditorGUILayout.BeginScrollView(filtersScrollPosition, GUILayout.Width(position.width), GUILayout.Height(filtersHeight)); // TAG CATEGORIES GUILayout.BeginHorizontal(); if (queryTags == null) { queryTags = new List <string>(); } foreach (KeyValuePair <string, List <string> > kv in library.categories) { GUILayout.BeginVertical(GUILayout.Width(130)); //GUILayout.Label (kv.Key); foreach (string tag in kv.Value) { //GUILayout.Label ("- "+tag); EditorGUI.BeginChangeCheck(); EditorGUILayout.ToggleLeft(tag, queryTags.Contains(tag), GUILayout.Width(130)); if (EditorGUI.EndChangeCheck()) { if (queryTags.Contains(tag)) { queryTags.Remove(tag); } else { queryTags.Add(tag); } library.filterResultsUsing(queryTags); } } GUILayout.EndVertical(); } GUILayout.EndHorizontal(); // TAG CATEGORIES EditorGUILayout.EndScrollView(); GUILayout.Label(" ", shadowUp); GUILayout.Space(16); } EditorGUILayout.EndFadeGroup(); // CATALOG List <LibraryItem> libraryItems = null; //if (showClass == 1) /* * if (ArchimatixEngine.library.filteredResults.Count > 0) * { * * * libraryItems = ArchimatixEngine.library.filteredResults; * } */ GUILayout.Label(" ", shadowDown); int currentFiltersHeight = (showFilters.target ? filtersHeight + 36 : 0); Vector2 scrollPos = EditorGUILayout.BeginScrollView(libraryScrollPosition, GUILayout.Width(position.width), GUILayout.Height(position.height - 120 - currentFiltersHeight)); if (Vector2.Distance(scrollPos, libraryScrollPosition) > 1) { //Debug.Log ("NOT SCROLLING TO TARGET"); scrollingToTarget = false; libraryScrollPosition = scrollPos; } else if (scrollingToTarget) { libraryScrollPosition = Vector2.Lerp(libraryScrollPosition, libraryScrollTargetPosition, .05f); //Debug.Log ("SCROLLING TO TARGET "+Vector2.Distance(libraryScrollPosition, libraryScrollTargetPosition)); if (Vector2.Distance(libraryScrollPosition, libraryScrollTargetPosition) < 50) { scrollingToTarget = false; } } if (Event.current.type == EventType.Layout) { columnCount = (int)Math.Floor(position.width / (thumbnailSize + 20)); if (columnCount == 0) { columnCount = 1; } rowCount = libraryItems.Count / columnCount; rowCount++; cellCount = rowCount * columnCount; } EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); bool showDetailRow = false; LibraryItem libraryItem; for (int i = 0; i < cellCount; i++) { if (i >= libraryItems.Count) { break; } libraryItem = libraryItems[i]; if (i % columnCount == 0 && i > 0) { GUILayout.EndHorizontal(); if (showDetailRow) { showDetailRow = false; doDetailView(); } GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); } // MENU BUTTON EditorGUILayout.BeginVertical(); // ---------------------------- //Debug.Log("LIBRARY: " + poList.Count); if (i < libraryItems.Count) { if (detailItem == libraryItem) { showDetailRow = true; } // THE BIG CLICK if (GUILayout.Button(libraryItems[i].icon, GUILayout.Width(thumbnailSize), GUILayout.Height(thumbnailSize))) { if (Event.current.shift) { //Make a new Model For Sure AXEditorUtilities.createNewModel(); Library.instantiateParametricObject(libraryItem.readIntoLibraryFromRelativeAXOBJPath); } else { Library.instantiateParametricObject(libraryItem.readIntoLibraryFromRelativeAXOBJPath); } } } // LABEL AND DELETE BUTTON EditorGUILayout.BeginHorizontal(); string name = ""; if (i < libraryItems.Count) { name = libraryItem.Name; } GUILayout.Label(name, GUILayout.Width(thumbnailSize - 20), GUILayout.Height(16)); if (i < libraryItems.Count) { if (editingLibrary) { if (GUILayout.Button("-", GUILayout.Width(16))) { Library.removeLibraryItem(libraryItem); } } else { if (GUILayout.Button("i", GUILayout.Width(16))) { if (detailItem == libraryItem && showDetailItem.faded == 1) { //detailItem = ""; showDetailItem.target = false; libraryScrollTargetPosition = libraryScrollPosition + new Vector2(0, -thumbnailSize); scrollingToTarget = true; } else { detailScreen(libraryItem); showDetailItem.target = true; int row = (int)Mathf.Floor(i / columnCount); //if (row != currentRow) //{ libraryScrollTargetPosition = libraryScrollPosition + new Vector2(0, +thumbnailSize * 2); scrollingToTarget = true; //} //else //scrollingToTarget = false; currentRow = row; } } } } GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); GUILayout.Space(8); // ------------------------------ EditorGUILayout.EndVertical(); } EditorGUILayout.EndHorizontal(); if (showDetailRow) { showDetailRow = false; doDetailView(); } GUILayout.Space(256); EditorGUILayout.EndScrollView(); //GUILayout.FlexibleSpace(); EditorGUILayout.BeginHorizontal(); if (editingLibrary) { if (GUILayout.Button("Done", GUILayout.Width(32))) { editingLibrary = false; } } else { if (GUILayout.Button("Edit", GUILayout.Width(32))) { editingLibrary = true; } } GUILayout.FlexibleSpace(); EditorGUI.BeginChangeCheck(); thumbnailSize = EditorGUILayout.IntSlider(thumbnailSize, 32, 256, GUILayout.Width(300)); if (EditorGUI.EndChangeCheck()) { showDetailRow = false; detailItem = null; } EditorGUILayout.EndHorizontal(); labelstyle.fixedWidth = 0; }
public static Library loadLibraryMetadata() { //Debug.Log("Loading Binary Library"); string filename = getLibraryPath() + "axlibrary.dat"; if (File.Exists(filename)) { BinaryFormatter bf = new BinaryFormatter(); FileStream file = File.Open(filename, FileMode.Open); Library library = (Library)bf.Deserialize(file); file.Close(); if (library == null || library.libraryItems == null || library.libraryItems.Count == 0) { ArchimatixEngine.createLibraryFromJSONFiles(); } if (library == null || library.libraryItems == null || library.libraryItems.Count == 0) { Debug.Log("reloading library"); ArchimatixEngine.createLibraryFromJSONFiles(); } // check if the number of axfiles is different than the number of library items if (library != null && library.libraryItems != null) { DirectoryInfo info = new DirectoryInfo(Application.dataPath); FileInfo[] files = info.GetFiles("*.axobj", SearchOption.AllDirectories); if (files.Length != library.libraryItems.Count) { // this might be the case after you reinstall AX and the user has her own library items somewhere else in the asset folder. ArchimatixEngine.createLibraryFromJSONFiles(); } } if (library != null && library.libraryItems != null && library.libraryItems.Count > 0) { // check to make sure that the libraryItems have the right path // if not, then reread from JSON files. // if ( File.Exists(library.libraryItems[0].readIntoLibraryFromAbsoluteAXOBJPath)) // ArchimatixEngine.createLibraryFromJSONFiles(); library.cacheLibraryItems(); library.sortLibraryItems(); return(library); } } // no existing library ArchimatixEngine.createLibraryFromJSONFiles(); return(ArchimatixEngine.library); }