Пример #1
0
        public static void Duplicate(InAudioNode audioNode)
        {
            InUndoHelper.DoInGroup(() =>
            {
                List <Object> toUndo = new List <Object>(AudioBankWorker.GetAllBanks().ConvertAll(b => b as Object));

                toUndo.Add(audioNode._parent);
                toUndo.AddRange(audioNode._parent.GetAuxData());
                toUndo.Add(audioNode.GetBank());

                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);
                    }
                });
            });
        }
Пример #2
0
        public static void Duplicate(InAudioNode audioNode)
        {
            UndoHelper.DoInGroup(() =>
            {
                List <Object> toUndo = TreeWalker.FindAll(audioNode, node => node.GetBank().LazyBankFetch).ConvertList <InAudioBank, Object>();

                toUndo.Add(audioNode.Parent);
                toUndo.Add(audioNode.GetBank());

                UndoHelper.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)
                    {
                        Type type        = oldNode.NodeData.GetType();
                        newNode.NodeData = gameObject.AddComponentUndo(type) as InAudioNodeBaseData;
                        EditorUtility.CopySerialized(oldNode.NodeData, newNode.NodeData);
                        if (newNode.Type == AudioNodeType.Audio)
                        {
                            AudioBankWorker.AddNodeToBank(newNode, (oldNode.NodeData as InAudioData).EditorClip);
                        }
                    }
                });
            });
        }
Пример #3
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);
        }
Пример #4
0
        public static InAudioNode CreateChild(InAudioNode parent, AudioNodeType newNodeType)
        {
            var bank = parent.GetBank();

            UndoHelper.RecordObject(UndoHelper.Array(parent, parent.NodeData, bank != null ? bank.LazyBankFetch : null), "Undo Node Creation");
            OnRandomNode(parent);

            var child = CreateNode(parent.gameObject, 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);
        }
Пример #5
0
        public static Object[] NodeUndo(InAudioNode node)
        {
            var bank = node.GetBank();

            return(new Object[]
            {
                node,
                node.NodeData,
                bank != null ? bank.LazyBankFetch : null
            });
        }
Пример #6
0
        public static void RemoveNodeFromBank(InAudioNode node)
        {
            var bankLink = node.GetBank();

            if (bankLink != null)
            {
                InUndoHelper.RecordObjectFull(bankLink, "Node from bank removal");
                var bank = bankLink._bankData;
                bank.RemoveAll(b => b.AudioNode == node);
            }
        }
Пример #7
0
        public static Object[] NodeUndo(InAudioNode node)
        {
            var bank = node.GetBank();

            return(new Object[]
            {
                node,
                node._nodeData,
                bank
            });
        }
Пример #8
0
        public static void RemoveNodeFromBank(InAudioNode node)
        {
            var bankLink = node.GetBank();

            if (bankLink != null)
            {
                var bank = bankLink.LazyBankFetch;
                UndoHelper.RecordObjectFull(bank, "Node from bank removal");
                bank.Clips.RemoveAll(p => p.Node == node);
            }
        }
Пример #9
0
 public static void AddNodeToBank(InAudioNode node)
 {
     var bank = node.GetBank();
     if (bank != null)
     {
         bank._bankData.Add(CreateBankDataItem(node));
         EditorUtility.SetDirty(bank);
     }
     else
     {
         Debug.LogError("InAudio: Could not add node to bank as bank could not be found");
     }
 }
Пример #10
0
 private static void SetBanks(InAudioNode node)
 {
     if (node.IsRootOrFolder)
     {
         InFolderData inFolderData = (node.NodeData as InFolderData);
         if (inFolderData != null)
         {
             if (inFolderData.BankLink == null)
             {
                 inFolderData.BankLink = node.GetBank();
             }
         }
     }
 }
Пример #11
0
        public static void AddNodeToBank(InAudioNode node)
        {
            var bank = node.GetBank();

            if (bank != null)
            {
                bank._bankData.Add(CreateBankDataItem(node));
                EditorUtility.SetDirty(bank);
            }
            else
            {
                Debug.LogError("InAudio: Could not add node to bank as bank could not be found");
            }
        }
Пример #12
0
        public static bool SwapClipInBank(InAudioNode node, AudioClip newClip)
        {
            var bank = node.GetBank();

            var clipTuple = bank.LazyBankFetch.Clips;

            for (int i = 0; i < clipTuple.Count; i++)
            {
                if (clipTuple[i].Node == node)
                {
                    clipTuple[i].Clip = newClip;

                    return(true);
                }
            }
            return(false);
        }
Пример #13
0
        public static void AddNodeToBank(InAudioNode node, AudioClip clip)
        {
            var bank = node.GetBank();

            if (bank != null)
            {
                if (bank.LazyBankFetch == null)
                {
                    Debug.LogError("Please open the InAudio Integrity window and \"Fix Bank integrity\"\n"
                                   + "Bank " + bank.Name + " with id " + bank.ID + " does not have an attached bank storage.\n");
                }
                else
                {
                    bank.LazyBankFetch.Clips.Add(CreateTuple(node, clip));
                    EditorUtility.SetDirty(bank.LazyBankFetch);
                }
            }
        }
Пример #14
0
        public static void CopyTo(InAudioNode audioNode, InAudioNode newParent)
        {
            List <Object> toUndo = new List <Object>(AudioBankWorker.GetAllBanks().ConvertAll(b => b as Object));

            toUndo.Add(audioNode._parent);
            toUndo.AddRange(audioNode._parent.GetAuxData());
            toUndo.Add(audioNode.GetBank());

            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);
                }
            });
        }
Пример #15
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);
        }
Пример #16
0
        //private static GameObject go;
        public static void Draw(InAudioNode node)
        {
            if (Application.isPlaying)
            {
                EditorGUILayout.BeginHorizontal();
                if (GUILayout.Button("Play Node"))
                {
                    var link = node.GetBank();
                    if (link != null && link.IsLoaded)
                    {
                        if (preview != null)
                        {
                            preview.Stop();
                        }
                        preview             = InAudio.Play(InAudioInstanceFinder.Instance.gameObject, node);
                        preview.Pan         = 0.0f;
                        preview.OnCompleted = (go, audioNode) => preview = null;
                    }
                    else
                    {
                        Debug.Log("InAudio: Cannot preview node as its beloning bank is not loaded");
                    }
                }
                if (GUILayout.Button("Stop Playing Node") && preview != null)
                {
                    preview.Stop();
                }
                EditorGUILayout.EndHorizontal();
            }

            InAudioNodeData baseData = (InAudioNodeData)node.NodeData;

            EditorGUILayout.Separator();

            DrawSelectedArea(node, baseData);

            Seperators(2);

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

                #region Volume

                UndoHelper.GUIUndo(baseData, "Random Volume", ref baseData.RandomVolume, () =>
                                   EditorGUILayout.Toggle("Random Volume", baseData.RandomVolume));

                if (!baseData.RandomVolume)
                {
                    UndoHelper.GUIUndo(baseData, "Volume", () =>
                                       EditorGUILayout.Slider("Volume", baseData.MinVolume, 0, 1),
                                       v =>
                    {
                        baseData.MinVolume = v;
                        if (baseData.MinVolume > baseData.MaxVolume)
                        {
                            baseData.MaxVolume = baseData.MinVolume + 0.1f;
                        }
                    });
                }
                else
                {
                    UndoHelper.GUIUndo(baseData, "Random Volume", ref baseData.MinVolume, ref baseData.MaxVolume, (out float minVolume, out float maxVolume) =>
                    {
                        EditorGUILayout.MinMaxSlider(new GUIContent("Volume"), ref baseData.MinVolume, ref baseData.MaxVolume, 0, 1);
                        minVolume = Mathf.Clamp(EditorGUILayout.FloatField("Min volume", baseData.MinVolume), 0, baseData.MaxVolume);
                        maxVolume = Mathf.Clamp(EditorGUILayout.FloatField("Max volume", baseData.MaxVolume), baseData.MinVolume, 1);
                    });
                }
                #endregion

                Seperators(2);

                #region Parent pitch

                float minPitch = 0.001f;
                float maxPitch = 3;
                UndoHelper.GUIUndo(baseData, "Random Pitch", ref baseData.RandomPitch, () =>
                                   EditorGUILayout.Toggle("Random Pitch", baseData.RandomPitch));

                if (!baseData.RandomPitch)
                {
                    UndoHelper.GUIUndo(baseData, "Pitch", () =>
                                       EditorGUILayout.Slider("Pitch", baseData.MinPitch, minPitch, maxPitch),
                                       v => {
                        baseData.MinPitch = v;
                        if (baseData.MinPitch > baseData.MaxPitch)
                        {
                            baseData.MaxPitch = baseData.MinPitch + 0.1f;
                        }
                        baseData.MaxPitch = Mathf.Clamp(baseData.MaxPitch, minPitch, 3.0f);
                    });
                }
                else
                {
                    UndoHelper.GUIUndo(baseData, "Random Pitch",
                                       ref baseData.MinPitch, ref baseData.MaxPitch,
                                       (out float v1, out float v2) => {
                        EditorGUILayout.MinMaxSlider(new GUIContent("Pitch"), ref baseData.MinPitch, ref baseData.MaxPitch, minPitch, maxPitch);
                        v1 = Mathf.Clamp(EditorGUILayout.FloatField("Min pitch", baseData.MinPitch), minPitch, baseData.MaxPitch);
                        v2 = Mathf.Clamp(EditorGUILayout.FloatField("Max pitch", baseData.MaxPitch), baseData.MinPitch, maxPitch);
                    });
                }

                #endregion

                Seperators(2);

                #region Delay

                GUILayout.BeginHorizontal();

                GUILayout.BeginVertical();

                UndoHelper.GUIUndo(baseData, "Randomize Delay", ref baseData.RandomizeDelay, () =>
                                   EditorGUILayout.Toggle("Randomize Delay", baseData.RandomizeDelay));
                if (baseData.RandomizeDelay)
                {
                    UndoHelper.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
                {
                    UndoHelper.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.DrawBus(node);

                #endregion

                Seperators(2);

                #region Loops

                GUILayout.BeginVertical();

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

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

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

                    if (!baseData.RandomizeLoops)
                    {
                        UndoHelper.GUIUndo(baseData, "Loop Count",
                                           ref baseData.MinIterations, () => (byte)Mathf.Clamp(EditorGUILayout.IntField("Loop Count", baseData.MinIterations), 0, 255));
                    }
                    else
                    {
                        GUILayout.BeginHorizontal();
                        UndoHelper.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
                UndoHelper.GUIUndo(baseData, "Limit Instances (Global)", ref baseData.LimitInstances, () => EditorGUILayout.Toggle("Limit Instances", baseData.LimitInstances));
                GUI.enabled = baseData.LimitInstances;
                if (baseData.LimitInstances)
                {
                    UndoHelper.GUIUndo(baseData, "Max Instance Cont", ref baseData.MaxInstances, () => Math.Max(EditorGUILayout.IntField("Max Instance Count", baseData.MaxInstances), 0));
                    UndoHelper.GUIUndo(baseData, "Stealing Type", ref baseData.InstanceStealingTypes, () => (InstanceStealingTypes)EditorGUILayout.EnumPopup("Stealing Type", baseData.InstanceStealingTypes));
                }
                GUI.enabled = true;

                #endregion

                Seperators(2);

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

                Seperators(2);

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

                if (baseData.RandomSecondsOffset)
                {
                    UndoHelper.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
                {
                    UndoHelper.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.EditorClip != null)
                    {
                        float length = nodeData.EditorClip.ExactLength();
                        EditorGUILayout.BeginHorizontal();
                        EditorGUILayout.PrefixLabel("Clip length");
                        EditorGUILayout.SelectableLabel(length.ToString(), GUILayout.Height(20));
                        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)
                {
                    UndoHelper.GUIUndo(baseData, "Override Parent", ref baseData.OverrideAttenuation, () => GUILayout.Toggle(baseData.OverrideAttenuation, "Override Parent"));
                }
                GUI.enabled = baseData.OverrideAttenuation;
                if (node.Parent.IsRootOrFolder)
                {
                    GUI.enabled = true;
                }

                bool dirty = false;
                UndoHelper.GUIUndo(node, "Rolloff Mode", ref baseData.RolloffMode, () =>
                {
                    dirty = true;
                    return((AudioRolloffMode)EditorGUILayout.EnumPopup("Volume Rolloff", baseData.RolloffMode));
                });

                UndoHelper.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);

                    dirty = true;
                });



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

                    UndoHelper.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.Clamp(key.time, 0.0f, 1.0f);
                        key.value = Mathf.Clamp(key.value, 0.0f, 1.0f);
                        try
                        {
                            baseData.FalloffCurve.MoveKey(i, key);
                        }
                        catch (Exception)
                        {
                        }
                    }
                    if (GUILayout.Button("Reset curve", GUILayout.Width(150)))
                    {
                        UndoHelper.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;
                }


                if (dirty && Application.isPlaying)
                {
                    UpdateDateRuntime.Update(node.GetBus(), node);
                }

                #endregion

                GUI.enabled = true;
            }
        }
Пример #17
0
 public static void RemoveNodeFromBank(InAudioNode node)
 {
     var bankLink = node.GetBank();
     if (bankLink != null)
     {
         InUndoHelper.RecordObjectFull(bankLink, "Node from bank removal");
         var bank = bankLink._bankData;
         bank.RemoveAll(b => b.AudioNode == node);
     }
 }
Пример #18
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);
        }
Пример #19
0
        public static void CopyTo(InAudioNode audioNode, InAudioNode newParent)
        {
            List<Object> toUndo = new List<Object>(AudioBankWorker.GetAllBanks().ConvertAll(b => b as Object));

            toUndo.Add(audioNode._parent);
            toUndo.AddRange(audioNode._parent.GetAuxData());
            toUndo.Add(audioNode.GetBank());

            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);
                }
            });
        }
Пример #20
0
 private static void SetBanks(InAudioNode node)
   {
       if(node.IsRootOrFolder)
       {
           InFolderData inFolderData = (node._nodeData as InFolderData);
           if(inFolderData != null)
           {
               if (inFolderData.BankLink == null)
                   inFolderData.BankLink = node.GetBank();
           }
       }
   }
Пример #21
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;
        }
Пример #22
0
        public static void Duplicate(InAudioNode audioNode)
        {
            InUndoHelper.DoInGroup(() =>
            {
                List<Object> toUndo = new List<Object>(AudioBankWorker.GetAllBanks().ConvertAll(b => b as Object));

                toUndo.Add(audioNode._parent);
                toUndo.AddRange(audioNode._parent.GetAuxData());
                toUndo.Add(audioNode.GetBank());

                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);
                    }
                });
            });
        }
Пример #23
0
        public static void Draw(InAudioNode node)
        {
            UndoHelper.GUIUndo(node, "Name Change", ref node.Name, () =>
                               EditorGUILayout.TextField("Name", node.Name));

            Rect area = GUILayoutUtility.GetLastRect();

            EditorGUILayout.Separator();
            EditorGUILayout.BeginHorizontal();
            InAudioData audioData = node.NodeData as InAudioData;

            EditorGUILayout.BeginVertical();
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("");
            area = GUILayoutUtility.GetLastRect();
            Rect objectArea = area;

            if (Application.isPlaying)
            {
                objectArea.width -= 100;
            }
            var  clip       = (AudioClip)EditorGUI.ObjectField(objectArea, audioData.EditorClip, typeof(AudioClip), false);
            Rect buttonArea = area;

            if (Application.isPlaying)
            {
                buttonArea.x    += buttonArea.width - 100;
                buttonArea.width = 70;
                GUI.enabled      = false;
                EditorGUI.LabelField(buttonArea, "Is Loaded");
                buttonArea.x    += 70;
                buttonArea.width = 10;
                EditorGUI.Toggle(buttonArea, audioData.RuntimeClip != null);
                GUI.enabled = true;
            }



            if (GUILayout.Button("Preview", GUILayout.Width(60)))
            {
                AudioSource source = InAudioInstanceFinder.Instance.GetComponent <AudioSource>();
                var         root   = TreeWalker.FindParentBeforeFolder(node);
                source.volume = RuntimeHelper.ApplyVolume(root, node);
                source.pitch  = RuntimeHelper.ApplyPitch(root, node);
                source.clip   = audioData.EditorClip;
                source.Play();
            }

            if (GUILayout.Button("Raw", GUILayout.Width(45)))
            {
                AudioSource source = InAudioInstanceFinder.Instance.GetComponent <AudioSource>();
                source.clip   = audioData.EditorClip;
                source.volume = 1.0f;
                source.pitch  = 1.0f;
                source.Play();
            }

            if (GUILayout.Button("Stop", GUILayout.Width(45)))
            {
                AudioSource source = InAudioInstanceFinder.Instance.GetComponent <AudioSource>();
                source.Stop();
                source.clip = null;
            }


            EditorGUILayout.EndHorizontal();

            EditorGUILayout.EndVertical();

            if (audioData.RuntimeClip != null && Application.isPlaying)
            {
                audioData.RuntimeClip = clip;
            }

            if (clip != audioData.EditorClip) //Assign new clip
            {
                UndoHelper.RecordObjectFull(new Object[] { audioData, node.GetBank().LazyBankFetch }, "Changed " + node.Name + " Clip");
                audioData.EditorClip  = clip;
                audioData.RuntimeClip = clip;
                AudioBankWorker.SwapClipInBank(node, clip);

                EditorUtility.SetDirty(node.GetBank().LazyBankFetch.gameObject);
                EditorUtility.SetDirty(node.NodeData.gameObject);
            }

            EditorGUILayout.EndHorizontal();

            NodeTypeDataDrawer.Draw(node);
        }
Пример #24
0
    //private static GameObject go;
    public static void Draw(InAudioNode node)
    {
        if (Application.isPlaying)
        {
            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button("Play Node"))
            {
                var link = node.GetBank();
                if (link != null && link.IsLoaded)
                {
                    if (preview != null)
                    {
                        preview.Stop();
                    }
                    preview = InAudio.Play(InAudioInstanceFinder.Instance.gameObject, node);
                    preview.SpatialBlend = 0.0f;
                    preview.OnCompleted = (go, audioNode) => preview = null;
                }
                else
                {
                    Debug.Log("InAudio: Cannot preview node as its beloning bank is not loaded");
                }
            }
            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._clip != null)
                    {
                        float length = nodeData._clip.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;
        }
    }