Add() public method

Add new empty sound to list of cached sounds
public Add ( ) : void
return void
示例#1
0
        protected override void ProcessResource(SoundCollection aSounds)
        {
            var files = GetXmlFiles(Directories.Sounds);

            if (files.Any())
            {
                OnCategoryProcessing(ResourceTypes.Sounds);
                var previous = SetCurrentDirectory(Directories.Sounds);

                foreach (var file in files)
                {
                    var document = LoadXml(file);

                    if (document != null)
                    {
                        var sound = new Sound();

                        sound.ID               = GetElementValue <int>(document, "ID");
                        sound.Name             = GetElement(document, "Name").Value;
                        sound.Kind             = GetElementValue <SoundKinds>(document, "Kind");
                        sound.Preload          = GetElementValue <bool>(document, "Preload");
                        sound.TypeExtension    = GetElement(document, "TypeExtension").Value;
                        sound.OriginalFilename = GetElement(document, "OriginalFilename").Value;
                        sound.Volume           = GetElementValue <double>(document, "Volume");
                        sound.Pan              = GetElementValue <double>(document, "Pan");
                        sound.Effects          = GetElementValue <EffectBitMask>(document, "Effects");

                        var data = LoadToMemory(GetElement(document, "SoundPath").Value);
                        sound.SoundData = data; // ?

                        aSounds.Add(sound);
                    }

                    OnAbortProcessingCallback();
                }

                OnCategoryProcessed(ResourceTypes.Sounds);
                SetCurrentDirectory(previous);
            }
        }
示例#2
0
        public override void OnInspectorGUI()
        {
            DrawDefaultInspector();

            SoundCollection mycollection = (SoundCollection)target;

            if (GUILayout.Button("Add New Sound"))
            {
                mycollection.Add();
            }

            GUI.color = Color.red;
            if (GUILayout.Button("Clear Sounds"))
            {
                if (EditorUtility.DisplayDialog("Clear All Sounds",
                                                "Are sure you want to clear all the sounds? This action cannot be undone.", "Yes Damnit  (╯°□°)╯︵ ┻━┻", "Oh god no"))
                {
                    mycollection.sounds.Clear();
                }
            }
            GUI.color = Color.white;

            EditorGUILayout.Space();
            EditorGUILayout.Space();

            GUIContent content = new GUIContent("Sound Type ", HELP_MESSAGE_SOUND_TYPE);

            mycollection.soundType = (SoundType)EditorGUILayout.EnumPopup(mycollection.soundType);

            EditorGUILayout.Space();
            EditorGUILayout.Space();
            EditorGUILayout.Space();
            EditorGUILayout.Space();
            EditorGUILayout.Space();

            foreach (Sound sound in mycollection.sounds)
            {
                EditorGUILayout.BeginVertical("Box");
                sound.show = EditorGUILayout.Foldout(sound.show, sound.name);

                if (sound.show)
                {
                    EditorGUILayout.Space();

                    content    = new GUIContent("Name ", HELP_MESSAGE_NAME);
                    sound.name = EditorGUILayout.TextField(content, sound.name);

                    EditorGUILayout.Space();

                    content         = new GUIContent("Audio Clip ", HELP_MESSAGE_AUDIO_CLIP);
                    sound.audioClip = (AudioClip)EditorGUILayout.ObjectField(content, sound.audioClip, typeof(AudioClip), true);

                    EditorGUILayout.Space();

                    content      = new GUIContent("Volume ", HELP_MESSAGE_VOLUME);
                    sound.volume = EditorGUILayout.Slider(content, sound.volume, 0f, 1f);

                    EditorGUILayout.Space();

                    content             = new GUIContent("Instance Limit ", HELP_MESSAGE_INSTANCE_LIMIT);
                    sound.instanceLimit = EditorGUILayout.IntField(content, sound.instanceLimit);


                    EditorGUILayout.Space();
                    EditorGUILayout.Space();
                    EditorGUILayout.Space();

                    content = new GUIContent("Pitch ", HELP_MESSAGE_PITCH);
                    EditorGUILayout.LabelField(content);
                    float minVal = sound.minPitch;
                    float maxVal = sound.maxPitch;
                    EditorGUILayout.MinMaxSlider(ref minVal, ref maxVal, 0f, 3f);
                    sound.minPitch = minVal;
                    sound.maxPitch = maxVal;


                    EditorGUILayout.BeginHorizontal();
                    float width = EditorGUIUtility.currentViewWidth - 50;

                    EditorGUILayout.BeginVertical();
                    EditorGUILayout.LabelField("min", GUILayout.Width(width / 2));
                    sound.minPitch = EditorGUILayout.FloatField(sound.minPitch, GUILayout.Width(width / 2));
                    EditorGUILayout.EndVertical();

                    EditorGUILayout.BeginVertical();
                    EditorGUILayout.LabelField("max", GUILayout.Width(width / 2));
                    sound.maxPitch = EditorGUILayout.FloatField(sound.maxPitch, GUILayout.Width(width / 2));
                    EditorGUILayout.EndVertical();

                    EditorGUILayout.EndHorizontal();

                    EditorGUILayout.Space();
                    EditorGUILayout.Space();
                    EditorGUILayout.Space();
                    EditorGUILayout.Space();
                    EditorGUILayout.Space();

                    content            = new GUIContent("Spatial Blend ", HELP_MESSAGE_SPATIAL_BLEND);
                    sound.spatialBlend = EditorGUILayout.Slider(content, sound.spatialBlend, 0f, 1f);

                    EditorGUILayout.Space();

                    content    = new GUIContent("Loop ", HELP_MESSAGE_LOOP);
                    sound.loop = EditorGUILayout.Toggle(content, sound.loop);

                    EditorGUILayout.Space();
                    EditorGUILayout.Space();
                    EditorGUILayout.Space();

                    if (GUILayout.Button("Reset"))
                    {
                        mycollection.Reset(sound);
                        break;
                    }

                    if (GUILayout.Button("Remove"))
                    {
                        mycollection.Remove(sound);
                        break;
                    }



                    EditorGUILayout.Space();
                    EditorGUILayout.Space();
                    EditorGUILayout.Space();
                    EditorGUILayout.Space();
                    EditorGUILayout.Space();
                }
                EditorGUILayout.EndVertical();
            }
        }