Esempio n. 1
0
    public static bool Draw(InAudioEventNode audioevent)
    {
        if (ListAdapter == null)
        {
            ListAdapter = new EventActionListAdapter();
            ListAdapter.DrawEvent = DrawItem;
            ListAdapter.ClickedInArea = ClickedInArea;
        }

        if (lastEvent != audioevent)
        {
            ListAdapter.Event = audioevent;

            audioEventAction = null;
            if (audioevent._actionList.Count > 0)
            {
                audioEventAction = audioevent._actionList[0];
            }
        }
        EditorGUILayout.BeginVertical();

        lastEvent = audioevent;
        InUndoHelper.GUIUndo(audioevent, "Name Change", ref audioevent.Name, () => 
            EditorGUILayout.TextField("Name", audioevent.Name));
        
        bool repaint = false;
      
        if (audioevent._type == EventNodeType.Event)
        {
            EditorGUIHelper.DrawID(audioevent._guid);

            if (Application.isPlaying)
            {
                eventObjectTarget = EditorGUILayout.ObjectField("Event preview target", eventObjectTarget, typeof(GameObject), true) as GameObject;
                
                if (eventObjectTarget != null )
                {
                    bool prefab = PrefabUtility.GetPrefabParent(eventObjectTarget) == null && PrefabUtility.GetPrefabObject(eventObjectTarget) != null;
                    if (!prefab)
                    {
                        EditorGUILayout.BeginHorizontal();
                        if (GUILayout.Button("Post event"))
                        {
                            InAudio.PostEvent(eventObjectTarget, audioevent);
                        }
                        if (GUILayout.Button("Stop All Sounds/Music in Event"))
                        {
                            InAudio.StopAll(eventObjectTarget);
                            foreach (var eventAction in audioevent._actionList)
                            {
                                var music = eventAction.Target as InMusicGroup;
                                if (music != null)
                                {
                                    InAudio.Music.Stop(music);
                                }
                            }
                        }
                        EditorGUILayout.EndHorizontal();
                    }
                    else
                    {
                        EditorGUILayout.HelpBox("Cannot post events on Prefab", MessageType.Error);
                    }
                }
                EditorGUILayout.Separator();
            }

            

            InUndoHelper.GUIUndo(audioevent, "Delay", ref audioevent.Delay, () =>
                Mathf.Max(EditorGUILayout.FloatField("Delay", audioevent.Delay), 0));
          
            NewEventArea(audioevent);

            EditorGUILayout.Separator();
            EditorGUILayout.Separator();

            scrollPos = EditorGUILayout.BeginScrollView(scrollPos);

                repaint = DrawContent();

            EditorGUILayout.EndScrollView();
            DrawSelected(audioEventAction);
        }
        else if (audioevent._type == EventNodeType.Folder)
        {
            if (audioevent.PlacedExternaly)
            {
                EditorGUILayout.Separator();

                GUI.enabled = false;
                EditorGUILayout.ObjectField("Placed on", audioevent.gameObject, typeof(GameObject), false);
                GUI.enabled = true;

                EditorGUILayout.Separator();
            }
        }

        EditorGUILayout.EndVertical(); 

        if (toRemove != null)
        {
            InUndoHelper.DoInGroup(() =>
            {
                //Remove the required piece
                int index = audioevent._actionList.FindIndex(toRemove);
                AudioEventWorker.DeleteActionAtIndex(audioevent, index);
                
            });
            toRemove = null;

        }
        else //Remove all actions that does not excist. 
        {
            audioevent._actionList.RemoveAll(p => p == null);
        }
        return repaint;
    }
Esempio n. 2
0
        public static bool Draw(InAudioEventNode audioevent)
        {
            if (ListAdapter == null)
            {
                ListAdapter               = new EventActionListAdapter();
                ListAdapter.DrawEvent     = DrawItem;
                ListAdapter.ClickedInArea = ClickedInArea;
            }

            if (lastEvent != audioevent)
            {
                ListAdapter.Event = audioevent;

                audioEventAction = null;
                if (audioevent._actionList.Count > 0)
                {
                    audioEventAction = audioevent._actionList[0];
                }
            }
            EditorGUILayout.BeginVertical();

            lastEvent = audioevent;
            InUndoHelper.GUIUndo(audioevent, "Name Change", ref audioevent.Name, () =>
                                 EditorGUILayout.TextField("Name", audioevent.Name));

            bool repaint = false;

            if (audioevent._type == EventNodeType.Event)
            {
                EditorGUIHelper.DrawID(audioevent._guid);

                if (Application.isPlaying)
                {
                    eventObjectTarget = EditorGUILayout.ObjectField("Event preview target", eventObjectTarget, typeof(GameObject), true) as GameObject;

                    if (eventObjectTarget != null)
                    {
                        bool prefab = PrefabUtility.GetPrefabParent(eventObjectTarget) == null && PrefabUtility.GetPrefabObject(eventObjectTarget) != null;
                        if (!prefab)
                        {
                            EditorGUILayout.BeginHorizontal();
                            if (GUILayout.Button("Post event"))
                            {
                                InAudio.PostEvent(eventObjectTarget, audioevent);
                            }
                            if (GUILayout.Button("Stop All Sounds/Music in Event"))
                            {
                                InAudio.StopAll(eventObjectTarget);
                                foreach (var eventAction in audioevent._actionList)
                                {
                                    var music = eventAction.Target as InMusicGroup;
                                    if (music != null)
                                    {
                                        InAudio.Music.Stop(music);
                                    }
                                }
                            }
                            EditorGUILayout.EndHorizontal();
                        }
                        else
                        {
                            EditorGUILayout.HelpBox("Cannot post events on Prefab", MessageType.Error);
                        }
                    }
                    EditorGUILayout.Separator();
                }



                InUndoHelper.GUIUndo(audioevent, "Delay", ref audioevent.Delay, () =>
                                     Mathf.Max(EditorGUILayout.FloatField("Delay", audioevent.Delay), 0));

                NewEventArea(audioevent);

                EditorGUILayout.Separator();
                EditorGUILayout.Separator();

                scrollPos = EditorGUILayout.BeginScrollView(scrollPos);

                repaint = DrawContent();

                EditorGUILayout.EndScrollView();
                DrawSelected(audioEventAction);
            }
            else if (audioevent._type == EventNodeType.Folder)
            {
                if (audioevent.PlacedExternaly)
                {
                    EditorGUILayout.Separator();

                    GUI.enabled = false;
                    EditorGUILayout.ObjectField("Placed on", audioevent.gameObject, typeof(GameObject), false);
                    GUI.enabled = true;

                    EditorGUILayout.Separator();
                }
            }

            EditorGUILayout.EndVertical();

            if (toRemove != null)
            {
                InUndoHelper.DoInGroup(() =>
                {
                    //Remove the required piece
                    int index = audioevent._actionList.FindIndex(toRemove);
                    AudioEventWorker.DeleteActionAtIndex(audioevent, index);
                });
                toRemove = null;
            }
            else //Remove all actions that does not excist.
            {
                audioevent._actionList.RemoveAll(p => p == null);
            }
            return(repaint);
        }