private void _DrawProperties() { int width = showHierarchy ? Screen.width - leftSplitter.pos - leftSplitter.thickness : Screen.width; GUILayout.BeginArea(new Rect(showHierarchy ? leftSplitter.pos + leftSplitter.thickness : 0f, 0f, width, showClipList ? bottomSplitter.pos : Screen.height)); bool allCues = selectedHierarchyItems.Count > 0; bool allBuses = selectedHierarchyItems.Count > 0; foreach(TreeItem item in selectedHierarchyItems) { allCues &= item.Cue != null; allBuses &= item.Bus != null; } if(allBuses) { DrawHeader("BUSES", ref busSearchString, (Screen.width - leftSplitter.pos) / 4, true); EditorGUILayout.Space(); busScrollPos = EditorGUILayout.BeginScrollView(busScrollPos); EditorGUILayout.BeginHorizontal(); string searchString = busSearchString.ToLower(); List<TreeItem> drawnBuses = new List<TreeItem>(selectedHierarchyItems.Count); foreach(TreeItem item in hierarchyItems.Values) { if(selectedHierarchyItems.Contains(item) && !drawnBuses.Contains(item)) { _DrawBus(item, searchString, drawnBuses); } } EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); EditorGUILayout.EndScrollView(); } else if(allCues) { string nullSearch = null; if(selectedHierarchyItems.Count > 1) { DrawHeader("PROPERTIES (" + selectedHierarchyItems.Count + " SELECTED)", ref nullSearch, 0, true); } else { DrawHeader("PROPERTIES (" + selectedHierarchyItem.Cue.name + ")", ref nullSearch, 0, true); } propertyScrollPos = EditorGUILayout.BeginScrollView(propertyScrollPos); bool wasEnabled = GUI.enabled; GUI.enabled &= SECTR_VC.IsEditable(selectedHierarchyItem.Path); if(selectedHierarchyItem.Cue && (propertyEditor == null || propertyEditor.target != selectedHierarchyItem.Cue)) { int numSelected = selectedHierarchyItems.Count; SECTR_AudioCueEditor cueEditor = null; if(numSelected > 1) { SECTR_AudioCue[] cues = new SECTR_AudioCue[selectedHierarchyItems.Count]; for(int selectedIndex = 0; selectedIndex < numSelected; ++selectedIndex) { cues[selectedIndex] = selectedHierarchyItems[selectedIndex].Cue; } cueEditor = (SECTR_AudioCueEditor)Editor.CreateEditor(cues); } else { cueEditor = (SECTR_AudioCueEditor)Editor.CreateEditor(selectedHierarchyItem.Cue); } cueEditor.DrawBus = false; propertyEditor = cueEditor; } else if(selectedHierarchyItem.Bus && (propertyEditor == null || propertyEditor.target != selectedHierarchyItem.Bus)) { propertyEditor = (SECTR_Editor)Editor.CreateEditor(selectedHierarchyItem.Bus); } if(propertyEditor) { propertyEditor.WidthOverride = width; propertyEditor.OnInspectorGUI(); } GUI.enabled = wasEnabled; EditorGUILayout.EndScrollView(); } else if(selectedHierarchyItems.Count > 0) { string nullSearch = null; DrawHeader("MIXED SELECTION", ref nullSearch, 0, true); bool wasEnabled = GUI.enabled; GUI.enabled = false; GUILayout.Button("Cannot display Buses and Cues simultaneously.", GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true)); GUI.enabled = wasEnabled; } else { string nullSearch = null; DrawHeader("NO SELECTION", ref nullSearch, 0, true); bool wasEnabled = GUI.enabled; GUI.enabled = false; GUILayout.Button("Nothing Selected in Hierarchy View.", GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true)); GUI.enabled = wasEnabled; } GUILayout.EndArea(); }
private void _DuplicateSelected(TreeItem item, bool hierarchy) { _UpdateSelected(item, hierarchy); List<TreeItem> selectedItems = hierarchy ? selectedHierarchyItems : selectedClipItems; List<TreeItem> newItems = new List<TreeItem>(selectedItems.Count); foreach(TreeItem selectedItem in selectedItems) { TreeItem newItem = null; string dirPath = ""; string fileName = ""; SECTR_Asset.SplitPath(selectedItem.Path, out dirPath, out fileName); string copyName = selectedItem.Name + " Copy"; string newPath = dirPath + copyName + Path.GetExtension(fileName); if(AssetDatabase.CopyAsset(selectedItem.Path, newPath)) { SECTR_VC.WaitForVC(); if(selectedItem.Bus) { SECTR_AudioBus bus = SECTR_Asset.Load<SECTR_AudioBus>(newPath); newItem = new TreeItem(this, bus, newPath); } else if(selectedItem.Cue) { SECTR_AudioCue cue = SECTR_Asset.Load<SECTR_AudioCue>(newPath); newItem = new TreeItem(this, cue, newPath); } else if(selectedItem.Clip) { newItem = new TreeItem((AudioImporter)AssetImporter.GetAtPath(newPath), newPath, copyName); AudioClipFolder folder = clipItems[dirPath]; folder.items.Add(newItem); } if(newItem != null) { newItems.Add(newItem); } } } if(hierarchy) { selectedHierarchyItems = newItems; selectedHierarchyItem = selectedItems.Count > 0 ? selectedItems[0] : null; } else { selectedClipItems = newItems; selectedClipItem = selectedItems.Count > 0 ? selectedItems[0] : null; } propertyEditor = null; Repaint(); }
private TreeItem _CreateTreeItem(TreeItem selectedItem, bool createBus, string name) { SECTR_AudioBus parentBus = null; string dirPath = audioRootPath; string fileName = ""; string typeName = createBus ? "Bus" : "Cue"; if(string.IsNullOrEmpty(name)) { name = "New" + typeName; } if(selectedItem != null) { if(selectedItem.Bus) { parentBus = selectedItem.Bus; } else if(selectedItem.Cue) { parentBus = selectedItem.Cue.Bus; } SECTR_Asset.SplitPath(selectedItem.Path, out dirPath, out fileName); } else { foreach(TreeItem item in hierarchyItems.Values) { if((item.Bus && item.Bus.Parent == null) || (item.Cue && item.Cue.Bus == null)) { SECTR_Asset.SplitPath(item.Path, out dirPath, out fileName); break; } } dirPath = EditorUtility.SaveFolderPanel("Chose " + typeName + " Location", dirPath, ""); if(string.IsNullOrEmpty(dirPath)) { return null; } dirPath = dirPath.Replace(Application.dataPath, "Assets"); } string assetPath = ""; TreeItem newItem; if(createBus) { SECTR_AudioBus bus = SECTR_Asset.Create<SECTR_AudioBus>(dirPath, name, ref assetPath); bus.Parent = parentBus; newItem = new TreeItem(this, bus, assetPath); } else { SECTR_AudioCue cue = SECTR_Asset.Create<SECTR_AudioCue>(dirPath, name, ref assetPath); cue.Bus = parentBus; newItem = new TreeItem(this, cue, assetPath); } newItem.Rename = true; selectedHierarchyItem = newItem; selectedHierarchyItems.Clear(); selectedHierarchyItems.Add(selectedHierarchyItem); propertyEditor = null; return newItem; }
private void _StartRenameItem(TreeItem item, bool hierarchy) { if(item != null) { if(selectedHierarchyItem != null && selectedHierarchyItem.Rename) { selectedHierarchyItem.Rename = false; } if(selectedClipItem != null && selectedClipItem.Rename) { selectedClipItem.Rename = false; } if(hierarchy) { selectedHierarchyItem = item; selectedHierarchyItems.Clear(); selectedHierarchyItems.Add(selectedHierarchyItem); } else { selectedClipItem = item; selectedClipItems.Clear(); selectedClipItems.Add(selectedClipItem); selectedClipItem.Name = Path.GetFileNameWithoutExtension(selectedClipItem.Path); } item.Rename = true; propertyEditor = null; Repaint(); } }
private void _HandleEvents() { if(Event.current != null) { if(!string.IsNullOrEmpty(Event.current.commandName) && Event.current.commandName == "UndoRedoPerformed") { Repaint(); return; } if((showHierarchy && showProperties && leftSplitter.HandleEvents(this)) || (showClipList && (showHierarchy || showProperties) && bottomSplitter.HandleEvents(this))) { Repaint(); return; } #if UNITY_EDITOR_OSX bool heldControl = (Event.current.modifiers & EventModifiers.Command) != 0; #else bool heldControl = (Event.current.modifiers & EventModifiers.Control) != 0; #endif bool heldShift = (Event.current.modifiers & EventModifiers.Shift) != 0; switch(Event.current.type) { case EventType.MouseDown: if(Event.current.button == 0) { if(Event.current.mousePosition.x < leftSplitter.pos && Event.current.mousePosition.y < bottomSplitter.pos) { foreach(TreeItem item in displayedHierarchyItems) { if(item.WindowRect.Contains(Event.current.mousePosition)) { if(Event.current.clickCount > 1) { if(SECTR_VC.IsEditable(item.Path)) { _StartRenameItem(item, true); } } else { dragHierarchyItem = item; } break; } } } else if(Event.current.mousePosition.y > bottomSplitter.pos) { foreach(TreeItem item in displayedClipItems) { if(item.WindowRect.Contains(Event.current.mousePosition)) { if(Event.current.clickCount > 1) { if(SECTR_VC.IsEditable(item.Path)) { _StartRenameItem(item, false); } } else { dragClipItem = item; } break; } } } } break; case EventType.MouseUp: dragHierarchyItem = null; dragClipItem = null; dragHoverItem = null; if(selectedHierarchyItem != null && selectedHierarchyItem.Rename && !selectedHierarchyItem.WindowRect.Contains(Event.current.mousePosition)) { _CancelRename(selectedHierarchyItem); } else if(selectedClipItem != null && selectedClipItem.Rename && !selectedClipItem.WindowRect.Contains(Event.current.mousePosition)) { _CancelRename(selectedClipItem); } else if(Event.current.mousePosition.x < leftSplitter.pos && Event.current.mousePosition.y < bottomSplitter.pos) { lastSelectedHierarchy = true; TreeItem newSelection = Event.current.button == 0 ? null : selectedHierarchyItem; foreach(TreeItem item in displayedHierarchyItems) { if(item.WindowRect.Contains(Event.current.mousePosition)) { newSelection = item; break; } } if(newSelection != selectedHierarchyItem || heldControl || heldShift) { if(newSelection == null) { selectedHierarchyItem = null; selectedHierarchyItems.Clear(); } else if(heldControl) { if(selectedHierarchyItems.Contains(newSelection)) { selectedHierarchyItems.Remove(newSelection); if(selectedHierarchyItems.Count > 0) { selectedHierarchyItem = selectedHierarchyItems[0]; } else { selectedHierarchyItem = null; } } else { selectedHierarchyItems.Add(newSelection); selectedHierarchyItem = newSelection; } } else if(heldShift && selectedHierarchyItem != null) { foreach(TreeItem item in displayedHierarchyItems) { if((item.WindowRect.y >= selectedHierarchyItem.WindowRect.y && item.WindowRect.y <= newSelection.WindowRect.y) || (item.WindowRect.y <= selectedHierarchyItem.WindowRect.y && item.WindowRect.y >= newSelection.WindowRect.y)) { if(!selectedHierarchyItems.Contains(item)) { selectedHierarchyItems.Add(item); } } else { selectedHierarchyItems.Remove(item); } } selectedHierarchyItem = newSelection; } else { selectedHierarchyItem = newSelection; selectedHierarchyItems.Clear(); selectedHierarchyItems.Add(selectedHierarchyItem); } propertyEditor = null; GUI.FocusControl(null); Repaint(); } } else if(Event.current.mousePosition.y > bottomSplitter.pos) { lastSelectedHierarchy = false; TreeItem newSelection = Event.current.button == 0 ? null : selectedClipItem; foreach(TreeItem item in displayedClipItems) { if(item.WindowRect.Contains(Event.current.mousePosition)) { newSelection = item; break; } } if(newSelection != selectedClipItem || heldControl || heldShift) { if(newSelection == null) { selectedClipItem = null; selectedClipItems.Clear(); } else if(heldControl) { if(selectedClipItems.Contains(newSelection)) { selectedClipItems.Remove(newSelection); if(selectedClipItems.Count > 0) { selectedClipItem = selectedClipItems[0]; } else { selectedClipItem = null; } } else { selectedClipItems.Add(newSelection); selectedClipItem = newSelection; } } else if(heldShift && selectedClipItem != null) { foreach(TreeItem item in displayedClipItems) { if((item.WindowRect.y >= selectedClipItem.WindowRect.y && item.WindowRect.y <= newSelection.WindowRect.y) || (item.WindowRect.y <= selectedClipItem.WindowRect.y && item.WindowRect.y >= newSelection.WindowRect.y)) { if(!selectedClipItems.Contains(item)) { selectedClipItems.Add(item); } } else { selectedClipItems.Remove(item); } } selectedClipItem = newSelection; } else { selectedClipItem = newSelection; selectedClipItems.Clear(); selectedClipItems.Add(selectedClipItem); } Repaint(); } } break; case EventType.MouseDrag: if(Event.current.mousePosition.y > bottomSplitter.pos && dragClipItem != null) { if(!selectedClipItems.Contains(dragClipItem)) { selectedClipItem = dragClipItem; selectedClipItems.Clear(); selectedClipItems.Add(selectedClipItem); } DragAndDrop.PrepareStartDrag(); int numSelected = selectedClipItems.Count; Object[] objects = new Object[numSelected]; for(int selectedIndex = 0; selectedIndex < numSelected; ++selectedIndex) { objects[selectedIndex] = selectedClipItems[selectedIndex].Clip; } DragAndDrop.objectReferences = objects; DragAndDrop.StartDrag("Dragging " + dragClipItem.Name + " (AudioClip)"); Event.current.Use(); } else if(Event.current.mousePosition.x < leftSplitter.pos && dragHierarchyItem != null) { if(!selectedHierarchyItems.Contains(dragHierarchyItem)) { selectedHierarchyItem = dragHierarchyItem; selectedHierarchyItems.Clear(); selectedHierarchyItems.Add(selectedHierarchyItem); } DragAndDrop.PrepareStartDrag(); int numSelected = selectedHierarchyItems.Count; Object[] objects = new Object[numSelected]; for(int selectedIndex = 0; selectedIndex < numSelected; ++selectedIndex) { objects[selectedIndex] = selectedHierarchyItems[selectedIndex].AsObject; } DragAndDrop.objectReferences = objects; DragAndDrop.StartDrag("Dragging " + dragHierarchyItem.Name + " (" + objects[0].GetType() + ")"); Event.current.Use(); } break; case EventType.DragPerform: case EventType.DragUpdated: if(Event.current.mousePosition.x < leftSplitter.pos && Event.current.mousePosition.y < bottomSplitter.pos) { TreeItem hoverItem = null; Object dragObject = DragAndDrop.objectReferences[0]; if(dragObject && dragObject.GetType() == typeof(AudioClip)) { foreach(TreeItem item in displayedHierarchyItems) { if(item.WindowRect.Contains(Event.current.mousePosition)) { if(Event.current.type == EventType.DragPerform) { if(item.Cue != null && SECTR_VC.IsEditable(item.Path)) { SECTR_Undo.Record(item.Cue, "Add Clip"); foreach(TreeItem selectedItem in selectedClipItems) { if(selectedItem.Importer != null) { item.Cue.AddClip(selectedItem.Clip, false); } } selectedHierarchyItem = item; selectedHierarchyItems.Clear(); selectedHierarchyItems.Add(selectedHierarchyItem); DragAndDrop.AcceptDrag(); Repaint(); } else if(item.Bus != null) { foreach(TreeItem selectedItem in selectedClipItems) { if(selectedItem.Importer != null) { TreeItem newItem = _CreateTreeItem(item, false, selectedItem.Clip.name); if(newItem != null) { SECTR_AudioCue cue = newItem.Cue; #if UNITY_4 AudioImporter importer = selectedItem.Importer; cue.Loops = importer.loopable; cue.Spatialization = importer.threeD ? SECTR_AudioCue.Spatializations.Local3D : SECTR_AudioCue.Spatializations.Simple2D; #endif cue.AddClip(selectedItem.Clip, false); newItem.Rename = selectedClipItems.Count == 1; } } } AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); DragAndDrop.AcceptDrag(); Repaint(); } } else { hoverItem = item; DragAndDrop.visualMode = DragAndDropVisualMode.Copy; } break; } } } else if(dragObject && dragObject.GetType() == typeof(SECTR_AudioBus)) { SECTR_AudioBus bus = ((SECTR_AudioBus)dragObject); foreach(TreeItem item in displayedHierarchyItems) { if(item.WindowRect.Contains(Event.current.mousePosition)) { if(item.Bus != null && bus != item.Bus && bus.Parent != item.Bus && !bus.IsAncestorOf(item.Bus) && SECTR_VC.IsEditable(item.Path)) { if(Event.current.type == EventType.DragPerform) { foreach(TreeItem selectedItem in selectedHierarchyItems) { if(selectedItem.Bus != null && selectedItem.Bus.Parent != item.Bus && !selectedItem.Bus.IsAncestorOf(item.Bus) && SECTR_VC.IsEditable(selectedItem.Path)) { selectedItem.Bus.Parent = item.Bus; EditorUtility.SetDirty(selectedItem.Bus); } } DragAndDrop.AcceptDrag(); Repaint(); } else { hoverItem = item; DragAndDrop.visualMode = DragAndDropVisualMode.Copy; } } break; } } } else if(dragObject && dragObject.GetType() == typeof(SECTR_AudioCue)) { SECTR_AudioCue cue = ((SECTR_AudioCue)dragObject); foreach(TreeItem item in displayedHierarchyItems) { if(item.WindowRect.Contains(Event.current.mousePosition)) { if(item.Bus != null && item.Bus != cue.Bus && SECTR_VC.IsEditable(item.Path)) { if(Event.current.type == EventType.DragPerform) { foreach(TreeItem selectedItem in selectedHierarchyItems) { if(selectedItem.Cue && selectedItem.Cue.Bus != item.Bus && SECTR_VC.IsEditable(selectedItem.Path)) { selectedItem.Cue.Bus = item.Bus; EditorUtility.SetDirty(selectedItem.Cue); } } DragAndDrop.AcceptDrag(); Repaint(); } else { hoverItem = item; DragAndDrop.visualMode = DragAndDropVisualMode.Copy; } } break; } } } if(dragHoverItem != hoverItem) { dragHoverItem = hoverItem; Repaint(); } } break; case EventType.KeyUp: bool renameHierarchy = lastSelectedHierarchy && selectedHierarchyItem != null && selectedHierarchyItem.Rename; bool renameClip = !lastSelectedHierarchy && selectedClipItem != null && selectedClipItem.Rename; if(renameHierarchy || renameClip) { if(Event.current.keyCode == KeyCode.Escape) { if(renameHierarchy) { _CancelRename(selectedHierarchyItem); } else if(renameClip) { _CancelRename(selectedClipItem); } } else if(Event.current.keyCode == KeyCode.Return) { string newPath = ""; bool cue = selectedHierarchyItem != null && selectedHierarchyItem.Cue != null; bool bus = selectedHierarchyItem != null && selectedHierarchyItem.Bus != null; bool importer = selectedClipItem != null && selectedClipItem.Importer != null; if(renameHierarchy) { newPath = selectedHierarchyItem.Path.Replace(selectedHierarchyItem.DefaultName, selectedHierarchyItem.Name); if(newPath == selectedHierarchyItem.Path) { _CancelRename(selectedHierarchyItem); return; } AssetDatabase.RenameAsset(selectedHierarchyItem.Path, selectedHierarchyItem.Name); SECTR_VC.WaitForVC(); _RemoveHierarchyItem(selectedHierarchyItem); } else if(renameClip) { newPath = selectedClipItem.Path.Replace(Path.GetFileNameWithoutExtension(selectedClipItem.Path), selectedClipItem.Name); if(newPath == selectedClipItem.Path) { _CancelRename(selectedClipItem); return; } AssetDatabase.RenameAsset(selectedClipItem.Path, selectedClipItem.Name); SECTR_VC.WaitForVC(); _RemoveClipItem(selectedClipItem); } TreeItem renamedItem = null; if(renameHierarchy && cue) { SECTR_AudioBus newBus = (SECTR_AudioBus)AssetDatabase.LoadAssetAtPath(newPath, typeof(SECTR_AudioBus)); if(newBus) { renamedItem = new TreeItem(this, newBus, newPath); } } else if(renameHierarchy && bus) { SECTR_AudioCue newCue = (SECTR_AudioCue)AssetDatabase.LoadAssetAtPath(newPath, typeof(SECTR_AudioCue)); if(newCue) { renamedItem = new TreeItem(this, newCue, newPath); } } else if(renameClip && importer) { AudioImporter newImporter = (AudioImporter)AssetImporter.GetAtPath(newPath); if(newImporter) { renamedItem = new TreeItem(newImporter, newPath, Path.GetFileName(newPath)); } AudioClipFolder folder = clipItems[Path.GetDirectoryName(newPath) + "/"]; folder.items.Add(renamedItem); folder.items.Sort(delegate(TreeItem A, TreeItem B) { return string.Compare(A.DefaultName, B.DefaultName); }); } if(renamedItem != null) { if(renameHierarchy) { selectedHierarchyItem = renamedItem; selectedHierarchyItems.Clear(); selectedHierarchyItems.Add(selectedHierarchyItem); } else if(renameClip) { selectedClipItem = renamedItem; selectedClipItems.Clear(); selectedClipItems.Add(selectedHierarchyItem); } } else { Debug.LogWarning("Unable to rename asset. Name may already be in use."); _RefreshAssets(); } GUI.FocusControl(null); Repaint(); } } else { switch(Event.current.keyCode) { case KeyCode.Return: if(string.IsNullOrEmpty(GUI.GetNameOfFocusedControl())) { if(lastSelectedHierarchy && selectedHierarchyItem != null && SECTR_VC.IsEditable(selectedHierarchyItem.Path)) { _StartRenameItem(selectedHierarchyItem, true); } else if(!lastSelectedHierarchy && selectedClipItem != null && SECTR_VC.IsEditable(selectedClipItem.Path)) { _StartRenameItem(selectedClipItem, false); Repaint(); } } else if(changedAudioClip) { GUI.FocusControl(null); Repaint(); } break; case KeyCode.D: if(heldControl) { if(lastSelectedHierarchy && selectedHierarchyItem != null) { _DuplicateSelected(selectedHierarchyItem, true); } else if(!lastSelectedHierarchy && selectedClipItem != null) { _DuplicateSelected(selectedClipItem, false); } } break; case KeyCode.Delete: case KeyCode.Backspace: if(string.IsNullOrEmpty(GUI.GetNameOfFocusedControl())) { if(lastSelectedHierarchy && selectedHierarchyItem != null && SECTR_VC.IsEditable(selectedHierarchyItem.Path)) { _DeleteSelected(selectedHierarchyItem, true); } else if(!lastSelectedHierarchy && selectedClipItem != null && SECTR_VC.IsEditable(selectedClipItem.Path)) { _DeleteSelected(selectedClipItem, false); } } break; case KeyCode.Escape: SECTR_AudioSystem.StopAudition(); break; case KeyCode.Space: if(lastSelectedHierarchy && selectedHierarchyItem != null && selectedHierarchyItem.Cue != null) { SECTR_AudioSystem.Audition(selectedHierarchyItem.Cue); } else if(!lastSelectedHierarchy && selectedClipItem != null) { SECTR_AudioSystem.Audition(selectedClipItem.Clip); } break; case KeyCode.UpArrow: case KeyCode.DownArrow: case KeyCode.LeftArrow: case KeyCode.RightArrow: if(lastSelectedHierarchy && selectedHierarchyItem != null) { int numDisplayed = displayedHierarchyItems.Count; for(int treeIndex = 0; treeIndex < numDisplayed; ++treeIndex) { if(displayedHierarchyItems[treeIndex] == selectedHierarchyItem) { if(Event.current.keyCode == KeyCode.UpArrow && treeIndex > 0) { selectedHierarchyItem = displayedHierarchyItems[treeIndex - 1]; if(!Event.current.shift) { selectedHierarchyItems.Clear(); } if(!selectedHierarchyItems.Contains(selectedHierarchyItem)) { selectedHierarchyItems.Add(selectedHierarchyItem); } } else if(Event.current.keyCode == KeyCode.DownArrow && treeIndex < numDisplayed - 1) { selectedHierarchyItem = displayedHierarchyItems[treeIndex + 1]; if(!Event.current.shift) { selectedHierarchyItems.Clear(); } if(!selectedHierarchyItems.Contains(selectedHierarchyItem)) { selectedHierarchyItems.Add(selectedHierarchyItem); } } else if(Event.current.keyCode == KeyCode.RightArrow && selectedHierarchyItem.Bus != null) { selectedHierarchyItem.Expanded = true; } else if(Event.current.keyCode == KeyCode.LeftArrow && selectedHierarchyItem.Bus != null) { selectedHierarchyItem.Expanded = false; } Repaint(); break; } } } else if(!lastSelectedHierarchy && selectedClipItem != null) { int numDisplayed = displayedClipItems.Count; for(int treeIndex = 0; treeIndex < numDisplayed; ++treeIndex) { if(displayedClipItems[treeIndex] == selectedClipItem) { if(Event.current.keyCode == KeyCode.UpArrow && treeIndex > 0) { selectedClipItem = displayedClipItems[treeIndex - 1]; if(!Event.current.shift) { selectedClipItems.Clear(); } if(!selectedClipItems.Contains(selectedClipItem)) { selectedClipItems.Add(selectedClipItem); } if(selectedClipItem.ScrollRect.y < clipScrollPos.y) { clipScrollPos.y = selectedClipItem.ScrollRect.y; } } else if(Event.current.keyCode == KeyCode.DownArrow && treeIndex < numDisplayed - 1) { selectedClipItem = displayedClipItems[treeIndex + 1]; if(!Event.current.shift) { selectedClipItems.Clear(); } if(!selectedClipItems.Contains(selectedClipItem)) { selectedClipItems.Add(selectedClipItem); } if(selectedClipItem.ScrollRect.y > clipScrollPos.y + clipScrollRect.height) { clipScrollPos.y = selectedClipItem.ScrollRect.y; } } else if(Event.current.keyCode == KeyCode.RightArrow && selectedClipItem != null) { selectedClipItem.Expanded = true; } else if(Event.current.keyCode == KeyCode.LeftArrow && selectedClipItem != null) { selectedClipItem.Expanded = false; } Repaint(); break; } } } break; } } break; case EventType.ContextClick: GenericMenu menu = new GenericMenu(); menu.AddItem(new GUIContent("Show Hierarchy"), showHierarchy, delegate() { showHierarchy = !showHierarchy; UnityEditor.EditorPrefs.SetBool(showPrefPrefix + "Hierarchy", showHierarchy); }); menu.AddItem(new GUIContent("Show Properties"), showProperties, delegate() { showProperties = !showProperties; UnityEditor.EditorPrefs.SetBool(showPrefPrefix + "Properties", showProperties); }); menu.AddItem(new GUIContent("Show Audio Clips"), showClipList, delegate() { showClipList = !showClipList; UnityEditor.EditorPrefs.SetBool(showPrefPrefix + "ClipList", showClipList); }); if(Event.current.mousePosition.x < leftSplitter.pos || Event.current.mousePosition.y > bottomSplitter.pos) { menu.AddSeparator(null); bool hasVC = SECTR_VC.HasVC(); if(Event.current.mousePosition.x < leftSplitter.pos && Event.current.mousePosition.y < bottomSplitter.pos) { TreeItem cloneItem = null; foreach(TreeItem item in displayedHierarchyItems) { if(item.WindowRect.Contains(Event.current.mousePosition)) { cloneItem = item; bool editable = !hasVC || SECTR_VC.IsEditable(item.Path); if(hasVC) { if(!editable) { menu.AddItem(new GUIContent("Check Out"), false, delegate() { _CheckoutSelected(item, true); }); } else { menu.AddItem(new GUIContent("Revert"), false, delegate() { _RevertSelected(item, true); }); } } menu.AddItem(new GUIContent("Show In Project"), false, delegate() { if(item.Cue != null) Selection.activeObject = item.Cue; if(item.Bus != null) Selection.activeObject = item.Bus; EditorUtility.FocusProjectWindow(); }); menu.AddSeparator(""); menu.AddItem(new GUIContent("Duplicate"), false, delegate() { _DuplicateSelected(item, true); }); if(editable) { menu.AddItem(new GUIContent("Rename"), false, delegate() { _StartRenameItem(item, true); }); menu.AddItem(new GUIContent("Delete"), false, delegate() { _DeleteSelected(item, true); }); } else { menu.AddSeparator("Rename"); menu.AddSeparator("Delete"); } menu.AddSeparator(null); break; } } menu.AddItem(new GUIContent("Create New Bus"), false, delegate() { _CreateTreeItem(cloneItem, true, null); Repaint(); }); menu.AddItem(new GUIContent("Create New Cue"), false, delegate() { _CreateTreeItem(cloneItem, false, null); Repaint(); }); } else if(Event.current.mousePosition.y > bottomSplitter.pos) { foreach(TreeItem item in displayedClipItems) { if(item.WindowRect.Contains(Event.current.mousePosition)) { bool editable = !hasVC || SECTR_VC.IsEditable(item.Path); // Project Items if(SECTR_VC.HasVC()) { if(!editable) { menu.AddItem(new GUIContent("Check Out"), false, delegate() { _CheckoutSelected(item, false); }); } else { menu.AddItem(new GUIContent("Revert"), false, delegate() { _RevertSelected(item, false); }); } } menu.AddItem(new GUIContent("Show In Project"), false, delegate() { Selection.activeObject = item.Clip; EditorUtility.FocusProjectWindow(); }); menu.AddSeparator(""); menu.AddItem(new GUIContent("Duplicate"), false, delegate() { _DuplicateSelected(item, false); }); if(editable) { menu.AddItem(new GUIContent("Rename"), false, delegate() { _StartRenameItem(item, false); }); menu.AddItem(new GUIContent("Delete"), false, delegate() { _DeleteSelected(item, false); }); } else { menu.AddSeparator("Rename"); menu.AddSeparator("Delete"); } menu.AddSeparator(""); // Creation Items if(selectedHierarchyItem != null && selectedHierarchyItem.Cue != null && !selectedHierarchyItem.Cue.HasClip(item.Clip)) { menu.AddItem(new GUIContent("Add Selected to Cue"), false, delegate() { SECTR_Undo.Record(selectedHierarchyItem.Cue, "Add Clips"); foreach(TreeItem selectedItem in selectedClipItems) { selectedHierarchyItem.Cue.AddClip(selectedItem.Clip, false); } Repaint(); }); } else { menu.AddSeparator("Add Clip to Selected Cue"); } menu.AddItem(new GUIContent("Create Cues from Selected"), false, delegate() { foreach(TreeItem selectedItem in selectedClipItems) { TreeItem newItem = _CreateTreeItem(selectedHierarchyItem, false, selectedItem.Clip.name); if(newItem != null) { newItem.Rename = selectedClipItems.Count == 1; SECTR_AudioCue cue = newItem.Cue; #if UNITY_4_0 AudioImporter importer = (AudioImporter)AssetImporter.GetAtPath(selectedItem.Path); cue.Spatialization = importer.threeD ? SECTR_AudioCue.Spatializations.Local3D : SECTR_AudioCue.Spatializations.Simple2D; cue.Loops = importer.loopable; #endif cue.AddClip(selectedItem.Clip, false); } } Repaint(); }); menu.AddSeparator(""); break; } } menu.AddItem(new GUIContent("Show Advanced Properties"), showFullClipDetails, delegate() { showFullClipDetails = !showFullClipDetails; UnityEditor.EditorPrefs.SetBool(fullDetailsPref, showFullClipDetails); Repaint(); }); menu.AddItem(new GUIContent("Close All Folders"), false, delegate() { foreach(string path in clipItems.Keys) { clipItems[path].expanded = false; UnityEditor.EditorPrefs.SetBool(expandedPrefPrefix + path, false); } Repaint(); }); } } // Items in all menus. menu.AddSeparator(null); menu.AddItem(new GUIContent("Bake All HDR Keys"), false, delegate() { List<string> paths = new List<string>(); List<string> extensions = new List<string>() { ".asset", }; bakeMaster = SECTR_ComputeRMS.BakeList(SECTR_Asset.GetAll<SECTR_AudioCue>(audioRootPath, extensions, ref paths, false)); }); menu.AddSeparator(null); menu.AddItem(new GUIContent("Refresh Assets"), false, delegate() { _RefreshAssets(); }); menu.AddSeparator(null); menu.AddItem(new GUIContent("Change Audio Root"), false, delegate() { _SelectAudioRoot(); _RefreshAssets(); }); menu.ShowAsContext(); break; } } }