Exemplo n.º 1
0
        private void StartSample()
        {
            ResolvedGrain resolvedGrain = this.subDef.RandomizedResolvedGrain();

            if (resolvedGrain == null)
            {
                Log.Error("SubSustainer for " + this.subDef + " of " + this.parent.def + " could not resolve any grains.");
                this.parent.End();
            }
            else
            {
                float num  = (!this.subDef.sustainLoop) ? resolvedGrain.duration : this.subDef.sustainLoopDurationRange.RandomInRange;
                float num2 = Time.realtimeSinceStartup + num;
                this.nextSampleStartTime = num2 + this.subDef.sustainIntervalRange.RandomInRange;
                if (this.nextSampleStartTime < Time.realtimeSinceStartup + 0.0099999997764825821)
                {
                    this.nextSampleStartTime = (float)(Time.realtimeSinceStartup + 0.0099999997764825821);
                }
                if (!(resolvedGrain is ResolvedGrain_Silence))
                {
                    SampleSustainer sampleSustainer = SampleSustainer.TryMakeAndPlay(this, ((ResolvedGrain_Clip)resolvedGrain).clip, num2);
                    if (sampleSustainer != null)
                    {
                        if (this.subDef.sustainSkipFirstAttack && Time.frameCount == this.creationFrame)
                        {
                            sampleSustainer.resolvedSkipAttack = true;
                        }
                        this.samples.Add(sampleSustainer);
                    }
                }
            }
        }
Exemplo n.º 2
0
        private void StartSample()
        {
            ResolvedGrain resolvedGrain = subDef.RandomizedResolvedGrain();

            if (resolvedGrain == null)
            {
                Log.Error(string.Concat("SubSustainer for ", subDef, " of ", parent.def, " could not resolve any grains."));
                parent.End();
                return;
            }
            float num  = ((!subDef.sustainLoop) ? resolvedGrain.duration : subDef.sustainLoopDurationRange.RandomInRange);
            float num2 = Time.realtimeSinceStartup + num;

            nextSampleStartTime = num2 + subDef.sustainIntervalRange.RandomInRange;
            if (nextSampleStartTime < Time.realtimeSinceStartup + 0.01f)
            {
                nextSampleStartTime = Time.realtimeSinceStartup + 0.01f;
            }
            if (resolvedGrain is ResolvedGrain_Silence)
            {
                return;
            }
            SampleSustainer sampleSustainer = SampleSustainer.TryMakeAndPlay(this, ((ResolvedGrain_Clip)resolvedGrain).clip, num2);

            if (sampleSustainer != null)
            {
                if (subDef.sustainSkipFirstAttack && Time.frameCount == creationFrame)
                {
                    sampleSustainer.resolvedSkipAttack = true;
                }
                samples.Add(sampleSustainer);
            }
        }
        public static SampleSustainer TryMakeAndPlay(SubSustainer subSus, AudioClip clip, float scheduledEndTime)
        {
            SampleSustainer sampleSustainer = new SampleSustainer(subSus.subDef);

            sampleSustainer.subSustainer     = subSus;
            sampleSustainer.scheduledEndTime = scheduledEndTime;
            GameObject gameObject = new GameObject(string.Concat(new object[]
            {
                "SampleSource_",
                sampleSustainer.subDef.name,
                "_",
                sampleSustainer.startRealTime
            }));
            GameObject gameObject2 = (!subSus.subDef.onCamera) ? subSus.parent.worldRootObject : Find.Camera.gameObject;

            gameObject.transform.parent        = gameObject2.transform;
            gameObject.transform.localPosition = Vector3.zero;
            sampleSustainer.source             = AudioSourceMaker.NewAudioSourceOn(gameObject);
            SampleSustainer result;

            if (sampleSustainer.source == null)
            {
                if (gameObject != null)
                {
                    UnityEngine.Object.Destroy(gameObject);
                }
                result = null;
            }
            else
            {
                sampleSustainer.source.clip         = clip;
                sampleSustainer.source.volume       = sampleSustainer.SanitizedVolume;
                sampleSustainer.source.pitch        = sampleSustainer.SanitizedPitch;
                sampleSustainer.source.minDistance  = sampleSustainer.subDef.distRange.TrueMin;
                sampleSustainer.source.maxDistance  = sampleSustainer.subDef.distRange.TrueMax;
                sampleSustainer.source.spatialBlend = 1f;
                List <SoundFilter> filters = sampleSustainer.subDef.filters;
                for (int i = 0; i < filters.Count; i++)
                {
                    filters[i].SetupOn(sampleSustainer.source);
                }
                if (sampleSustainer.subDef.sustainLoop)
                {
                    sampleSustainer.source.loop = true;
                }
                sampleSustainer.Update();
                sampleSustainer.source.Play();
                sampleSustainer.source.Play();
                result = sampleSustainer;
            }
            return(result);
        }
Exemplo n.º 4
0
        private void StartSample()
        {
            ResolvedGrain resolvedGrain = this.subDef.RandomizedResolvedGrain();

            if (resolvedGrain == null)
            {
                Log.Error(string.Concat(new object[]
                {
                    "SubSustainer for ",
                    this.subDef,
                    " of ",
                    this.parent.def,
                    " could not resolve any grains."
                }));
                this.parent.End();
                return;
            }
            float num;

            if (this.subDef.sustainLoop)
            {
                num = this.subDef.sustainLoopDurationRange.RandomInRange;
            }
            else
            {
                num = resolvedGrain.duration;
            }
            float num2 = Time.realtimeSinceStartup + num;

            this.nextSampleStartTime = num2 + this.subDef.sustainIntervalRange.RandomInRange;
            if (this.nextSampleStartTime < Time.realtimeSinceStartup + 0.01f)
            {
                this.nextSampleStartTime = Time.realtimeSinceStartup + 0.01f;
            }
            if (resolvedGrain is ResolvedGrain_Silence)
            {
                return;
            }
            SampleSustainer sampleSustainer = SampleSustainer.TryMakeAndPlay(this, ((ResolvedGrain_Clip)resolvedGrain).clip, num2);

            if (sampleSustainer == null)
            {
                return;
            }
            if (this.subDef.sustainSkipFirstAttack && Time.frameCount == this.creationFrame)
            {
                sampleSustainer.resolvedSkipAttack = true;
            }
            this.samples.Add(sampleSustainer);
        }
Exemplo n.º 5
0
 private void EndSample(SampleSustainer samp)
 {
     this.samples.Remove(samp);
     samp.SampleCleanup();
 }