Пример #1
0
        public BackgroundKite(float initialX)
        {
            var scale = this.GetRandomScale();

            var scrollBehavior = new ScrollBehavior(scale * 0.1f);

            var transform = new Transform2D()
            {
                X      = initialX,
                Y      = WaveServices.ViewportManager.VirtualHeight,
                Origin = Vector2.UnitY,
                XScale = scale,
                YScale = scale
            };

            var spriteAtlas = new SpriteAtlas(Textures.GAME_ATLAS, this.GetRandomTextureName());

            this.entity = new Entity()
                          .AddComponent(transform)
                          .AddComponent(spriteAtlas)
                          .AddComponent(new SpriteAtlasRenderer(DefaultLayers.Alpha))
                          .AddComponent(scrollBehavior);

            scrollBehavior.EntityOutOfScreen += (entity) =>
            {
                transform.X = WaveServices.ViewportManager.RightEdge;

                var newScale = this.GetRandomScale();
                transform.XScale = newScale;
                transform.YScale = newScale;

                //Set a new kite texture
                spriteAtlas.TextureName = this.GetRandomTextureName();
            };
        }
Пример #2
0
 /// <summary>
 /// Add a new behavior onto the entity to check for while scrolling.
 /// </summary>
 /// <param name="behavior">Behavior to add.</param>
 protected void AddScrollBehavior(ScrollBehavior behavior)
 {
     if (!scrollModes.Contains(behavior))
     {
         scrollModes.Add(behavior);
     }
 }
Пример #3
0
 /// <summary>
 /// Scroll to an url fragment
 /// </summary>
 /// <param name="id">The id of the selector that is going to be scrolled to</param>
 /// <param name="behavior">smooth or auto</param>
 /// <returns></returns>
 public async Task ScrollToFragment(string id, ScrollBehavior behavior)
 {
     await _jSRuntime
     .InvokeVoidAsync("scrollHelpers.scrollToFragment",
                      id,
                      behavior.ToDescriptionString());
 }
Пример #4
0
 public ScrollConfigurationTest(
     Key key = null,
     ScrollBehavior behavior = null,
     Widget child            = null
     ) : base(key: key, behavior: behavior, child: child)
 {
 }
Пример #5
0
        public async Task ScrollToTop(ScrollBehavior scrollBehavior = ScrollBehavior.Auto)
        {
#pragma warning disable CS0612 // Type or member is obsolete
            await ScrollToAsync(Selector, 0, 0, scrollBehavior);

#pragma warning restore CS0612 // Type or member is obsolete
        }
Пример #6
0
    //捲軸設定初始化
    //[param] isAnimation = 是否使用動畫
    public void SetScrollCount(bool isAnimation)
    {
        for (int i = 0; i < scrollCount; i++)
        {
            if (scrollGroup.Count < scrollCount) //捲軸物件不足時, 創建之
            {
                GameObject     _go  = Instantiate(scrollPrefab, scrollHolder);
                ScrollBehavior _scr = _go.GetComponent <ScrollBehavior>(); //取得腳本

                _go.SetActive(false);                                      //暫時隱藏物件
                scrollGroup.Add(_scr);                                     //加入列表
            }

            scrollGroup[i].Initialize((byte)i, scrollMinWidth, scrollPrefrerrdWidth, isAnimation ? layoutAnimationDuration : 0);
        }

        for (int i = scrollCount; i < scrollGroup.Count; i++) //暫時隱藏多餘捲軸
        {
            if (isAnimation)
            {
                scrollGroup[i].Invalid(scrollMinWidth, scrollPrefrerrdWidth, layoutAnimationDuration);              //有動畫
            }
            else
            {
                scrollGroup[i].Invalid(scrollMinWidth, scrollPrefrerrdWidth);  //無動畫
            }
        }
    }
Пример #7
0
 /// <summary>
 /// Scrolls to the coordinates of the element defined in Selector property
 /// </summary>
 /// <param name="left">x coordinate</param>
 /// <param name="top">y coordinate</param>
 /// <param name="behavior">smooth or auto</param>
 /// <returns></returns>
 public async Task ScrollTo(int left = 0, int top = 0, ScrollBehavior behavior = ScrollBehavior.Auto)
 {
     await _jSRuntime
     .InvokeVoidAsync("scrollHelpers.scrollTo",
                      Selector,
                      left,
                      top,
                      behavior.ToDescriptionString());
 }
Пример #8
0
 public Entity(State _state, Texture2D _image, string _tag = "Entity [Default]",
               Vector2?_pos    = null, float _size          = 0.0f,
               float _rotation = 0f, ScrollBehavior _scroll = ScrollBehavior.Wrap,
               CollisionBehavior _collision = CollisionBehavior.Null,
               bool _enabled = false, bool _visible         = false,
               bool _drawGUI = false, ControlScheme _schema = null,
               ColorSet _set = null)
 {
     Initialize(_state, _image, _tag, _pos, _size, _rotation, _set, _scroll, _collision, _enabled, _visible, _drawGUI, _schema);
 }
Пример #9
0
        /// <summary>
        /// Determines if this contains a particular behavior.
        /// </summary>
        /// <param name="behavior">Behavior to check for.</param>
        /// <returns>Returns true if it is in the list.</returns>
        protected bool HasScrollBehavior(ScrollBehavior behavior)
        {
            foreach (ScrollBehavior mode in scrollModes)
            {
                if (behavior == mode)
                {
                    return(true);
                }
            }

            return(false);
        }
Пример #10
0
 protected void Initialize(State _state,
                           Texture2D _image, string _tag = "Entity [Default]",
                           Vector2?_pos                 = null, float _size = 0.0f,
                           float _rotation              = 0f, ColorSet _set = null,
                           ScrollBehavior _scroll       = ScrollBehavior.Wrap,
                           CollisionBehavior _collision = CollisionBehavior.Null,
                           bool _enabled                = false, bool _visible         = false,
                           bool _drawGUI                = false, ControlScheme _schema = null)
 {
     SetState(_state);              // Store the current state.
     SetImage(_image);              // File the image to draw with.
     SetTag(_tag);                  // Add a tag for the element.
     SetColorSet(_set);             // Set the colors we'd like to use.
     SetDimensions(_size);          // By default, base the size off of the image's picture.
     SetRotation(_rotation);        // By default this will be 0, but, we can customize on creation. Useful for spawning.
     SetScrollModes(_scroll);       // Wrap entity by default.
     SetCollisionModes(_collision); // Do not collide by default.
     SetFlags(_enabled, _visible);  // Set these flags up by default.
     CreateControlScheme(_schema);
 }
Пример #11
0
        /// <summary>
        /// Creates a new backgroundCloud entity.
        /// </summary>
        /// <returns></returns>
        public static Entity CreateBackgroundCloud()
        {
            var scrollBehavior = new ScrollBehavior(0.06f);

            var transform = new Transform2D()
            {
                X = WaveServices.ViewportManager.VirtualWidth / 2,
                Y = 197,
            };

            var cloud = new Entity()
                        .AddComponent(transform)
                        .AddComponent(new SpriteAtlas(Textures.GAME_ATLAS, Textures.GameAtlas.bg_cloud.ToString()))
                        .AddComponent(new SpriteAtlasRenderer(DefaultLayers.Alpha))
                        .AddComponent(scrollBehavior);

            scrollBehavior.EntityOutOfScreen += (entity) =>
            {
                transform.X = WaveServices.ViewportManager.RightEdge;
            };

            return(cloud);
        }
Пример #12
0
        /// <summary>
        /// Creates a new backgroundPlane entity.
        /// </summary>
        /// <returns></returns>
        public static Entity CreateBackgroundPlane()
        {
            var scrollBehavior = new ScrollBehavior(0.08f);

            var transform = new Transform2D()
            {
                X         = WaveServices.ViewportManager.RightEdge - 150,
                Y         = 273,
                DrawOrder = 0.85f
            };

            var cloud = new Entity()
                        .AddComponent(transform)
                        .AddComponent(new SpriteAtlas(Textures.GAME_ATLAS, Textures.GameAtlas.bg_plane.ToString()))
                        .AddComponent(new SpriteAtlasRenderer(DefaultLayers.Alpha))
                        .AddComponent(scrollBehavior);

            scrollBehavior.EntityOutOfScreen += (entity) =>
            {
                transform.X = WaveServices.ViewportManager.RightEdge + WaveServices.ViewportManager.ScreenWidth;
            };

            return(cloud);
        }
Пример #13
0
 public ValueTask ScrollToAsync(string id, int left, int top, ScrollBehavior scrollBehavior) => ValueTask.CompletedTask;
Пример #14
0
 public Task ScrollToTop(ScrollBehavior scrollBehavior = ScrollBehavior.Auto)
 {
     return(Task.CompletedTask);
 }
Пример #15
0
 public Task ScrollToFragment(string id, ScrollBehavior behavior)
 {
     return(Task.CompletedTask);
 }
Пример #16
0
 public async Task ScrollTo(int left, int top, ScrollBehavior behavior) =>
 await ScrollToAsync(Selector, left, top, behavior);
Пример #17
0
 /// <summary>
 /// Scrolls to the top of the element
 /// </summary>
 /// <param name="id">id of element</param>
 /// <param name="scrollBehavior">smooth or auto</param>
 /// <returns></returns>
 public ValueTask ScrollToTopAsync(string id, ScrollBehavior scrollBehavior = ScrollBehavior.Auto) =>
 ScrollToAsync(id, 0, 0, scrollBehavior);
Пример #18
0
 public async Task ScrollToFragment(string id, ScrollBehavior behavior) =>
 await ScrollToFragmentAsync(id, behavior);
Пример #19
0
 /// <summary>
 /// Scrolls to the coordinates of the element
 /// </summary>
 /// <param name="id">id of element</param>
 /// <param name="left">x coordinate</param>
 /// <param name="top">y coordinate</param>
 /// <param name="behavior">smooth or auto</param>
 /// <returns></returns>
 public ValueTask ScrollToAsync(string id, int left, int top, ScrollBehavior behavior) =>
 _jSRuntime.InvokeVoidAsync("mudScrollManager.scrollTo", id, left, top, behavior.ToDescriptionString());
Пример #20
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ObstaclePair" /> class.
        /// </summary>
        /// <param name="reappearanceX">The reappearance X.</param>
        public ObstaclePair(float reappearanceX)
        {
            var topObstacleY = (WaveServices.ViewportManager.VirtualHeight - OBSTACLES_SEPARATION) / 2;

            var topObstacle = new Entity("TopObstacle")
                              .AddComponent(new Transform2D()
            {
                Y      = topObstacleY,
                Origin = Vector2.UnitY,
            })
                              .AddComponent(new SpriteAtlas(Textures.GAME_ATLAS, Textures.GameAtlas.obstacle_top.ToString()))
                              .AddComponent(new SpriteAtlasRenderer(typeof(ObstaclesLayer)))
                              .AddComponent(this.TopCollider = new PerPixelCollider(Textures.OBSTACLE_TOP_COLLID, 0.5f));

            var bottomObstacle = new Entity("BottomObstacle")
                                 .AddComponent(new Transform2D()
            {
                X = 75,
                Y = topObstacleY + OBSTACLES_SEPARATION
            })
                                 .AddComponent(new SpriteAtlas(Textures.GAME_ATLAS, Textures.GameAtlas.obstacle_bottom.ToString()))
                                 .AddComponent(new SpriteAtlasRenderer(typeof(ObstaclesLayer)))
                                 .AddComponent(this.BottomCollider = new PerPixelCollider(Textures.OBSTACLE_BOTTOM_COLLID, 0.5f));

            this.starEntity = EntitiesFactory.CreateGameStar(
                0,
                WaveServices.ViewportManager.VirtualHeight / 2)
                              .AddComponent(this.StarCollider = new CircleCollider());

            this.starParticles = new Entity()
                                 .AddComponent(new Transform2D()
            {
                X = 0,
                Y = WaveServices.ViewportManager.VirtualHeight / 2,
            })
                                 .AddComponent(new Material2D(new BasicMaterial2D(Textures.STAR, DefaultLayers.Alpha)))
                                 .AddComponent(new ParticleSystemRenderer2D("explosion"))
                                 .AddComponent(new ParticleSystem2D()
            {
                NumParticles        = 20,
                EmitRate            = 300,
                MinLife             = TimeSpan.FromSeconds(3f),
                MaxLife             = TimeSpan.FromSeconds(1f),
                LocalVelocity       = new Vector2(-3.5f, -5f),
                RandomVelocity      = new Vector2(3.5f, 1f),
                MinSize             = 5,
                MaxSize             = 20,
                MinRotateSpeed      = 0.03f,
                MaxRotateSpeed      = -0.03f,
                EndDeltaScale       = 0f,
                LinearColorEnabled  = true,
                InterpolationColors = new List <Color>()
                {
                    Color.White, Color.Black
                },
                EmitterSize  = new Vector3(30, 30, 0),
                Gravity      = Vector2.UnitY * 0.2f,
                EmitterShape = ParticleSystem2D.Shape.FillCircle,
                Emit         = false,
            });


            var scrollBehavior = new ScrollBehavior(1);

            this.entity = new Entity("ObstaclePair" + instancesCount++)
            {
                Tag = "OBSTACLE"
            }
            .AddComponent(this.Transform2D = new Transform2D()
            {
                X         = WaveServices.ViewportManager.RightEdge,
                DrawOrder = 0.8f
            })
            .AddComponent(scrollBehavior)
            .AddChild(topObstacle)
            .AddChild(bottomObstacle)
            .AddChild(this.starEntity)
            .AddChild(this.starParticles)
            .AddComponent(new ChildrenRectangle());

            scrollBehavior.EntityOutOfScreen += (entity) =>
            {
                this.Transform2D.X += reappearanceX;
                this.Transform2D.Y  = this.GetRandomY();
                this.StarAvaible    = true;
            };
        }
Пример #21
0
 /// <summary>
 /// Scroll to an url fragment
 /// </summary>
 /// <param name="id">The id of the selector that is going to be scrolled to</param>
 /// <param name="behavior">smooth or auto</param>
 /// <returns></returns>
 public ValueTask ScrollToFragmentAsync(string id, ScrollBehavior behavior) =>
 _jSRuntime.InvokeVoidAsync("mudScrollManager.scrollToFragment", id, behavior.ToDescriptionString());
Пример #22
0
 public Task ScrollToTop(ScrollBehavior scrollBehavior = ScrollBehavior.Auto) => Task.CompletedTask;
Пример #23
0
 public ValueTask ScrollToTopAsync(string id, ScrollBehavior scrollBehavior = ScrollBehavior.Auto) => ValueTask.CompletedTask;
Пример #24
0
 public ValueTask ScrollToFragmentAsync(string id, ScrollBehavior behavior) => ValueTask.CompletedTask;
Пример #25
0
 public Task ScrollToFragment(string id, ScrollBehavior behavior) => Task.CompletedTask;
Пример #26
0
 public Task ScrollTo(int left, int top, ScrollBehavior scrollBehavior)
 {
     return(Task.CompletedTask);
 }
Пример #27
0
 public Task ScrollTo(int left, int top, ScrollBehavior scrollBehavior) => Task.CompletedTask;
Пример #28
0
 /// <summary>
 /// Scrolls to the top of the element defined in Selector property
 /// </summary>
 /// <param name="scrollBehavior">smooth or auto</param>
 /// <returns></returns>
 public async Task ScrollToTop(ScrollBehavior scrollBehavior = ScrollBehavior.Auto)
 {
     await ScrollTo(0, 0, scrollBehavior);
 }