Inheritance: MonoBehaviour
示例#1
0
        public static void initSounds()
        {
            if (offline)
            {
                return;
            }

            XmlSerializer serializer = new XmlSerializer(typeof(SoundCollection));

            using (FileStream fileStream = new FileStream(Path.Combine(SoundsDataPath(), "_infos.xml"), FileMode.Open))
            {
                SoundCollection result = (SoundCollection)serializer.Deserialize(fileStream);
                soundsUrl = result.Location;
            }

            try
            {
                using (WebClient client = new WebClient())
                {
                    string collection = string.Empty;

                    collection = client.DownloadString(soundsUrl);

                    availableSounds = Newtonsoft.Json.JsonConvert.DeserializeObject <List <string> >(collection);
                }
            } catch (WebException e)
            {
                Loggers.WriteError(LogTags.Sound, "Unable to fetch sound collection from server. Reason is " + e.ToString());
            }
        }
示例#2
0
 // Use this for initialization
 void Start()
 {
     GameObject obj = GameObject.Find("SoundCollection");
     soundCollection = (SoundCollection)obj.GetComponent("SoundCollection");
     audioSource = gameObject.AddComponent<AudioSource>();
     audioSource.playOnAwake = false;
 }
 public void PlaySoundCollection(SoundCollection soundCollection)
 {
     if (soundCollection != null)
     {
         soundCollection.Play(fxAudioSource);
     }
 }
示例#4
0
 public void PlayNextSound(SoundCollection collection)
 {
     if (collection == null)
     {
         return;
     }
     _audioSource.PlayOneShot(collection.getNextClip(), collection.volumeScale);
 }
示例#5
0
 private void Initialize()
 {
     if (Initialized)
     {
         return;
     }
     log.InfoFormat("Initializing Soundpack '{0}'...", Name);
     Music = new SoundCollection(elem.Element("MusicList"), this);
     Sound = new SoundCollection(elem.Element("SoundList"), this);
 }
示例#6
0
    public void playSoundCollection(SoundCollection soundCollection)
    {
        int randomIndex = Random.Range(0, soundCollection.sounds.Count);

        _audioSource.clip   = soundCollection.sounds[randomIndex];
        _audioSource.volume = soundCollection.volume;

        _audioSource.pitch = Random.Range(soundCollection.minPitch, soundCollection.maxPitch);
        _audioSource.Play();
    }
示例#7
0
        private void MoveDown()
        {
            int currentIndex = SoundCollection.IndexOf(SelectedSound);

            if (currentIndex < 1)
            {
                return;
            }

            SoundCollection.Move(currentIndex, currentIndex - 1);
        }
示例#8
0
        private void MoveUp()
        {
            int currentIndex = SoundCollection.IndexOf(SelectedSound);
            int maxIndex     = SoundCollection.Count - 1;

            if (currentIndex == maxIndex)
            {
                return;
            }

            SoundCollection.Move(currentIndex, currentIndex + 1);
        }
示例#9
0
    private void Start()
    {
        collection = Globals.soundcollection;

        ui_audio_source       = Loader.EnsureComponent <AudioSource>(gameObject);
        rcs_audio_source      = gameObject.AddComponent <AudioSource>();
        rcs_audio_source.loop = true;
        rcs_audio_source.clip = Globals.loaded_data.rcs_sound;

        computer_audio_source      = gameObject.AddComponent <AudioSource>();
        computer_audio_source.loop = true;

        UpdateVolumes();
    }
示例#10
0
    public void PlayRandomSound(SoundCollection collection, float overrideVolumeScale = 0f)
    {
        if (collection == null)
        {
            return;
        }
        float volumeScale = collection.volumeScale;

        if (overrideVolumeScale > 0)
        {
            volumeScale = overrideVolumeScale;
        }
        _audioSource.PlayOneShot(collection.getRandomClip(), volumeScale);
    }
示例#11
0
    public bool AllocateRand3dSound(SoundCollection collection, Transform parent, Vector3 localPos, out AudioUnit unit)
    {
        if (!AllocateUnit(out unit))
        {
            return(false);
        }

        SoundType type = soundRandomCollect[collection][URandom.Range(0, soundRandomCollect[collection].Count)];

        unit.source.clip = clipDict[type];
        unit.gameObject.transform.parent        = parent != null ? parent : transform;
        unit.gameObject.transform.localPosition = localPos;

        return(true);
    }
示例#12
0
 public GMXFile()
 {
     Sprites      = new SpriteCollection();
     Sound        = new SoundCollection();
     Backgrounds  = new BackgroundCollection();
     Paths        = new PathCollection();
     Scripts      = new ScriptCollection();
     Fonts        = new FontCollection();
     TimeLines    = new TimeLineCollection();
     Objects      = new ObjectCollection();
     Rooms        = new RoomCollection();
     Includes     = new IncludedFileCollection();
     Configs      = new ConfigCollection();
     ResourceTree = new ResourceTree();
 }
示例#13
0
        /// <summary>
        /// Calculates dictionary of sounds
        /// </summary>
        /// <param name="collection">Collection of objects</param>
        /// <returns>Dictionary of sounds</returns>
        Dictionary <double, string> GetSounds(IComponentCollection collection)
        {
            IDesktop desktop = collection as IDesktop;
            Dictionary <double, string> d    = new Dictionary <double, string>();
            SoundCollection             coll = desktop.GetObject(name) as SoundCollection;
            IDataConsumer        dc          = coll;
            ITimeMeasureProvider p           = DataPerformer.Portable.StaticExtensionDataPerformerPortable.Factory.TimeProvider;
            Action <string>      act         = (string s) => { d[p.Time] = s; };

            coll.PlaySound += act;
            dc.PerformFixed(start, step, stepCount, p,
                            DataPerformer.Portable.DifferentialEquationProcessors.DifferentialEquationProcessor.Processor, "Animation", 0, () => { });
            coll.PlaySound -= act;
            return(d);
        }
 public GameMakerFile()
 {
     Sprites = new SpriteCollection();
       Sounds = new SoundCollection();
       Backgrounds = new BackgroundCollection();
       Paths = new PathCollection();
       Scripts = new ScriptCollection();
       Fonts = new FontCollection();
       TimeLines = new TimeLineCollection();
       Objects = new ObjectCollection();
       Rooms = new RoomCollection();
       Triggers = new TriggerCollection();
       Includes = new IncludedFileCollection();
       Constants = new ConstantCollection();
       Information = new GameInformation();
       Settings = new GameSettings();
       ResourceTree = new ResourceTree();
 }
 public GameMakerFile()
 {
     Sprites      = new SpriteCollection();
     Sounds       = new SoundCollection();
     Backgrounds  = new BackgroundCollection();
     Paths        = new PathCollection();
     Scripts      = new ScriptCollection();
     Fonts        = new FontCollection();
     TimeLines    = new TimeLineCollection();
     Objects      = new ObjectCollection();
     Rooms        = new RoomCollection();
     Triggers     = new TriggerCollection();
     Includes     = new IncludedFileCollection();
     Constants    = new ConstantCollection();
     Information  = new GameInformation();
     Settings     = new GameSettings();
     ResourceTree = new ResourceTree();
 }
示例#16
0
    private void Awake()
    {
        // Make this persistent
        if (GameObject.FindGameObjectsWithTag("Persistent").Length > 1)
        {
            Destroy(gameObject);
            return;
        }
        DontDestroyOnLoad(gameObject);
        Globals.persistend = this;

        var sound_coll = new SoundCollection("sounds");

        SetCursor();
        UpdateOnMenu();

        Volumes.Initialize(Globals.settings.GetChild("sound volume"));
        DeveloppmentTools.Testing();
    }
示例#17
0
        void Add(object o, DataRow row, TestData test)
        {
            IObjectLabel l = o as IObjectLabel;

            string          name = l.Name;
            ICategoryObject co   = l.Object;

            if (co is SoundCollection)
            {
                SoundCollection sc  = co as SoundCollection;
                TestDataSound   tds = test as TestDataSound;
                if (l is IProperties)
                {
                    object p = (l as IProperties).Properties;
                    SoundService.UI.Labels.SoundCollectionLabel sl = p as SoundService.UI.Labels.SoundCollectionLabel;
                    object[] ob = sl.TestData;
                    tds.AddSound(name, (double)ob[0], (double)ob[1], (int)ob[2], l.Desktop);
                }
            }
        }
示例#18
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);
            }
        }
示例#19
0
 protected abstract void ProcessResource( SoundCollection aSounds );
示例#20
0
 protected abstract void ProcessResource(SoundCollection aSounds);
示例#21
0
        protected override void ProcessResource( SoundCollection aSounds )
        {
            if ( !aSounds.Any() )
            return;

              OnCategoryProcessing( ResourceTypes.Sounds );
              Directory.CreateDirectory( IO.Path.Combine( Directories.Sounds, Directories.Files ) );
              var previous = SetCurrentDirectory( Directories.Sounds );

              foreach ( var sound in aSounds ) {
            var fileName = SafeResourceFilename( sound );
            string pathSound = null;

            if ( sound.SoundData != null ) {
              pathSound = IO.Path.Combine( Directories.Files, fileName + sound.TypeExtension );

              using ( var file = File.Create( pathSound ) )
            file.Write( sound.SoundData, 0, sound.SoundData.Length );
            }

            var document =
              new XElement( "Sound",
            CreateIndexedResourceNodes( sound ),
            new XElement( "Kind", sound.Kind ),
            new XElement( "Preload", sound.Preload ),
            new XElement( "SoundPath", pathSound ),
            new XElement( "TypeExtension", sound.TypeExtension ),
            new XElement( "OriginalFilename", sound.OriginalFilename ),
            new XElement( "Volume", sound.Volume ),
            new XElement( "Pan", sound.Pan ),
            new XElement( "Effects", sound.Effects.ToString() )
              );

            OnResourceProcessed( sound.Name );
            SaveDocument( document, fileName + ".xml" );
              }

              OnCategoryProcessed( ResourceTypes.Sounds );
              SetCurrentDirectory( previous );
        }
示例#22
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();
            }
        }
示例#23
0
 private void RemoveSound()
 {
     SoundCollection.Remove(SelectedSound);
 }
示例#24
0
 public SoundController()
 {
     collection = GameObject.Find("GameManager").GetComponent <SoundCollection> ();
 }
示例#25
0
        public void PlayEffectFromCollection(SoundCollection collection, Vector3 pos, float volume = 1f)
        {
            var clip = collection.Random();

            PlayEffectAt(clip, pos, volume);
        }