Пример #1
0
        public override void Play(EffectContext context)
        {
            var position = context.GetRequiredFeature <PositionFeature>().Position;
            // Check if color features are present
            var color          = context.GetOptionalFeature <ColorFeature>();
            var gradient       = context.GetOptionalFeature <GradientFeature>();
            var minMaxColor    = context.GetOptionalFeature <MinMaxColorFeature>();
            var minMaxGradient = context.GetOptionalFeature <MinMaxGradientFeature>();

            // If more than one are provided,
            this.CheckIncompatibleFeatures(color, gradient, minMaxColor, minMaxGradient);

            var instance = ParticlePrefab.Clone(position);

            if (color != null)
            {
                SetParticleColor(instance, color.Color);
            }

            if (gradient != null)
            {
                SetParticleColor(instance, gradient.Gradient);
            }

            if (minMaxColor != null)
            {
                SetParticleColor(instance, minMaxColor);
            }

            if (minMaxGradient != null)
            {
                SetParticleColor(instance, minMaxGradient);
            }

            var material = context.GetOptionalFeature <MaterialFeature>();

            if (material != null)
            {
                var renderer = instance.GetComponent <ParticleSystemRenderer>();
                renderer.sharedMaterial = material.Material;
            }

            OnDefaultSetupFinished(instance, context);
            if (!ForceDestroyOnFinished)
            {
                return;
            }

            var main = instance.main;

            main.stopAction = ParticleSystemStopAction.Destroy;
            if (!main.playOnAwake)
            {
                instance.Play();
            }
        }
Пример #2
0
        public override void Play(EffectContext context)
        {
            var             position = context.GetOptionalFeature <PositionFeature>();
            var             clip     = Clips.RandomElement();
            AudioController controller;

            if (UseAudioControllerIfPresent && (controller = AudioController.Instance) != null)
            {
                PlayWithController(position, context, clip, controller);
            }
            else
            {
                var pos = position == null ? context.Host.transform.position : position.Position;
                PlayStandalone(pos, clip, context);
            }
        }
Пример #3
0
        public override void Play(EffectContext context)
        {
            if (UseShakeControllerIfPresent)
            {
                var f = context.GetOptionalFeature <ObjectFeature <ObjectShakeController> >();
                if (f != null)
                {
                    f.Value.RegisterTimedService(
                        Duration.Evaluate(context),
                        new ShakeMeta()
                        );
                    return;
                }
            }

            PlayStandalone(context);
        }
Пример #4
0
        private void PlayWithController(PositionFeature position, EffectContext context, AudioClip clip,
                                        AudioController controller)
        {
            AudioEvent audioEvent;
            var        volume       = LoadVolume(context);
            var        pitch        = LoadPitch(context);
            var        loopDuration = LoadLoopDuration(context);

            if (position == null)
            {
                audioEvent = new AudioEvent(clip, pitch, volume, Loop, loopDuration, Mixer, context.Host.transform);
            }
            else
            {
                var velFeature = context.GetOptionalFeature <VelocityFeature>();
                var velocity   = velFeature != null ? velFeature.Velocity : Vector3.zero;
                audioEvent = new AudioEvent(clip, pitch, volume, position.Position, Loop, loopDuration, Mixer,
                                            velocity);
            }

            controller.PlayAudioEvent(audioEvent);
        }