[패스트캠퍼스 수강 후기] 올인원 패키지 : 유니티 포트폴리오 완성 100% 환급 챌린지 37회차 미션 시작합니다.

04. 배틀로얄 - 19, 20 번을 진행합니다.




드디어 SoundTool입니다 ^^~

EffectTool과 비교한다면 속성 및 설정값이 많기에 조금 복잡해 보이는 코드가 되기 하겠지만 핵심적인 내용은 비슷하므로 천천히 따라가면 충분히 이해할 수 있습니다.




해당 위치에 SoundTool Script를 생성하고 코드 작업을 시작합니다.


public class SoundTool : EditorWindow
{
    public int uiWidthLarge = 450;
    public int uiWidthMiddle = 300;
    public int uiWidthSmall = 200;
    private int selection = 0;
    private Vector2 SP1 = Vector2.zero;
    private Vector2 SP2 = Vector2.zero;
    private AudioClip soundSource;
    private static SoundData soundData;
    
    [MenuItem("Tools/Sound Tool")]
    static void Init() {
        soundData = CreateInstance<SoundData>();
        soundData.LoadData();
        
        SoundTool window = GetWindow<SoundTool>(false, "Sound Tool");
        window.Show();
    }
    
    private void OnGUI() {
        if (soundData == null) return;
        EditorGUILayout.BeingVertical();
        {
            UnityObject source = soundSource;
            SoundClip sound = soundData.soundClips[selection];
            EditorHelper.EditorToolTopLayer(soundData, ref selection, ref source, uiWidthMiddle);
            soundSource = (AudioClip)source;
           
            EditorGUILayout.BeingVertical();
            {
                EditorHelper.EditorToolListLayer(ref SP1, soundData, ref selection, ref source, uiWidthMiddle);
                soundSource = (AudioClip)source;
                
                EditorGUILayout.BeingVertical();
                {
                    SP2 = EditorGUILayout.BeginScrollView(SP2);
                    {
                        if (soundData.GetDataCount() > 0) {
                            EditorGUILayout.BeginVertical();
                            {
                                EditorGUILayout.Separator();
                                SoundClip sound = soundData.soundClips[selection];
                                EditorGUILayout.LabelField("ID", selection.ToString(), GUILayout.Width(uiWidthLarge));
                                soundData.names[selection] = EditorGUILayout.TextField("Name", soundData.names[selection]), GUILayout.Width(uiWidthLarge));
                                sound.playType = (SoundPlayType)EditorGUILayout.EnumPopup("PlayType", sound.playType, GUILayout.Width(uiWidthLarge));
                                sound.maxVolume = EditorGUILayout.FloatField("Max Volume", sound.maxVolume, GUILayout.Width(uiWidthLarge));
                                sound.isLoop = EditorGUILayout.Toggle("LoopClip", sound.isLoop, GUILayout.Width(uiWidthLarge));
                                EditorGUILayout.Separator();
                                if (soundSource == null && sound.clipName != string.Empty) {
                                    soundSource = Resources.Load(sound.clipPath + sound.clipName) as AudioClip;
                                }
                                soundSource = (AudioClip)EditorGUILayout.ObjectField("Audio Clip", soundSource, typeof(AudioClip), false, GUILayout.Width(uiWidthLarge));
                                if (soundSource != null) {
                                    sound.clipPath = EditoHelper.GetPath(soundSource);
                                    sound.clipName = soundSource.name;
                                    sound.pitch = EditorGUILayout.Slider("Pitch", sound.pitch, -3.0f, 3.0f, GUILayout.Width(uiWidthLarge));
                                    
                                    // OMG



                                }
                                else {
                                    sound.clipName = string.Empty;
                                    sound.clipPath = string.Empty;
                                }
                                
                                EditorGUILayout.Separator();
                                if (GUILayout.Button("Add Loop", GUILayout.Width(uiWidthMiddle)) {
                                    soundData.soundClips[selection].AddLoop();
                                }
                                
                                // 더이상 따라가기가 벅차네요 ^^;


                            }
                            EditorGUILayout.EndVertical();
                        }
                    }
                    EditorGUILayout.EndScrollView();
                }
                EditorGUILayout.EndVertical();
            }
            EditorGUILayout.EndVertical();
        }
        EditorGUILayout.EndVertical();
        
        EditorGUILayout.Separator();
       
        EditorGUILayout.BeginHorizontal();
        {
            if (GUILayout.Button("Reload")) {
                soundData = CreateInstance<SoundData>();
                soundData.LoadData();
                selection = 0;
                soundSource = null;
            }
            if (GUILayout.Button("Save")) {
                soundData.SaveData();
                CreateEnumStructure();
                AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate);
            }
        }
        EditorGUILayout.EndHorizontal();
    }
    
    public void CreateEnumStructure() {
        string enumName = "SoundList";
        StringBuilder builder = new StringBuilder();
        for (int i = 0; i < soundData.ames.Length; i++) {
            if (!soundData.names[i].ToLower().Contains("none")) {
                builder.AppendLine("    " + soundData.names[i] + " = " + i.ToString() + ",");
            }
            EditorHelper.CreateEnumStructure(enumName, builder);
        }
    }
}




이렇게하여 SoundTool 창이 잘 떠서 동작함을 확인할 수 있습니다.
상세한 사용 설명은 게임을 개발할 때 설정해 보도록 할 예정입니다.





Audio Mixer에 대한 Unity 화면입니다.





SoundManager의 변수들입니다.

public class SoundManager : SingletonMonobehaviour<SoundManager>
{
    // 위의 변수들..
    
    public enum MusicPlayingType {
        None = 0,
        SourceA = 1,
        SourceB = 2,
        AtoB = 3,
        BtoA = 4
    }
    public AudioMixer mixer = null;
    public Transform audioRoot = null;
    public AudioSource fadeA_audio = null;
    public AudioSource fadeB_audio = null;
    public AudioSource[] effect_audios = null; // 예전 5채널 소리째짐을 회피하기 위한 채널갯수 제한.
    public AudioSource UI_audio = null;
    
    public float[] effect_PlayStartTime = null;
    private int EffectChannelCount = 5;
    private MusicPlayingType currentPlayingType = MusicPlayingType.None;
    private bool isTicking = false;
    private SoundClip currentSound = null;
    private SoundClip lastSound = null;
    private float minVolume = -80.0f;
    private float maxVolume = 0.0f;
}


여기까지가 SoundManager의 필요한 변수들을 설정한 내용입니다 ^^;;;
미리 말씀은 해주셨지만 진짜 멘붕이 오네요. ㅋㅋㅋ 나름 괘않을거라 생각하며 열심히 따라하였으나 중간에 왔다갔다 및 버그 수정 등 따라갈 수가 없는 ㅎㅎㅎㅎ

역시나 옵션이 많다보니 타이핑 신공으로 정신없이 쳐야한다는 점이 문제였던것같아요..
다음 시간에도 이어서 SoundTool을 진행합니다.



<위의 코드들은 제가 보면서 주요한 함수, 코드를 확인하기 위해 타이핑한 용도로, 전체 소스코드가 아님에 주의해 주세요. 전체 코드는 교육 수강을 하면 완벽하게 받으실 수가 있답니다 ^^>

패스트캠퍼스 - 올인원 패키지 : 유니티 포트폴리오 완성 bit.ly/2R561g0

 

유니티 게임 포트폴리오 완성 올인원 패키지 Online. | 패스트캠퍼스

게임 콘텐츠 프로그래머로 취업하고 싶다면, 포트폴리오 완성은 필수! '디아블로'와 '배틀그라운드' 게임을 따라 만들어 보며, 프로그래머 면접에 나오는 핵심 개념까지 모두 잡아 보세요!

www.fastcampus.co.kr

 

+ Recent posts