Esempio n. 1
0
        public static void MoveNodeOneUp <T>(T node) where T : Object, InITreeNode <T>
        {
            if (node is InAudioNode)//As parent could be a random one, it needs to record this first
            {
                InUndoHelper.RecordObject(new Object[] { node._getParent, (node._getParent as InAudioNode)._nodeData },
                                          "Undo Reorder Of " + node.GetName);
            }
            else
            {
                InUndoHelper.RecordObject(new Object[] { node._getParent }, "Undo Reorder Of " + node.GetName);
            }

            var children = node._getParent._getChildren;
            var index    = children.IndexOf(node);

            if (index != 0 && children.Count > 0)
            {
                //TODO Remove hack
                if (node.GetType() == typeof(InAudioNode))
                {
                    var audioNode = node as InAudioNode;
                    if (audioNode._parent._type == AudioNodeType.Random)
                    {
                        (audioNode._parent._nodeData as RandomData).weights.SwapAtIndexes(index, index - 1);
                    }
                }
                children.SwapAtIndexes(index, index - 1);
            }
        }
Esempio n. 2
0
        public static void ChangeBankOverride(InMusicFolder node)
        {
            var all = GetAllBanks();

            InUndoHelper.RecordObject(all.ToArray().AddObj(node), "Changed Bank");
            node._overrideParentBank = !node._overrideParentBank;
            RebuildBanks();
        }
Esempio n. 3
0
 public static void DeleteBank(InAudioBankLink toDelete)
 {
     InUndoHelper.DoInGroup(() =>
     {
         InUndoHelper.RecordObject(InAudioInstanceFinder.DataManager.AudioTree.gameObject.GetComponents <MonoBehaviour>().Add(toDelete).Add(InAudioInstanceFinder.DataManager.MusicTree.gameObject.GetComponents <MonoBehaviour>()), "Bank detele");
         toDelete._parent._getChildren.Remove(toDelete);
         InUndoHelper.Destroy(toDelete);
     });
 }
Esempio n. 4
0
        public static void ChangeAudioNodeBank(InAudioNode node, InAudioBankLink newBank)
        {
            var all = GetAllBanks();

            InUndoHelper.RecordObject(all.ToArray().AddObj(node._nodeData), "Changed Bank");
            InFolderData data = (node._nodeData as InFolderData);

            data.BankLink = newBank;
            RebuildBanks();
        }
        public static AudioEventAction AddEventAction(InAudioEventNode audioevent, Type eventActionType, EventActionTypes enumType)
        {
            InUndoHelper.RecordObject(audioevent, "Event Action Creation");
            var eventAction = audioevent.gameObject.AddComponentUndo(eventActionType) as AudioEventAction;

            audioevent._actionList.Add(eventAction);
            eventAction._eventActionType = enumType;

            return(eventAction);
        }
Esempio n. 6
0
        public static void ChangeBankOverride(InAudioNode node)
        {
            var all = GetAllBanks();

            InUndoHelper.RecordObject(all.ToArray().AddObj(node._nodeData), "Changed Bank");
            InFolderData data = (node._nodeData as InFolderData);

            data.OverrideParentBank = !data.OverrideParentBank;
            RebuildBanks();
        }
        public static InAudioEventNode DeleteActionAtIndex(InAudioEventNode audioevent, int index)
        {
            InUndoHelper.RecordObject(audioevent, "Event Action Creation");
            InUndoHelper.Destroy(audioevent._actionList[index]);


            audioevent._actionList.RemoveAt(index);

            return(audioevent);
        }
Esempio n. 8
0
        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();
        }
Esempio n. 9
0
        public static void ChangeMusicNodeBank(InMusicNode node, InAudioBankLink newBank)
        {
            var all = GetAllBanks();

            InUndoHelper.RecordObject(all.ToArray().AddObj(node), "Changed Bank");
            InMusicFolder data = (node as InMusicFolder);

            data._bankLink = newBank;
            RebuildBanks();
        }
Esempio n. 10
0
 private void AssignNewParent(InAudioNode newParent, InAudioNode node, int index)
 {
     if (newParent._type == AudioNodeType.Random)
     {
         var randomData = newParent._nodeData as RandomData;
         InUndoHelper.RecordObject(randomData, "Random weights");
         randomData.weights.Insert(index, 50);
     }
     newParent._children.Insert(index, node);
     node._parent = newParent;
 }
        private static InAudioEventNode CreateEvent(GameObject go, InAudioEventNode parent, int guid, EventNodeType type)
        {
            var node = go.AddComponentUndo <InAudioEventNode>();

            node._type = type;
            node._guid = guid;
            node.Name  = parent.Name + " Child";
            InUndoHelper.RecordObject(parent, "Parrent asign");
            node.AssignParent(parent);
            return(node);
        }
Esempio n. 12
0
        public static InAudioNode CreateChild(GameObject go, InAudioNode parent, AudioNodeType newNodeType)
        {
            InUndoHelper.RecordObject(InUndoHelper.Array(parent).Concat(parent.GetAuxData()).ToArray(), "Undo Node Creation");
            OnRandomNode(parent);

            var child = CreateNode(go, parent, GUIDCreator.Create(), newNodeType);

            parent.EditorSettings.IsFoldedOut = true;
            child.Name = parent.Name + " Child";
            AddDataClass(child);
            return(child);
        }
Esempio n. 13
0
        private static void HandleDragging(AudioEventAction currentAction, Rect dragArea)
        {
            if (currentAction != null)
            {
                if (currentAction is InEventAudioAction)
                {
                    InAudioNode dragged = OnDragging.DraggingObject <InAudioNode>(dragArea, node => node.IsPlayable);
                    if (dragged != null)
                    {
                        InUndoHelper.RecordObject(currentAction, "Change Action Type");
                        currentAction.Target = dragged;
                    }
                }
                else if (currentAction is InEventBankLoadingAction)
                {
                    InAudioBankLink dragged = OnDragging.DraggingObject <InAudioBankLink>(dragArea,
                                                                                          bank => bank._type == AudioBankTypes.Bank);

                    if (dragged != null)
                    {
                        InUndoHelper.RecordObject(currentAction, "Change Action Type");
                        currentAction.Target = dragged;
                    }
                }
                else if (currentAction is InEventMixerValueAction)
                {
                    AudioMixer dragged = OnDragging.DraggingObject <AudioMixer>(dragArea);
                    if (dragged != null)
                    {
                        InUndoHelper.RecordObject(currentAction, "Change Action Type");
                        currentAction.Target = dragged;
                    }
                }
                else if (currentAction is InEventMusicControl || currentAction is InEventMusicFade || currentAction is InEventSoloMuteMusic)
                {
                    InMusicGroup dragged = OnDragging.DraggingObject <InMusicGroup>(dragArea);
                    if (dragged != null)
                    {
                        InUndoHelper.RecordObject(currentAction, "Change Action Type");
                        currentAction.Target = dragged;
                    }
                }
            }
        }
Esempio n. 14
0
        public static InAudioNode CreateChild(GameObject go, InAudioNode parent, AudioNodeType newNodeType)
        {
            var bank = parent.GetBank();

            InUndoHelper.RecordObject(InUndoHelper.Array(parent, bank).Concat(parent.GetAuxData()).ToArray(), "Undo Node Creation");
            OnRandomNode(parent);

            var child = CreateNode(go, parent, GUIDCreator.Create(), newNodeType);

            parent.FoldedOut = true;
            child.Name       = parent.Name + " Child";
            var data = AddDataClass(child);

            if (newNodeType == AudioNodeType.Folder)
            {
                (data as InFolderData).BankLink = parent.GetBank();
            }
            return(child);
        }
Esempio n. 15
0
        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);
        }
Esempio n. 16
0
        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);
        }
Esempio n. 17
0
 public void ReceiveNode(InMusicGroup group)
 {
     if (SelectedNode != null)
     {
         InUndoHelper.DoInGroup(() =>
         {
             TreeWalker.ForEachParent(SelectedNode, n => n.EditorSettings.IsFoldedOut = true);
             InUndoHelper.RecordObject(SelectedNode, "Send to Event");
             if (SelectedNode.IsRootOrFolder)
             {
                 var myEvent             = AudioEventWorker.CreateNode(SelectedNode, EventNodeType.Event);
                 var myAction            = AudioEventWorker.AddEventAction <InEventMusicControl>(myEvent, EventActionTypes.PlayMusic);
                 myAction.Target         = group;
                 SelectedNode            = myEvent;
                 treeDrawer.SelectedNode = myEvent;
             }
             else
             {
                 var myAction    = AudioEventWorker.AddEventAction <InEventMusicControl>(SelectedNode, EventActionTypes.PlayMusic);
                 myAction.Target = group;
             }
         });
     }
 }
Esempio n. 18
0
        private static void ChangeAction(InAudioEventNode audioEvent, AudioEventAction action, EventActionTypes newEnumType)
        {
            for (int i = 0; i < audioEvent._actionList.Count; ++i)
            {
                if (audioEvent._actionList[i] == action)
                {
                    Type oldType = AudioEventAction.ActionEnumToType(action._eventActionType);
                    Type newType = AudioEventAction.ActionEnumToType(newEnumType);


                    if (oldType != newType)
                    {
                        InUndoHelper.DoInGroup(() => AudioEventWorker.ReplaceActionDestructiveAt(audioEvent, newEnumType, i));
                    }
                    else
                    {
                        InUndoHelper.RecordObject(action, "Change Event Action Type");
                        action._eventActionType = newEnumType;
                    }

                    break;
                }
            }
        }
 public void ReceiveNode(InAudioNode node)
 {
     if (SelectedNode != null)
     {
         InUndoHelper.DoInGroup(() =>
         {
             TreeWalker.ForEachParent(SelectedNode, n => n.FoldedOut = true);
             InUndoHelper.RecordObject(SelectedNode, "Send to Event");
             if (SelectedNode.IsRootOrFolder)
             {
                 var myEvent             = AudioEventWorker.CreateNode(SelectedNode, EventNodeType.Event);
                 var myAction            = AudioEventWorker.AddEventAction <InEventAudioAction>(myEvent, EventActionTypes.Play);
                 myAction.Target         = node;
                 SelectedNode            = myEvent;
                 treeDrawer.SelectedNode = myEvent;
             }
             else
             {
                 var myAction    = AudioEventWorker.AddEventAction <InEventAudioAction>(SelectedNode, EventActionTypes.Play);
                 myAction.Target = node;
             }
         });
     }
 }
Esempio n. 20
0
        protected override void OnDrop(InMusicNode newParent, UnityEngine.Object[] objects)
        {
            if (newParent == null || objects == null)
            {
                return;
            }

            var dragged = objects[0] as InMusicNode;

            if (dragged != null)
            {
                if (dragged.IsRoot || dragged == newParent)
                {
                    return;
                }

                InUndoHelper.DoInGroup(() =>
                {
                    if (dragged.gameObject != newParent.gameObject)
                    {
                        if (EditorUtility.DisplayDialog("Move?",
                                                        "Warning, this will break all external references to this and all child nodes!\n" +
                                                        "Move node from\"" + dragged.gameObject.name +
                                                        "\" to \"" + newParent.gameObject.name + "\"?", "Ok", "Cancel"))
                        {
                            treeDrawer.SelectedNode = TreeWalker.GetPreviousVisibleNode(treeDrawer.SelectedNode);
                            MusicWorker.Duplicate(newParent.gameObject, dragged, newParent);
                            DeleteNodeRec(dragged);
                            AudioBankWorker.RebuildBanks();
                        }
                    }
                    else
                    {
                        var oldParent = dragged._parent;
                        InUndoHelper.RecordObjects("Music drag-n-drop", dragged, oldParent, newParent);

                        dragged.MoveToNewParent(newParent);


                        newParent.IsFoldedOut = true;
                    }


                    Event.current.UseEvent();
                });
            }
            else if (newParent._type == MusicNodeType.Music)
            {
                var clips      = objects.Convert(o => o as AudioClip).TakeNonNulls();
                var musicGroup = newParent as InMusicGroup;
                if (musicGroup != null)
                {
                    InUndoHelper.DoInGroup(() =>
                    {
                        InUndoHelper.RecordObject(newParent, "Music Clip Add");
                        foreach (var audioClip in clips)
                        {
                            musicGroup._clips.Add(audioClip);
                        }
                    });
                }
            }
        }
Esempio n. 21
0
        public static void Draw(InMusicGroup node)
        {
            node.ScrollPosition = EditorGUILayout.BeginScrollView(node.ScrollPosition);
            var prop = new SerializedObject(node);

            prop.Update();

            EditorGUILayout.PropertyField(prop.FindProperty("_name"));


            if (!Application.isPlaying)
            {
                InUndoHelper.GUIUndo(node, "Volume", ref node._minVolume, () => EditorGUILayout.Slider("Initial Volume", node._minVolume, 0f, 1f));
            }
            else
            {
                InUndoHelper.GUIUndo(node, "Volume", ref node.runtimeVolume, () => EditorGUILayout.Slider("Current Volume", node.runtimeVolume, 0f, 1f));
            }

            if (!Application.isPlaying)
            {
                InUndoHelper.GUIUndo(node, "Pitch", ref node._minPitch, () => EditorGUILayout.Slider("Initial Pitch", node._minPitch, 0f, 3f));
            }
            else
            {
                InUndoHelper.GUIUndo(node, "Pitch", ref node.runtimePitch, () => EditorGUILayout.Slider("Current Pitch", node.runtimePitch, 0f, 3f));
            }
            EditorGUILayout.BeginHorizontal();
            if (Application.isPlaying)
            {
                GUILayout.FlexibleSpace();
                if (GUILayout.Button("Save volume & pitch"))
                {
                    InUndoHelper.RecordObject(node, "Volume & Pitch for Music");
                    node._minVolume = node.runtimeVolume;
                    node._minPitch  = node.runtimePitch;
                    Debug.Log("InAudio: Saved volume: " + node._minVolume + ", pitch: " + node._minPitch);
                }
            }
            EditorGUILayout.EndHorizontal();

            var playingInfo = node.PlayingInfo;

            if (playingInfo.Fading && Application.isPlaying)
            {
                EditorGUILayout.Slider("Volume target", playingInfo.TargetVolume, 0f, 1f);
                GUI.enabled = false;
                var duration = playingInfo.EndTime - playingInfo.StartTime;
                var left     = playingInfo.EndTime - Time.time;
                EditorGUILayout.Slider("Time elapsed", duration - left, 0, duration);
                GUI.enabled = true;
            }

            EditorGUILayout.PropertyField(prop.FindProperty("_loop"));

            EditorGUILayout.Separator();

            DataDrawerHelper.DrawMixer(node, prop.FindProperty("_mixerGroup"));
            EditorGUILayout.Separator();

            prop.ApplyModifiedProperties();

            if (!Application.isPlaying)
            {
                InUndoHelper.GUIUndo(node, "Mute", ref node._mute, () => EditorGUILayout.Toggle("Initial Mute", node._mute));
            }
            else
            {
                InUndoHelper.GUIUndo(node, "Mute", ref node.runtimeMute, () => EditorGUILayout.Toggle("Currently Mute", node.runtimeMute));
            }

            if (!Application.isPlaying)
            {
                InUndoHelper.GUIUndo(node, "Solo", ref node._solo, () => EditorGUILayout.Toggle("Initial Solo", node._solo));
            }
            else
            {
                InUndoHelper.GUIUndo(node, "Solo", ref node.runtimeSolo, () => EditorGUILayout.Toggle("Currently Solo", node.runtimeSolo));
            }

            EditorGUILayout.Separator();
            prop.Update();

            EditorGUILayout.LabelField("Clips in node");
            if (Application.isPlaying)
            {
                ReorderableListGUI.ListField(prop.FindProperty("_clips"), ReorderableListFlags.DisableDuplicateCommand | ReorderableListFlags.DisableContextMenu | ReorderableListFlags.DisableReordering | ReorderableListFlags.HideRemoveButtons);
                var rect = GUILayoutUtility.GetLastRect();
                for (int i = 0; i < node._clips.Count; i++)
                {
                    var progress = rect;
                    progress.height = 3;
                    progress.x     += 5;
                    progress.width -= 30;
                    progress.y     += i * 20 + 20;
                    //GUI.DrawTexture(progress, EditorResources.Background);
                    var item   = node._clips[i];
                    var player = node.PlayingInfo.Players.Find(s => s.clip == item);
                    if (player != null)
                    {
                        EditorGUI.DrawRect(progress, Color.white);
                        float pos = (float)player.ExactPosition();
                        if (node.PlayingInfo.State == MusicState.Playing || node.PlayingInfo.State == MusicState.Paused)
                        {
                            progress.width = progress.width * Mathf.Clamp01(pos / item.length);
                            EditorGUI.DrawRect(progress, Color.green);
                        }
                    }
                }
            }
            else
            {
                ReorderableListGUI.ListField(prop.FindProperty("_clips"), ReorderableListFlags.DisableDuplicateCommand);
            }

            prop.ApplyModifiedProperties();


            EditorGUILayout.Separator();
            if (node._children.Count > 0)
            {
                EditorGUILayout.LabelField("Child nodes");
                ReorderableListGUI.ListField(node._children, (position, item) =>
                {
                    EditorGUI.LabelField(position, item._name);
                    return(item);
                },
                                             ReorderableListFlags.DisableContextMenu | ReorderableListFlags.DisableReordering |
                                             ReorderableListFlags.HideAddButton | ReorderableListFlags.HideRemoveButtons);
            }
            EditorGUILayout.EndScrollView();
        }
Esempio n. 22
0
        //private static GameObject go;
        public static void Draw(InAudioNode node)
        {
            if (Application.isPlaying)
            {
                EditorGUILayout.BeginHorizontal();
                if (GUILayout.Button("Play Node"))
                {
                    if (preview != null)
                    {
                        preview.Stop();
                    }
                    preview = InAudio.Play(InAudioInstanceFinder.Instance.gameObject, node);
                    preview.SpatialBlend = 0.0f;
                    preview.OnCompleted  = (go, audioNode) => preview = null;
                }
                if (GUILayout.Button("Stop Playing Node") && preview != null)
                {
                    InAudio.StopAll(InAudioInstanceFinder.Instance.gameObject);
                }
                if (GUILayout.Button("Stop All Instances"))
                {
                    InAudio.StopAllOfNode(node);
                }
                EditorGUILayout.EndHorizontal();
            }

            InAudioNodeData baseData = (InAudioNodeData)node._nodeData;

            EditorGUILayout.Separator();

            DrawSelectedArea(node, baseData);

            Seperators(2);

            if (baseData.SelectedArea == 0)
            {
                EditorGUIHelper.DrawID(node._guid);

                #region Volume

                DataDrawerHelper.DrawVolume(baseData, ref baseData.MinVolume, ref baseData.MaxVolume, ref baseData.RandomVolume);
                #endregion

                Seperators(2);

                #region Parent pitch

                SetPitch(baseData);

                #endregion
                Seperators(2);
                #region Spatial blend

                SetSpatialBlend(baseData);

                #endregion

                Seperators(2);

                #region Delay

                GUILayout.BeginHorizontal();

                GUILayout.BeginVertical();

                InUndoHelper.GUIUndo(baseData, "Randomize Delay", ref baseData.RandomizeDelay, () =>
                                     EditorGUILayout.Toggle("Randomize Delay", baseData.RandomizeDelay));
                if (baseData.RandomizeDelay)
                {
                    InUndoHelper.GUIUndo(baseData, "Delay Change", ref baseData.InitialDelayMin, ref baseData.InitialDelayMax,
                                         (out float v1, out float v2) =>
                    {
                        v1 = Mathf.Clamp(EditorGUILayout.FloatField("Min delay", baseData.InitialDelayMin), 0, baseData.InitialDelayMax);
                        v2 = Mathf.Clamp(EditorGUILayout.FloatField("Max delay", baseData.InitialDelayMax), baseData.InitialDelayMin, float.MaxValue);
                    });
                }
                else
                {
                    InUndoHelper.GUIUndo(baseData, "Delay", ref baseData.InitialDelayMin, () =>
                    {
                        float delay = Mathf.Max(EditorGUILayout.FloatField("Initial delay", baseData.InitialDelayMin), 0);
                        if (delay > baseData.InitialDelayMax)
                        {
                            baseData.InitialDelayMax = baseData.InitialDelayMin + 0.001f;
                        }
                        return(delay);
                    });
                }

                GUILayout.EndVertical();

                GUILayout.BeginVertical();

                GUILayout.EndVertical();

                GUILayout.EndHorizontal();
                #endregion

                Seperators(2);

                #region Audio bus

                DataDrawerHelper.DrawMixer(node);

                #endregion

                Seperators(2);

                #region Loops

                GUI.enabled = true;
                GUILayout.BeginVertical();

                InUndoHelper.GUIUndo(baseData, "Use looping", ref baseData.Loop, () => EditorGUILayout.Toggle("Loop", baseData.Loop));
                if (baseData.Loop)
                {
                    GUI.enabled = baseData.Loop;

                    InUndoHelper.GUIUndo(baseData, "Loop Infinite", ref baseData.LoopInfinite,
                                         () => EditorGUILayout.Toggle("Loop Infinite", baseData.LoopInfinite));
                    if (baseData.Loop)
                    {
                        GUI.enabled = !baseData.LoopInfinite;
                    }

                    InUndoHelper.GUIUndo(baseData, "Loop Randomize", ref baseData.RandomizeLoops,
                                         () => EditorGUILayout.Toggle("Randomize Loop Count", baseData.RandomizeLoops));

                    if (!baseData.RandomizeLoops)
                    {
                        InUndoHelper.GUIUndo(baseData, "Loop Count",
                                             ref baseData.MinIterations, () => (byte)Mathf.Clamp(EditorGUILayout.IntField("Loop Count", baseData.MinIterations), 0, 255));
                    }
                    else
                    {
                        GUILayout.BeginHorizontal();
                        InUndoHelper.GUIUndo(baseData, "Loop Count", ref baseData.MinIterations, ref baseData.MaxIterations,
                                             (out byte v1, out byte v2) =>
                        {
                            v1 = (byte)Mathf.Clamp(EditorGUILayout.IntField("Min Loop Count", baseData.MinIterations), 0, 255);
                            v2 = (byte)Mathf.Clamp(EditorGUILayout.IntField("Max Loop Count", baseData.MaxIterations), 0, 255);

                            //Clamp to 0-255 and so that min/max doesn't overlap
                            v2 = (byte)Mathf.Clamp(v2, v1, 255);
                            v1 = (byte)Mathf.Clamp(v1, 0, v2);
                        });

                        GUILayout.EndHorizontal();
                    }
                }

                GUI.enabled = true;

                GUILayout.EndVertical();

                #endregion

                Seperators(2);

                #region Instance limiting
                InUndoHelper.GUIUndo(baseData, "Limit Instances (Global)", ref baseData.LimitInstances, () => EditorGUILayout.Toggle("Limit Instances", baseData.LimitInstances));
                GUI.enabled = baseData.LimitInstances;
                if (baseData.LimitInstances)
                {
                    InUndoHelper.GUIUndo(baseData, "Max Instance Cont", ref baseData.MaxInstances, () => Math.Max(EditorGUILayout.IntField("Max Instance Count", baseData.MaxInstances), 0));
                    InUndoHelper.GUIUndo(baseData, "Stealing Type", ref baseData.InstanceStealingTypes, () => (InstanceStealingTypes)EditorGUILayout.EnumPopup("Stealing Type", baseData.InstanceStealingTypes));
                }
                GUI.enabled = true;

                #endregion

                Seperators(2);

                #region Priority
                InUndoHelper.GUIUndo(baseData, "Priority", ref baseData.Priority, () => EditorGUILayout.IntSlider("Priority", baseData.Priority, 0, 255));
                #endregion

                Seperators(2);

                #region Sample offset
                InUndoHelper.GUIUndo(baseData, "Random Second Offset", ref baseData.RandomSecondsOffset, () =>
                                     EditorGUILayout.Toggle("Random Second Offset", baseData.RandomSecondsOffset));

                if (baseData.RandomSecondsOffset)
                {
                    InUndoHelper.GUIUndo(baseData, "First item offset", ref baseData.MinSecondsOffset, ref baseData.MaxSecondsOffset,
                                         (out float v1, out float v2) =>
                    {
                        v1 = Mathf.Clamp(EditorGUILayout.FloatField("Min offset", baseData.MinSecondsOffset), 0, baseData.MaxSecondsOffset);
                        v2 = Mathf.Clamp(EditorGUILayout.FloatField("Max offset", baseData.MaxSecondsOffset), baseData.MinSecondsOffset, float.MaxValue);
                    });
                }
                else
                {
                    InUndoHelper.GUIUndo(baseData, "Delay", ref baseData.MinSecondsOffset, () =>
                    {
                        var delay = Mathf.Max(EditorGUILayout.FloatField("First clip offset", baseData.MinSecondsOffset), 0);
                        if (delay > baseData.MaxSecondsOffset)
                        {
                            baseData.MaxSecondsOffset = baseData.MinSecondsOffset + 1;
                        }
                        return(delay);
                    });
                }

                if (node._type == AudioNodeType.Audio)
                {
                    var nodeData = node._nodeData as InAudioData;
                    if (nodeData.AudioClip != null)
                    {
                        float length = nodeData.AudioClip.ExactLength();
                        EditorGUILayout.BeginHorizontal();
                        EditorGUILayout.PrefixLabel("Clip length");
                        EditorGUILayout.SelectableLabel(length.ToString(), GUILayout.Height(EditorGUIUtility.singleLineHeight));
                        EditorGUILayout.EndHorizontal();
                        if (baseData.RandomSecondsOffset && (baseData.MinSecondsOffset > length || baseData.MaxSecondsOffset > length))
                        {
                            EditorGUILayout.HelpBox("Offset exceeds sound clip length", MessageType.Warning);
                        }
                        else if (baseData.MinSecondsOffset > length)
                        {
                            EditorGUILayout.HelpBox("Offset exceeds sound clip length", MessageType.Warning);
                        }
                    }
                }
                #endregion
            }
            else
            {
                #region Attenuation

                if (!node._parent.IsRootOrFolder)
                {
                    InUndoHelper.GUIUndo(baseData, "Override Parent", ref baseData.OverrideAttenuation, () => GUILayout.Toggle(baseData.OverrideAttenuation, "Override Parent"));
                }
                GUI.enabled = baseData.OverrideAttenuation;
                if (node._parent.IsRootOrFolder)
                {
                    GUI.enabled = true;
                }

                InUndoHelper.GUIUndo(node, "Rolloff Mode", ref baseData.RolloffMode, () => (AudioRolloffMode)EditorGUILayout.EnumPopup("Volume Rolloff", baseData.RolloffMode));

                InUndoHelper.GUIUndo(baseData, "Set Rolloff Distance", ref baseData.MinDistance, ref baseData.MaxDistance,
                                     (out float v1, out float v2) =>
                {
                    if (baseData.RolloffMode != AudioRolloffMode.Custom)
                    {
                        v1 = EditorGUILayout.FloatField("Min Distance", baseData.MinDistance);
                    }
                    else
                    {
                        v1 = baseData.MinDistance;
                    }
                    v2 = EditorGUILayout.FloatField("Max Distance", baseData.MaxDistance);
                    v1 = Mathf.Max(v1, 0.00001f);
                    v2 = Mathf.Max(v2, v1 + 0.01f);
                });



                if (baseData.RolloffMode == AudioRolloffMode.Custom)
                {
                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.PrefixLabel("Rolloff");

                    InUndoHelper.GUIUndo(baseData, "Set Rolloff Curve", ref baseData.FalloffCurve, () => EditorGUILayout.CurveField(baseData.FalloffCurve, GUILayout.Height(200), GUILayout.Width(200)));
                    //baseData.FalloffCurve = EditorGUILayout.CurveField(baseData.FalloffCurve, GUILayout.Height(200), GUILayout.Width(200));
                    EditorGUILayout.EndHorizontal();

                    var keys     = baseData.FalloffCurve.keys;
                    int keyCount = keys.Length;
                    for (int i = 0; i < keyCount; i++)
                    {
                        Keyframe key = keys[i];

                        key.time  = Mathf.Clamp01(key.time);
                        key.value = Mathf.Clamp01(key.value);
                        try
                        {
                            baseData.FalloffCurve.MoveKey(i, key);
                        }
                        catch (Exception)
                        {
                        }
                    }
                    if (GUILayout.Button("Reset curve", GUILayout.Width(150)))
                    {
                        InUndoHelper.RecordObject(baseData, "Reset Curve");
                        baseData.FalloffCurve = new AnimationCurve(new Keyframe(0, 1), new Keyframe(0.1f, 1), new Keyframe(1, 0));
                    }

                    if (Selection.activeObject == null)
                    {
                        EditorGUILayout.HelpBox("Please select any game object in the scene.\nIt fixes a bug in Unity Editor API",
                                                MessageType.Info, true);
                    }

                    EditorGUILayout.HelpBox("Unity does not support setting custom rolloff via scripts. This will perform slower than a log/linear rolloff curve", MessageType.Warning, true);
                    GUI.enabled = false;
                }

                #endregion

                GUI.enabled = true;
            }
        }
Esempio n. 23
0
        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
            {
                InUndoHelper.DoInGroup(() =>
                {
                    node.IsFoldedOut = true;
                    var nodeToMove   = objects[0] as InAudioNode;

                    if (node.gameObject != nodeToMove.gameObject)
                    {
                        if (EditorUtility.DisplayDialog("Move?",
                                                        "Warning, this will break all external references to this and all child nodes!\n" +
                                                        "Move node from\"" + nodeToMove.gameObject.name +
                                                        "\" to \"" + node.gameObject.name + "\"?", "Ok", "Cancel"))
                        {
                            treeDrawer.SelectedNode = treeDrawer.SelectedNode._getParent;
                            isDirty = false;
                            AudioNodeWorker.CopyTo(nodeToMove, node);
                            AudioNodeWorker.DeleteNodeNoGroup(nodeToMove);
                        }
                    }
                    else
                    {
                        MoveNode(node, nodeToMove);
                    }
                });
            }
            else if (node._type != AudioNodeType.Audio) //Create new audio nodes when we drop clips
            {
                InUndoHelper.DoInGroup(() =>
                {
                    InUndoHelper.RecordObject(InUndoHelper.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";
                        }

                        var audioData   = (child._nodeData as InAudioData);
                        audioData._clip = clip;

                        AudioBankWorker.AddNodeToBank(child);
                        Event.current.UseEvent();
                    }
                });
            }
            else //Then it must be an audio clip dropped on an audio node, so assign the clip to that node
            {
                InUndoHelper.DoInGroup(() =>
                {
                    var nodeData = (node._nodeData as InAudioData);
                    if (nodeData != null)
                    {
                        InUndoHelper.RecordObject(InUndoHelper.NodeUndo(node), "Change Audio Clip In " + node.Name);
                        nodeData._clip = objects[0] as AudioClip;
                    }
                });
                Event.current.UseEvent();
            }
        }
Esempio n. 24
0
 private void UndoAll(string message)
 {
     InUndoHelper.RecordObject(
         SplineController.Nodes.Cast <Object>().ToArray().Add(SplineController), message);
 }
Esempio n. 25
0
        public override void OnInspectorGUI()
        {
            if (!InAudioInstanceFinder.IsValid)
            {
                EditorGUILayout.HelpBox("Please add the InAudio Manager to the scene", MessageType.Info);
                if (GUILayout.Button("Add manager to scene"))
                {
                    ErrorDrawer.AddManagerToScene();
                }
            }


            serializedObject.Update();
            EditorGUI.BeginChangeCheck();
            if (serializedObject.FindProperty("SplineController").hasMultipleDifferentValues)
            {
                EditorGUILayout.HelpBox("Different spline controllers", MessageType.Warning);
                return;
            }
            if (SplineNode.SplineController == null)
            {
                EditorGUILayout.HelpBox("Missing spline controller, please assign one", MessageType.Warning);
            }

            if (InAudioInstanceFinder.IsValid)
            {
                InAudioInstanceFinder.InAudioGuiUserPrefs.SelectedSplineController = SplineNode.SplineController;
            }

            bool add       = GUILayout.Button("Add Node");
            bool selectNew = false;

            if (GUILayout.Button("Add and Select"))
            {
                add       = true;
                selectNew = true;
            }
            EditorGUILayout.Separator();


            var objectField = EditorGUILayout.ObjectField("Controlling Spline", serializedObject.FindProperty("SplineController").objectReferenceValue, typeof(InSpline), true);

            if (serializedObject.FindProperty("SplineController").objectReferenceValue == null)
            {
                serializedObject.FindProperty("SplineController").objectReferenceValue = objectField;
            }

            if (Selection.objects.Length == 1)
            {
                GUILayout.Button("Drag node here to connect");
                OnDragging.DraggingObject <Object>(GUILayoutUtility.GetLastRect(), o =>
                {
                    GameObject go = o as GameObject;
                    if (go != null)
                    {
                        var node = go.GetComponent <InSplineNode>();
                        if (node != SplineNode && !SplineNode.SplineController.ContainsConnection(SplineNode, node))
                        {
                            return(true);
                        }
                    }
                    return(false);
                }, o =>
                {
                    InUndoHelper.RecordObject(SplineNode.SplineController, "Connect nodes");
                    (o as GameObject).GetComponent <InSplineNode>().ConnectTo(SplineNode);
                });

                //var a = new SerializedObject(SplineNode.SplineController)
                if (SplineNode.SplineController != null)
                {
                    expandedConnections = EditorGUILayout.Foldout(expandedConnections, "Connected to");

                    for (int i = 0; i < SplineNode.SplineController.Connections.Count; i++)
                    {
                        EditorGUILayout.BeginHorizontal();
                        GUI.enabled = false;
                        var conc = SplineNode.SplineController.Connections[i];
                        if (conc.NodeA == SplineNode)
                        {
                            EditorGUILayout.ObjectField(conc.NodeB, typeof(InSplineNode), true);
                            GUI.enabled = true;
                            if (GUILayout.Button("X", GUILayout.Width(20)))
                            {
                                InUndoHelper.RecordObject(SplineNode.SplineController, "Remove spline connection");
                                SplineNode.SplineController.RemoveConnections(conc);
                            }
                            EditorUtility.SetDirty(SplineNode.SplineController);
                        }
                        else if (conc.NodeB == SplineNode)
                        {
                            EditorGUILayout.ObjectField(conc.NodeA, typeof(InSplineNode), true);
                            GUI.enabled = true;
                            if (GUILayout.Button("X", GUILayout.Width(20)))
                            {
                                InUndoHelper.RecordObject(SplineNode.SplineController, "Remove spline connection");
                                SplineNode.SplineController.RemoveConnections(conc);
                            }
                            EditorUtility.SetDirty(SplineNode.SplineController);
                        }


                        EditorGUILayout.EndHorizontal();
                    }
                }
            }



            EditorGUILayout.Separator();
            bool delete = true;

            if (GUILayout.Button("Delete"))
            {
                InUndoHelper.DoInGroup(() =>
                {
            #if UNITY_4_1 || UNITY_4_2
                    Undo.RegisterSceneUndo("Combine nodes");
            #else
                    UndoAll("Delete node");
            #endif
                    foreach (var gameObject in Selection.gameObjects)
                    {
                        InUndoHelper.Destroy(gameObject);
                    }

                    delete = true;
                });
            }


            if (add)
            {
                InUndoHelper.DoInGroup(() =>
                {
                #if UNITY_4_1 || UNITY_4_2
                    Undo.RegisterSceneUndo("Delete element in spline");
                #else
                    UndoAll("Add new spline node");
                #endif

                    GameObject go         = InUndoHelper.CreateGO(SplineNode.SplineController.gameObject.name + " Node");
                    go.transform.parent   = SplineNode.SplineController.transform;
                    go.transform.position = SplineNode.transform.position + SplineNode.transform.forward;
                    go.transform.position = SplineNode.transform.position;

                    var newNode = go.AddComponent <InSplineNode>();
                    newNode.SplineController = SplineNode.SplineController;
                    newNode.ConnectTo(SplineNode);
                    SplineNode.SplineController.Nodes.Add(newNode);

                    if (selectNew)
                    {
                        Selection.activeGameObject = go;
                    }
                });
            }

            if (EditorGUI.EndChangeCheck() && delete == false)
            {
                serializedObject.ApplyModifiedProperties();
            }
        }