예제 #1
0
        protected override void OnStartRunning()
        {
            Entities.WithStoreEntityQueryInField(ref renderCmdQuery).ForEach((RenderCommand cmd) => {
                feature = cmd.RenderFeature;
            }).WithoutBurst().Run();

            Entities.WithStoreEntityQueryInField(ref textureBinQuery).ForEach((TextureBin c0) => {
                textureBin = c0;
            }).WithoutBurst().Run();
        }
예제 #2
0
        protected override void OnUpdate()
        {
            Entities.ForEach((Image image) => {
                TextureBin.TryLoadTextureBin("TextureBin", out TextureBin textureBin);

                var texture    = image.sprite != null ? image.sprite.texture : Texture2D.whiteTexture;
                var imageIndex = textureBin.Add(texture);

                var entity   = GetPrimaryEntity(image);
                var material = image.material != null ? image.material : Canvas.GetDefaultCanvasMaterial();
                DstEntityManager.AddComponentObject(entity, material);

                // TODO: Internally this would need a look up table...
                // DstEntityManager.AddSharedComponentData(entity, new MaterialID { Value = material.GetInstanceID() });

                var rectSize = image.rectTransform.Int2Size();

                DstEntityManager.AddComponentData(entity, new TextureKey   {
                    Value = imageIndex
                });
                DstEntityManager.AddComponentData(entity, new AppliedColor {
                    Value = image.color
                });
                DstEntityManager.AddComponentData(entity, new Dimensions   {
                    Value = rectSize
                });

                var spriteTexture = image.sprite;
                var spriteRes     = spriteTexture != null ?
                                    new int2(spriteTexture.texture.width, spriteTexture.texture.height) :
                                    rectSize;

                DstEntityManager.AddComponentData(entity, new DefaultSpriteResolution {
                    Value = spriteRes
                });

                var spriteData = SpriteData.FromSprite(image.sprite);
                DstEntityManager.AddComponentData(entity, spriteData);

                // TODO: Does not handle image slicing
                DstEntityManager.AddBuffer <MeshVertexData>(entity).ResizeUninitialized(4);
                DstEntityManager.AddBuffer <TriangleIndexElement>(entity).ResizeUninitialized(6);
            });
        }
예제 #3
0
        /// <summary>
        /// Makes a new tree at the given position in the given room.
        /// </summary>
        /// <param name="Position">The starting position of the tree.</param>
        /// <param name="Room">The room in which the tree is located.</param>
        public Tree(Vector2 Position, float Height, float numBranches, Room Room, float Rotation = 0)
            : base(Position, Vector2.Zero, TextureBin.GetTexture("Objects/tree"), Room)
        {
            this.Height = Height;

            // add in a random number of branches
            Random random = new Random();
            float  branchSeparationDistance = (Height - BRANCH_STARTING_HEIGHT) / numBranches;

            for (int i = 0; i < numBranches; i++)
            {
                // the side of the tree the branch is located on
                // 1 for left, 0 for right.
                int facing = random.Next(0, 1);

                Vector2 branchPosition = new Vector2(facing == 1 ? Position.X : Position.X + texture.Width,
                                                     i * branchSeparationDistance + BRANCH_STARTING_HEIGHT);
                branches.Add(new Tree(branchPosition, Height / 4, numBranches / 4, Room,
                                      rotation + (float)(facing == 1 ? BRANCH_ROTATION_MIN + MathHelper.TwoPi - MathHelper.PiOver2 + random.NextDouble() * BRANCH_ROTATION_MAX :
                                                         BRANCH_ROTATION_MIN + MathHelper.PiOver2 + random.NextDouble() * BRANCH_ROTATION_MAX)));
            }
        }