public static void Duplicate(InAudioNode audioNode) { InUndoHelper.DoInGroup(() => { List <Object> toUndo = new List <Object>(); toUndo.Add(audioNode._parent); toUndo.AddRange(audioNode._parent.GetAuxData()); InUndoHelper.RecordObjectFull(toUndo.ToArray(), "Undo Duplication Of " + audioNode.Name); if (audioNode._parent._type == AudioNodeType.Random) { (audioNode._parent._nodeData as RandomData).weights.Add(50); } NodeWorker.DuplicateHierarchy(audioNode, (@oldNode, newNode) => { var gameObject = audioNode.gameObject; if (oldNode._nodeData != null) { NodeDuplicate(oldNode, newNode, gameObject); } }); }); }
protected override void OnDrop(InAudioBankLink node, Object[] objects) { InUndoHelper.DragNDropUndo(node, "Bank Drag N Drop"); InAudioBankLink target = objects[0] as InAudioBankLink; NodeWorker.ReasignNodeParent(target, node); }
public static bool OnDrop(InAudioEventNode audioevent, Object[] objects) { InUndoHelper.DoInGroup(() => { //if (audioevent.Type == EventNodeType.Folder) //{ // UndoHelper.RecordObjectInOld(audioevent, "Created event"); // audioevent = CreateNode(audioevent, EventNodeType.Event); //} if (objects[0] as InAudioEventNode) { var movingEvent = objects[0] as InAudioEventNode; if (movingEvent.gameObject != audioevent.gameObject) { if (EditorUtility.DisplayDialog("Move?", "Warning, this will break all external references to this and all child nodes!\n" + "Move node from\"" + movingEvent.gameObject.name + "\" to \"" + audioevent.gameObject.name + "\"?", "Ok", "Cancel")) { InUndoHelper.DoInGroup(() => { CopyTo(movingEvent, audioevent); DeleteNodeNoGroup(movingEvent); }); } } else { InUndoHelper.RecordObjectFull(new Object[] { audioevent, movingEvent, movingEvent._parent }, "Event Move"); NodeWorker.ReasignNodeParent(movingEvent, audioevent); audioevent.EditorSettings.IsFoldedOut = true; } } var audioNode = objects[0] as InAudioNode; if (audioNode != null && audioNode.IsPlayable) { InUndoHelper.RecordObjectFull(audioevent, "Adding of Audio Action"); var action = AddEventAction <InEventAudioAction>(audioevent, EventActionTypes.Play); action.Node = audioNode; } var musicGroup = objects[0] as InMusicGroup; if (musicGroup != null) { InUndoHelper.RecordObjectFull(audioevent, "Adding of Music Action"); var action = AddEventAction <InEventMusicControl>(audioevent, EventActionTypes.PlayMusic); action.MusicGroup = musicGroup; } Event.current.UseEvent(); }); return(true); }
public static void StartFromScratch(InCommonDataManager Manager) { SystemFolderHelper.CreateIfMissing(FolderSettings.BankCreateFolder); try { DataCleanup.Cleanup(DataCleanup.CleanupVerbose.Silent); } catch (Exception) { //Do nothing as something is seriously wrong } int levelSize = 3; GameObject audioGO = new GameObject(); GameObject eventGO = new GameObject(); GameObject busGO = new GameObject(); GameObject bankGO = new GameObject(); Manager.BusTree = AudioBusWorker.CreateTree(busGO); Manager.BankLinkTree = AudioBankWorker.CreateTree(bankGO); Manager.AudioTree = AudioNodeWorker.CreateTree(audioGO, levelSize, Manager.BusTree); Manager.EventTree = AudioEventWorker.CreateTree(eventGO, levelSize); SaveAndLoad.CreateDataPrefabs(Manager.AudioTree.gameObject, Manager.EventTree.gameObject, Manager.BusTree.gameObject, Manager.BankLinkTree.gameObject); Manager.Load(true); if (Manager.BankLinkTree != null) { var bankLink = Manager.BankLinkTree.Children[0]; bankLink.Name = "Default - Auto loaded"; bankLink.AutoLoad = true; NodeWorker.AssignToNodes(Manager.AudioTree, node => { var data = (node.NodeData as InFolderData); if (data != null) { data.BankLink = Manager.BankLinkTree.GetChildren[0]; } }); NodeWorker.AssignToNodes(Manager.AudioTree, node => node.Bus = Manager.BusTree); AssetDatabase.Refresh(); DataCleanup.Cleanup(DataCleanup.CleanupVerbose.Silent); EditorApplication.SaveCurrentSceneIfUserWantsTo(); } else { Debug.LogError("There was a problem creating the data."); } }
private static void MoveNode(InAudioNode node, InAudioNode nodeToMove) { InUndoHelper.RecordObject( new UnityEngine.Object[] { node, node._nodeData, node._parent, node._parent != null ? node._parent._nodeData : null, nodeToMove._parent._nodeData, nodeToMove, nodeToMove._parent, nodeToMove._parent._nodeData }.AddObj(), "Audio Node Move"); NodeWorker.ReasignNodeParent(nodeToMove, node); Event.current.UseEvent(); }
public static InAudioEventNode Duplicate(InAudioEventNode audioEvent) { return(NodeWorker.DuplicateHierarchy(audioEvent, (@oldNode, newNode) => { newNode._actionList.Clear(); for (int i = 0; i < oldNode._actionList.Count; i++) { newNode._actionList.Add(NodeWorker.CopyComponent(oldNode._actionList[i])); } })); }
protected override bool CanDropObjects(InAudioBankLink node, Object[] objects) { if (node == null || objects == null) { return(false); } if (objects.Length > 0 && objects[0] as InAudioBankLink != null && node._type != AudioBankTypes.Bank) { return(!NodeWorker.IsChildOf(objects[0] as InAudioBankLink, node)); } return(false); }
public static bool CanDropObjects(InAudioEventNode audioEvent, Object[] objects) { if (objects.Length == 0 || audioEvent == null) { return(false); } if (audioEvent._type == EventNodeType.Event) { var nonEventDrop = CanDropNonEvent(objects); return(nonEventDrop); } else if (audioEvent._type == EventNodeType.Folder || audioEvent._type == EventNodeType.Root) { var draggingEvent = objects[0] as InAudioEventNode; if (draggingEvent != null) { if (draggingEvent._type == EventNodeType.Event) { return(true); } if ((draggingEvent._type == EventNodeType.Folder && !NodeWorker.IsChildOf(draggingEvent, audioEvent)) || draggingEvent._type == EventNodeType.EventGroup) { return(true); } } else { var nonEventDrop = CanDropNonEvent(objects) && !audioEvent.IsRootOrFolder; return(nonEventDrop); } } else if (audioEvent._type == EventNodeType.EventGroup) { var draggingEvent = objects[0] as InAudioEventNode; if (draggingEvent == null) { return(false); } if (draggingEvent._type == EventNodeType.Event) { return(true); } } return(false); }
protected override bool CanDropObjects(InAudioNode node, UnityEngine.Object[] objects) { if (node == null || objects == null) { return(false); } int clipCount = DragAndDrop.objectReferences.Count(p => p is AudioClip); int nodeCount = DragAndDrop.objectReferences.Count(p => p is InAudioNode); if (DragAndDrop.objectReferences.Length == 0) { return(false); } if (clipCount == objects.Length) //Handle clip count { //clipCount == 1 means it overrides the current clip if (node.Type == AudioNodeType.Audio && clipCount != 1) { return(false); } return(true); } else if (nodeCount == objects.Length) //Handle audio node drag n drop { if (node.Type == AudioNodeType.Audio) //Can't drop on an audionode as it can't have children { return(false); } var draggingNode = objects[0] as InAudioNode; if (!node.IsRootOrFolder && draggingNode.IsRootOrFolder) { return(false); } if (node == draggingNode) { return(false); } return(!NodeWorker.IsChildOf(objects[0] as InAudioNode, node)); } return(false); }
public static void CopyTo(InAudioNode audioNode, InAudioNode newParent) { List <Object> toUndo = new List <Object>(); toUndo.Add(audioNode._parent); toUndo.AddRange(audioNode._parent.GetAuxData()); InUndoHelper.RecordObjectFull(toUndo.ToArray(), "Undo Move"); NodeWorker.DuplicateHierarchy(audioNode, newParent, newParent.gameObject, (@oldNode, newNode) => { var gameObject = newParent.gameObject; if (oldNode._nodeData != null) { NodeDuplicate(oldNode, newNode, gameObject); } }); }
public static void AddNewParent(InAudioNode node, AudioNodeType parentType) { InUndoHelper.RecordObject(new Object[] { node, node._parent }, "Undo Add New Parent for " + node.Name); var newParent = CreateNode(node.gameObject, node._parent, parentType); var oldParent = node._parent; newParent.MixerGroup = node.MixerGroup; newParent.EditorSettings.IsFoldedOut = true; int index = oldParent._children.FindIndex(node); NodeWorker.RemoveFromParent(node); node.AssignParent(newParent); OnRandomNode(newParent); NodeWorker.RemoveFromParent(newParent); oldParent._children.Insert(index, newParent); }
public static void AddNewParent(InAudioNode node, AudioNodeType parentType) { InUndoHelper.RecordObject(new Object[] { node, node._parent, node.GetBank() }, "Undo Add New Parent for " + node.Name); var newParent = CreateNode(node.gameObject, node._parent, parentType); var oldParent = node._parent; newParent.MixerGroup = node.MixerGroup; newParent.FoldedOut = true; if (node._type == AudioNodeType.Folder) { InFolderData data = (InFolderData)newParent._nodeData; data.BankLink = oldParent.GetBank(); } int index = oldParent._children.FindIndex(node); NodeWorker.RemoveFromParent(node); node.AssignParent(newParent); OnRandomNode(newParent); NodeWorker.RemoveFromParent(newParent); oldParent._children.Insert(index, newParent); }
private void DrawMissingDataCreation() { bool missingaudio = Manager.AudioTree == null; bool missingaudioEvent = Manager.EventTree == null; bool missingbankLink = Manager.BankLinkTree == null; bool missingMusic = Manager.MusicTree == null; bool areAnyMissing = missingaudio | missingaudioEvent | missingbankLink | missingMusic; if (areAnyMissing) { string missingAudioInfo = missingaudio ? "Audio Data\n" : ""; string missingEventInfo = missingaudioEvent ? "Event Data\n" : ""; string missingBankInfo = missingbankLink ? "BankLink Data\n" : ""; string missingMusicInfo = missingMusic ? "Music Data\n" : ""; EditorGUILayout.BeginVertical(); EditorGUILayout.HelpBox(missingAudioInfo + missingEventInfo + missingMusicInfo + missingBankInfo + "is missing.\nThis may be because of new project data is required in this version of InAudio", MessageType.Error, true); bool areAllMissing = missingaudio && missingaudioEvent && missingbankLink && missingMusic; if (!areAllMissing) { if (GUILayout.Button("Create missing content", GUILayout.Height(30))) { int levelSize = 3; //How many subfolders by default will be created. Number is only a hint for new people if (missingaudio) { CreateAudioPrefab(levelSize); } if (missingaudioEvent) { CreateEventPrefab(levelSize); } if (missingbankLink) { CreateBankLinkPrefab(); } if (missingMusic) { CreateMusicPrefab(levelSize); } Manager.Load(true); if (Manager.AudioTree != null && Manager.BankLinkTree != null) { NodeWorker.AssignToNodes(Manager.AudioTree, node => { var data = (node._nodeData as InFolderData); if (data != null) { data.BankLink = Manager.BankLinkTree._getChildren[0]; } }); } if (Manager.MusicTree != null && Manager.BankLinkTree != null) { NodeWorker.AssignToNodes(Manager.MusicTree, node => { var folder = (node as InMusicFolder); if (folder != null) { folder._bankLink = Manager.BankLinkTree._getChildren[0]; } }); } #if !UNITY_5_2 EditorSceneManager.MarkSceneDirty(SceneManager.GetActiveScene()); EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo(); #else EditorApplication.MarkSceneDirty(); EditorApplication.SaveCurrentSceneIfUserWantsTo(); #endif } } DrawStartFromScratch(); EditorGUILayout.EndVertical(); } }
//Draw all nodes recursively void DrawTree(T node, int indentLevel) { if (node != null) { if (node.IsFiltered) { return; } EditorGUI.indentLevel = indentLevel + 1; bool clicked; //Draw node node.IsFoldedOut = OnNodeDraw(node, node == selectedNode, out clicked); Rect area = GUILayoutUtility.GetLastRect(); Rect drawArea = area; drawArea.y += area.height - 5; drawArea.height = 10; toDrawArea.Add(new DrawArea(node, area, drawArea)); if (node == selectedNode && focusOnSelectedNode && Event.current.type == EventType.Repaint) { ScrollPosition.y = area.y - 50; dirty = true; focusOnSelectedNode = false; } if (Event.current.type == EventType.DragUpdated || Event.current.type == EventType.DragPerform) { if (Event.current.Contains(drawArea) && DragAndDrop.objectReferences.Length > 0) { if (genericCanPlaceHere(node, DragAndDrop.objectReferences[0] as T)) { DragAndDrop.visualMode = DragAndDropVisualMode.Link; } } else if (Event.current.Contains(area) && CanDropObjects(node, DragAndDrop.objectReferences)) { DragAndDrop.visualMode = DragAndDropVisualMode.Link; } } if (Event.current.type == EventType.DragPerform) { requriesUpdate = true; updateTime = Time.time; if (Event.current.Contains(drawArea)) { if (genericCanPlaceHere(node, DragAndDrop.objectReferences[0] as T)) { genericPlaceHere(node, DragAndDrop.objectReferences[0] as T); } Event.current.UseEvent(); } else if (Event.current.Contains(area) && CanDropObjects(node, DragAndDrop.objectReferences)) { OnDrop(node, DragAndDrop.objectReferences); } } if (area.Contains(Event.current.mousePosition)) { if (Event.current.type == EventType.MouseDown && Event.current.button == 0) { DragAndDrop.PrepareStartDrag(); DragAndDrop.SetGenericData(node._ID.ToString(), new Object[] { node }); Event.current.UseEvent(); } if (Event.current.type == EventType.MouseDrag) { var genericData = DragAndDrop.GetGenericData(node._ID.ToString()) as Object[]; if (genericData != null) { var data = genericData.FirstOrDefault() as T; if (data != null && data == node) { DragAndDrop.objectReferences = new Object[] { node }; DragAndDrop.StartDrag("Dragging Node Element"); Event.current.UseEvent(); } } } } if (clicked) { selectedNode = node; GUIUtility.keyboardControl = 0; Event.current.UseEvent(); } if (Event.current.MouseUpWithin(area, 1)) { OnContext(node); SelectedNode = node; } EditorGUI.indentLevel = indentLevel - 1; if (Event.current.type == EventType.Layout) { NodeWorker.RemoveNullChildren(node); } if (node.IsFoldedOut) { for (int i = 0; i < node._getChildren.Count; ++i) { T child = node._getChildren[i]; DrawTree(child, indentLevel + 1); } } } }
protected override void OnDrop(InAudioNode node, UnityEngine.Object[] objects) { if (objects[0] as InAudioNode != null) //Drag N Drop internally in the tree, change the parent { node.IsFoldedOut = true; var nodeToMove = objects[0] as InAudioNode; UndoHelper.RecordObject( new UnityEngine.Object[] { node, node.NodeData, nodeToMove.Parent.NodeData, nodeToMove, nodeToMove.Parent }.AddObj( TreeWalker.FindAll(InAudioInstanceFinder.DataManager.BankLinkTree, link => link.Type == AudioBankTypes.Link ? link.LazyBankFetch : null).ToArray()), "Audio Node Move"); NodeWorker.ReasignNodeParent(nodeToMove, node); AudioBankWorker.RebuildBanks(InAudioInstanceFinder.DataManager.BankLinkTree, InAudioInstanceFinder.DataManager.AudioTree); } else if (node.Type != AudioNodeType.Audio) //Create new audio nodes when we drop clips { UndoHelper.RecordObject(UndoHelper.NodeUndo(node), "Adding Nodes to " + node.Name); AudioClip[] clips = objects.Convert(o => o as AudioClip); Array.Sort(clips, (clip, audioClip) => StringLogicalComparer.Compare(clip.name, audioClip.name)); for (int i = 0; i < clips.Length; ++i) { var clip = clips[i]; var child = AudioNodeWorker.CreateChild(node, AudioNodeType.Audio); var path = AssetDatabase.GetAssetPath(clip); try { //Try and get the name of the clip. Gets the name and removes the end. Assets/IntroSound.mp3 -> IntroSound int lastIndex = path.LastIndexOf('/') + 1; child.Name = path.Substring(lastIndex, path.LastIndexOf('.') - lastIndex); } catch (Exception) //If it happens to be a mutant path. Not even sure if this is possible, but better safe than sorry { child.Name = node.Name + " Child"; } (child.NodeData as InAudioData).EditorClip = clip; (child.NodeData as InAudioData).RuntimeClip = clip; AudioBankWorker.AddNodeToBank(child, clip); Event.current.Use(); } } else //Then it must be an audio clip dropped on an audio node, so assign the clip to that node { var nodeData = (node.NodeData as InAudioData); if (nodeData != null) { UndoHelper.RecordObject(UndoHelper.NodeUndo(node), "Change Audio Clip In " + node.Name); nodeData.EditorClip = objects[0] as AudioClip; if (Application.isPlaying) { if (node.GetBank().IsLoaded) { nodeData.RuntimeClip = objects[0] as AudioClip; } } AudioBankWorker.SwapClipInBank(node, objects[0] as AudioClip); } } }
public static void Duplicate(GameObject go, InMusicNode current, InMusicNode parent) { NodeWorker.DuplicateHierarchy(current, parent, go, (node, musicNode) => {}); }
public static void StartFromScratch(InCommonDataManager Manager) { try { DataCleanup.Cleanup(DataCleanup.CleanupVerbose.Silent); } catch (Exception) { Debug.LogError("InAudio: Problem cleaning data before creating project.\nPlease report bug to [email protected] or via the feedback window."); } int levelSize = 3; GameObject audioGO = new GameObject(); GameObject eventGO = new GameObject(); GameObject bankGO = new GameObject(); GameObject musicGO = new GameObject(); Manager.BankLinkTree = AudioBankWorker.CreateTree(bankGO); Manager.AudioTree = AudioNodeWorker.CreateTree(audioGO, levelSize); Manager.MusicTree = MusicWorker.CreateTree(musicGO, levelSize); Manager.EventTree = AudioEventWorker.CreateTree(eventGO, levelSize); SaveAndLoad.CreateDataPrefabs(Manager.AudioTree.gameObject, Manager.MusicTree.gameObject, Manager.EventTree.gameObject, Manager.BankLinkTree.gameObject); Manager.Load(true); if (Manager.BankLinkTree != null) { var bankLink = Manager.BankLinkTree._children[0]; bankLink._name = "Default - Auto loaded"; bankLink._autoLoad = true; NodeWorker.AssignToNodes(Manager.AudioTree, node => { var data = (node._nodeData as InFolderData); if (data != null) { data.BankLink = Manager.BankLinkTree._getChildren[0]; } }); NodeWorker.AssignToNodes(Manager.MusicTree, musicNode => { var folder = musicNode as InMusicFolder; if (folder != null) { folder._bankLink = Manager.BankLinkTree._getChildren[0]; } }); var firstAudioFolder = Manager.AudioTree._children[0]; AudioNodeWorker.CreateChild(firstAudioFolder, AudioNodeType.Audio, "Empty Example Audio Node"); var random = AudioNodeWorker.CreateChild(firstAudioFolder, AudioNodeType.Random); random.Name = "Random Node Example"; AudioNodeWorker.CreateChild(random, AudioNodeType.Audio, "Empty Example Audio Node"); AudioNodeWorker.CreateChild(random, AudioNodeType.Audio, "Empty Example Audio Node"); AudioNodeWorker.CreateChild(random, AudioNodeType.Audio, "Empty Example Audio Node"); var multi = AudioNodeWorker.CreateChild(firstAudioFolder, AudioNodeType.Multi, "Multi-Sound Example"); AudioNodeWorker.CreateChild(multi, AudioNodeType.Audio, "Played simultaneously"); AudioNodeWorker.CreateChild(multi, AudioNodeType.Audio, "Played simultaneously"); var sequence = AudioNodeWorker.CreateChild(firstAudioFolder, AudioNodeType.Sequence, "Sequence-Sound Example"); AudioNodeWorker.CreateChild(sequence, AudioNodeType.Audio, "Played first"); AudioNodeWorker.CreateChild(sequence, AudioNodeType.Audio, "Played secondly"); var firstEventFolder = Manager.EventTree._children[0]; firstEventFolder.FoldedOut = true; var audioEvent = AudioEventWorker.CreateNode(firstEventFolder, EventNodeType.Event); audioEvent.Name = "Playing Random Audio Event"; var action = AudioEventWorker.AddEventAction <InEventAudioAction>(audioEvent, EventActionTypes.Play); audioEvent.FoldedOut = true; action.Node = random; var firstMusicFolder = Manager.MusicTree._children[0]; var musicGroup = MusicWorker.CreateMusicGroup(firstMusicFolder, "Empty Music Group"); firstMusicFolder.FoldedOut = true; MusicWorker.CreateMusicGroup(musicGroup, "Empty Music Group - Child 1"); MusicWorker.CreateMusicGroup(musicGroup, "Empty Music Group - Child 2"); musicGroup.FoldedOut = true; AssetDatabase.Refresh(); DataCleanup.Cleanup(DataCleanup.CleanupVerbose.Silent); #if !UNITY_5_2 EditorSceneManager.MarkSceneDirty(SceneManager.GetActiveScene()); EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo(); #else EditorApplication.MarkSceneDirty(); EditorApplication.SaveCurrentSceneIfUserWantsTo(); #endif } else { Debug.LogError("InAudio: There was a problem creating the data.\nPlease report this bug to [email protected] or via the feedback window."); } }