/// <summary>
        /// EDITOR: Remove and destroy a node (except Output)
        /// </summary>
        /// <param name="nodeToDelete">The node you wish to delete</param>
        public void DeleteNode(AudioNode nodeToDelete)
        {
            if (nodeToDelete == null)
            {
                Debug.LogWarning("Trying to remove null node!");
                return;
            }
            else if (nodeToDelete == this.output)
            {
                Debug.LogWarning("Trying to delete output node!");
                return;
            }

            for (int i = 0; i < this.nodes.Count; i++)
            {
                AudioNode tempNode = this.nodes[i];
                if (tempNode != nodeToDelete)
                {
                    if (tempNode.Input != null && nodeToDelete.Output != null)
                    {
                        tempNode.Input.RemoveConnection(nodeToDelete.Output);
                    }
                }
            }

            nodeToDelete.DeleteConnections();
            this.nodes.Remove(nodeToDelete);
            ScriptableObject.DestroyImmediate(nodeToDelete, true);
            EditorUtility.SetDirty(this);
        }
        /// <summary>
        /// Remove a node from the current AudioEvent and delete it from the asset
        /// </summary>
        /// <param name="positionObject">The position of the object to delete</param>
        private void RemoveNodeAtPosition(object positionObject)
        {
            AudioNode tempNode = GetNodeAtPosition((Vector2)positionObject);

            this.selectedEvent.DeleteNode(tempNode);
            EditorUtility.SetDirty(this.selectedEvent);
        }
        /// <summary>
        /// Process mouse clicks and call appropriate editor functions
        /// </summary>
        private void GetInput()
        {
            if (this.selectedEvent == null)
            {
                return;
            }

            Event e = Event.current;

            switch (e.type)
            {
            case EventType.MouseDown:
                this.selectedNode      = GetNodeAtPosition(e.mousePosition);
                Selection.activeObject = this.selectedNode;
                if (e.button == 0)
                {
                    HandleLeftClick(e);
                }
                else if (e.button == 1)
                {
                    HandleRightClick(e);
                }
                break;

            case EventType.MouseUp:
                HandleMouseUp(e);
                break;

            default:
                HandleMouseMovement(e);
                break;
            }
        }
        /// <summary>
        /// Perform necessary actions for the mouse moving while a button is held down
        /// </summary>
        /// <param name="e">The input event handled by Unity</param>
        private void HandleMouseMovement(Event e)
        {
            if (leftButtonDown && selectedNode != null && e.shift)
            {
                Vector3           tempMove = new Vector2(lastMousePos.x, lastMousePos.y) - e.mousePosition;
                AudioNodeOutput[] outputs  = selectedNode.Input.ConnectedNodes;
                for (int i = 0; i < outputs.Length; i++)
                {
                    outputs[i].ParentNode.MoveBy(tempMove);
                }
            }

            if (this.selectedOutput == null)
            {
                if (this.panGraph && this.selectedNode == null)
                {
                    if (Vector2.Distance(e.mousePosition, this.lastMousePos) > 0)
                    {
                        this.hasPanned = true;
                        this.panX     += (e.mousePosition.x - this.lastMousePos.x);
                        this.panY     += (e.mousePosition.y - this.lastMousePos.y);
                    }
                }
            }
            else
            {
                AudioNode.DrawCurve(ConvertToLocalPosition(this.selectedOutput.Center), e.mousePosition);
            }

            this.lastMousePos = e.mousePosition;
        }
        /// <summary>
        /// Perform necessary actions for the left mouse button being pushed this frame
        /// </summary>
        /// <param name="e">The input event handled in Unity</param>
        private void HandleLeftClick(Event e)
        {
            this.leftButtonDown     = true;
            this.rightButtonClicked = false;
            this.selectedOutput     = GetOutputAtPosition(e.mousePosition);

            this.selectedNode = GetNodeAtPosition(e.mousePosition);
        }
        /// <summary>
        /// Remove all connections from an output connector
        /// </summary>
        /// <param name="positionObject"></param>
        public void ClearOutput(object positionObject)
        {
            AudioNodeOutput tempOutput = GetOutputAtPosition((Vector2)positionObject);

            for (int i = 0; i < this.selectedEvent.EditorNodes.Count; i++)
            {
                AudioNode tempNode = this.selectedEvent.EditorNodes[i];
                if (tempNode.Input != null)
                {
                    tempNode.Input.RemoveConnection(tempOutput);
                }
            }
        }
        /// <summary>
        /// Perform necessary actions for the a mouse button being released this frame
        /// </summary>
        /// <param name="e">The input event handled by Unity</param>
        private void HandleMouseUp(Event e)
        {
            this.leftButtonDown = false;
            if (this.rightButtonClicked && !this.hasPanned)
            {
                this.selectedNode   = GetNodeAtPosition(e.mousePosition);
                this.selectedOutput = GetOutputAtPosition(e.mousePosition);
                AudioNodeInput tempInput = GetInputAtPosition(e.mousePosition);

                if (tempInput != null)
                {
                    InputContextMenu(e.mousePosition);
                }
                else if (this.selectedOutput != null)
                {
                    OutputContextMenu(e.mousePosition);
                }
                else if (this.selectedNode == null)
                {
                    CanvasContextMenu(e.mousePosition);
                }
                else
                {
                    ModifyNodeContextMenu(e.mousePosition);
                }
            }
            else
            {
                if (this.selectedOutput != null)
                {
                    AudioNodeInput hoverInput = GetInputAtPosition(e.mousePosition);
                    if (hoverInput != null)
                    {
                        hoverInput.AddConnection(this.selectedOutput);
                    }
                }
            }

            this.panGraph           = false;
            this.hasPanned          = false;
            this.selectedOutput     = null;
            this.rightButtonClicked = false;
            this.leftButtonDown     = false;
        }
Beispiel #8
0
        /// <summary>
        /// EDITOR: Sort the inputs in descending vertical order in the graph
        /// </summary>
        public void SortConnections()
        {
            List <AudioNodeOutput> updatedNodes = new List <AudioNodeOutput>();

            while (updatedNodes.Count < this.connectedNodes.Length)
            {
                AudioNode nextNode = this.connectedNodes[0].ParentNode;
                for (int i = 0; i < this.connectedNodes.Length; i++)
                {
                    AudioNode tempNode = this.connectedNodes[i].ParentNode;
                    if (updatedNodes.Contains(nextNode.Output) || (tempNode.NodeRect.y < nextNode.NodeRect.y && !updatedNodes.Contains(tempNode.Output)))
                    {
                        nextNode = tempNode;
                    }
                }
                updatedNodes.Add(nextNode.Output);
            }

            this.connectedNodes = updatedNodes.ToArray();
        }
        /// <summary>
        /// Find a node that overlaps a position on the graph
        /// </summary>
        /// <param name="position">The position on the graph to check against the nodes</param>
        /// <returns>The first node found that occupies the specified position or null</returns>
        private AudioNode GetNodeAtPosition(Vector2 position)
        {
            if (this.selectedEvent == null)
            {
                return(null);
            }

            position = ConvertToGlobalPosition(position);

            for (int i = 0; i < this.selectedEvent.EditorNodes.Count; i++)
            {
                AudioNode tempNode = this.selectedEvent.EditorNodes[i];
                if (tempNode.NodeRect.Contains(position))
                {
                    return(tempNode);
                }
            }

            return(null);
        }
        /// <summary>
        /// Find an input connector that overlaps the position on the graph
        /// </summary>
        /// <param name="position">The position on the graph to test against all input connectors</param>
        /// <returns>The first input connector found that occupies the specified position or null</returns>
        private AudioNodeInput GetInputAtPosition(Vector2 position)
        {
            if (this.selectedEvent == null)
            {
                return(null);
            }

            position = ConvertToGlobalPosition(position);

            for (int i = 0; i < this.selectedEvent.EditorNodes.Count; i++)
            {
                AudioNode tempNode = this.selectedEvent.EditorNodes[i];
                if (tempNode.Input != null && tempNode.Input.Window.Contains(position))
                {
                    return(tempNode.Input);
                }
            }

            return(null);
        }
        /// <summary>
        /// Find an output connector that overlaps the position on the graph
        /// </summary>
        /// <param name="position">The position on the graph to test against all output connectors</param>
        /// <returns>The first output connector found that occupies the specified position or null</returns>
        private AudioNodeOutput GetOutputAtPosition(Vector2 position)
        {
            position = ConvertToGlobalPosition(position);
            if (this.selectedEvent == null)
            {
                Debug.LogWarning("Tried to get output with no selected event");
                return(null);
            }

            for (int i = 0; i < this.selectedEvent.EditorNodes.Count; i++)
            {
                AudioNode tempNode = this.selectedEvent.EditorNodes[i];

                if (tempNode.Output != null && tempNode.Output.Window.Contains(position))
                {
                    return(tempNode.Output);
                }
            }

            return(null);
        }
        /// <summary>
        /// Display the nodes for an AuidoEvent on the graph
        /// </summary>
        /// <param name="audioEvent">The audio event to display the nodes for</param>
        private void DrawEventNodes(AudioEvent audioEvent)
        {
            if (audioEvent == null)
            {
                return;
            }

            if (audioEvent.EditorNodes == null)
            {
                return;
            }

            GUI.BeginGroup(new Rect(this.panX, this.panY, CANVAS_SIZE, CANVAS_SIZE));
            BeginWindows();
            for (int i = 0; i < audioEvent.EditorNodes.Count; i++)
            {
                AudioNode currentNode = audioEvent.EditorNodes[i];
                currentNode.DrawNode(i);
            }
            EndWindows();
            GUI.EndGroup();
        }
Beispiel #13
0
        /// <summary>
        /// Select a node with the current language in the AudioManager
        /// </summary>
        /// <param name="activeEvent">The existing runtime audio event</param>
        public override void ProcessNode(ActiveEvent activeEvent)
        {
            if (this.input.ConnectedNodes == null || this.input.ConnectedNodes.Length == 0)
            {
                Debug.LogWarningFormat("No connected nodes for {0}", this.name);
                return;
            }

            for (int i = 0; i < this.input.ConnectedNodes.Length; i++)
            {
                AudioNode tempNode = this.input.ConnectedNodes[i].ParentNode;
                if (tempNode.GetType() == typeof(AudioVoiceFile))
                {
                    AudioVoiceFile voiceNode = (AudioVoiceFile)tempNode;
                    if (voiceNode.Language == AudioManager.CurrentLanguage)
                    {
                        ProcessConnectedNode(i, activeEvent);
                        return;
                    }
                }
            }

            Debug.LogErrorFormat(activeEvent.rootEvent, "AudioManager: Event \"{0}\" not localized for language: {1}", activeEvent.rootEvent.name, AudioManager.CurrentLanguage);
        }
 /// <summary>
 /// EDITOR: Add a created node to the event
 /// </summary>
 /// <param name="newNode">The node to add</param>
 public void AddNode(AudioNode newNode)
 {
     this.nodes.Add(newNode);
 }