Ejemplo n.º 1
0
        public override void Bind(Entity entity, Main main, bool creating = false)
        {
            Transform transform = entity.GetOrCreate <Transform>("Transform");

            entity.CannotSuspendByDistance = true;

            Cloud settings = entity.GetOrCreate <Cloud>("Settings");

            ModelAlpha clouds = entity.GetOrCreate <ModelAlpha>("Clouds");

            clouds.Filename.Value        = "AlphaModels\\clouds";
            clouds.DrawOrder.Value       = -8;
            clouds.CullBoundingBox.Value = false;
            clouds.DisableCulling.Value  = true;

            base.Bind(entity, main, creating);

            clouds.Add(new Binding <Matrix>(clouds.Transform, transform.Matrix));

            clouds.Add(new Binding <string, bool>(clouds.TechniquePostfix, x => x ? "Infinite" : "", settings.Infinite));

            clouds.Add(new Binding <float>(clouds.GetFloatParameter("Height"), settings.Height));

            clouds.Add(new Binding <Vector3>(clouds.GetVector3Parameter("CameraPosition"), main.Camera.Position));

            clouds.Add(new Binding <Vector2>(clouds.GetVector2Parameter("Velocity"), x => x * (1.0f / 60.0f), settings.Velocity));

            clouds.Add(new Binding <float>(clouds.GetFloatParameter("StartDistance"), settings.StartDistance));

            entity.Add("Height", settings.Height);
            entity.Add("Velocity", settings.Velocity);
            entity.Add("StartDistance", settings.StartDistance);
            entity.Add("Color", clouds.Color);
            entity.Add("Alpha", clouds.Alpha);
            entity.Add("Infinite", settings.Infinite);
        }
Ejemplo n.º 2
0
        public override void Bind(Entity entity, Main main, bool creating = false)
        {
            Transform transform = entity.GetOrCreate <Transform>("Transform");

            ModelAlpha model = entity.GetOrCreate <ModelAlpha>("Model");

            model.Filename.Value   = "AlphaModels\\waterfall";
            model.Distortion.Value = true;

            this.SetMain(entity, main);

            VoxelAttachable.MakeAttachable(entity, main).EditorProperties();

            entity.Add("Scale", model.Scale);
            entity.Add("Color", model.Color);
            entity.Add("Alpha", model.Alpha);

            model.Add(new Binding <Matrix>(model.Transform, transform.Matrix));

            Property <Vector2> uvScale = model.GetVector2Parameter("UVScale");

            model.Add(new Binding <Vector2, Vector3>(uvScale, x => new Vector2(x.X, x.Y), model.Scale));

            Property <Vector3> soundPosition = new Property <Vector3>();

            Sound.AttachTracker(entity, soundPosition);

            if (!main.EditorEnabled && !model.Suspended)
            {
                AkSoundEngine.PostEvent(AK.EVENTS.PLAY_WATERFALL_LOOP, entity);
            }

            Action stopSound = delegate()
            {
                AkSoundEngine.PostEvent(AK.EVENTS.STOP_WATERFALL_LOOP, entity);
            };

            model.Add(new CommandBinding(model.OnSuspended, stopSound));
            model.Add(new CommandBinding(model.Delete, stopSound));
            model.Add(new CommandBinding(model.OnResumed, delegate()
            {
                if (!main.EditorEnabled)
                {
                    AkSoundEngine.PostEvent(AK.EVENTS.PLAY_WATERFALL_LOOP, entity);
                }
            }));

            Property <Vector2> offset  = model.GetVector2Parameter("Offset");
            Updater            updater = new Updater
                                         (
                delegate(float dt)
            {
                offset.Value           = new Vector2(0, main.TotalTime * -0.6f);
                Vector3 relativeCamera = Vector3.Transform(main.Camera.Position, Matrix.Invert(transform.Matrix));
                Vector3 bounds         = model.Scale.Value * 0.5f;
                relativeCamera.X       = MathHelper.Clamp(relativeCamera.X, -bounds.X, bounds.X);
                relativeCamera.Y       = Math.Min(0, relativeCamera.Y);
                relativeCamera.Z       = MathHelper.Clamp(relativeCamera.Z, -bounds.Z, bounds.Z);
                soundPosition.Value    = Vector3.Transform(relativeCamera, transform.Matrix);
            }
                                         );

            updater.EnabledInEditMode = true;
            entity.Add(updater);
        }