Пример #1
0
        public QuadTree(float3 bounds, Entity entity)
        {
            this.bounds = bounds;
            int maxSprites = SpriteSheetCache.GetLength("emoji");

            if (entity == Entity.Null)
            {
                var color = UnityEngine.Random.ColorHSV(.35f, .85f);
                List <IComponentData> components = new List <IComponentData> {
                    new Position2D {
                        Value = bounds.xy
                    },
                    new Scale {
                        Value = bounds.z
                    },
                    new SpriteIndex {
                        Value = UnityEngine.Random.Range(0, maxSprites)
                    },
                    new SpriteSheetAnimation {
                        frameCount = maxSprites, playMode = PlayMode.Loop, framesPerSecond = 10
                    },
                    new SpriteSheetColor {
                        color = new float4(color.r, color.g, color.b, color.a)
                    }
                };
                this.entity = SpriteSheetManager.Instantiate(FractalInitializer.archetype, components, "emoji");
            }
            else
            {
                this.entity = entity;
                UpdateEntityMatrix();
            }
        }
Пример #2
0
        void Update()
        {
            if (Input.GetKeyDown(KeyCode.Space))
            {
                int maxSprites = SpriteSheetCache.GetLength(spriteSheetName);
                var color      = UnityEngine.Random.ColorHSV(.35f, .85f);

                // 3) Populate components
                List <IComponentData> components = new List <IComponentData> {
                    new Position2D {
                        Value = UnityEngine.Random.insideUnitCircle * 7
                    },
                    new Scale {
                        Value = UnityEngine.Random.Range(0, 3f)
                    },
                    new SpriteIndex {
                        Value = UnityEngine.Random.Range(0, maxSprites)
                    },
                    new SpriteSheetAnimation {
                        frameCount = maxSprites, playMode = PlayMode.Loop, framesPerSecond = 10
                    },
                    new SpriteSheetColor {
                        color = new float4(color.r, color.g, color.b, color.a)
                    },
                    new LifeTime {
                        Value = UnityEngine.Random.Range(5, 15)
                    }
                };

                SpriteSheetManager.Instantiate(archetype, components, spriteSheetName);
            }
        }
Пример #3
0
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Space))
        {
            int maxSprites = SpriteSheetCache.GetLength("emoji");
            var color      = UnityEngine.Random.ColorHSV(.35f, .85f);

            // 3) Populate components
            List <IComponentData> components = new List <IComponentData> {
                new Position2D {
                    Value = UnityEngine.Random.insideUnitCircle * 7
                },
                new Scale {
                    Value = UnityEngine.Random.Range(0, 3f)
                },
                new SpriteIndex {
                    Value = UnityEngine.Random.Range(0, maxSprites)
                },
                new SpriteSheetAnimation {
                    maxSprites = maxSprites, play = true, repetition = SpriteSheetAnimation.RepetitionType.Loop, samples = 10
                },
                new SpriteSheetColor {
                    color = new float4(color.r, color.g, color.b, color.a)
                },
                new LifeTime {
                    Value = UnityEngine.Random.Range(5, 15)
                }
            };

            SpriteSheetManager.Instantiate(archetype, components, "emoji");
        }
    }
Пример #4
0
        public void Convert(Entity entity, EntityManager eManager, GameObjectConversionSystem conversionSystem)
        {
            EntityArchetype archetype = eManager.CreateArchetype(
                typeof(Position2D),
                typeof(Rotation2D),
                typeof(Scale),
                //required params
                typeof(SpriteIndex),
                typeof(SpriteSheetAnimation),
                typeof(SpriteSheetMaterial),
                typeof(SpriteSheetColor),
                typeof(SpriteMatrix),
                typeof(BufferHook)
                );

            NativeArray <Entity> entities = new NativeArray <Entity>(spriteCount, Allocator.Temp);

            eManager.CreateEntity(archetype, entities);

            //only needed for the first time to bake the material and create the uv map
            SpriteSheetManager.RecordSpriteSheet(sprites, "emoji", entities.Length);


            Rect   area                  = GetSpawnArea();
            Random rand                  = new Random((uint)UnityEngine.Random.Range(0, int.MaxValue));
            int    cellCount             = SpriteSheetCache.GetLength("emoji");
            SpriteSheetMaterial material = new SpriteSheetMaterial {
                material = SpriteSheetCache.GetMaterial("emoji")
            };

            for (int i = 0; i < entities.Length; i++)
            {
                Entity e = entities[i];
                eManager.SetComponentData(e, new SpriteIndex {
                    Value = rand.NextInt(0, cellCount)
                });
                eManager.SetComponentData(e, new Scale {
                    Value = 10
                });
                eManager.SetComponentData(e, new Position2D {
                    Value = rand.NextFloat2(area.min, area.max)
                });
                eManager.SetComponentData(e, new SpriteSheetAnimation {
                    maxSprites = cellCount, play = true, repetition = SpriteSheetAnimation.RepetitionType.Loop, samples = 10
                });
                var color            = UnityEngine.Random.ColorHSV(.15f, .75f);
                SpriteSheetColor col = new SpriteSheetColor {
                    color = new float4(color.r, color.g, color.b, color.a)
                };
                eManager.SetComponentData(e, col);
                eManager.SetComponentData(e, new BufferHook {
                    bufferID = i, bufferEnityID = DynamicBufferManager.GetEntityBufferID(material)
                });
                eManager.SetSharedComponentData(e, material);
            }
        }
        public void Convert(Entity entity, EntityManager eManager, GameObjectConversionSystem conversionSystem)
        {
            // 1) Create Archetype
            EntityArchetype archetype = eManager.CreateArchetype(
                typeof(Position2D),
                typeof(Rotation2D),
                typeof(Scale),
                //required params
                typeof(SpriteIndex),
                typeof(SpriteSheetAnimation),
                typeof(SpriteSheetMaterial),
                typeof(SpriteSheetColor),
                typeof(SpriteMatrix),
                typeof(BufferHook)
                );

            // 2) Record and bake this spritesheet(only once)
            SpriteSheetManager.RecordSpriteSheet(sprites, spriteSheetName);

            int maxSprites = SpriteSheetCache.GetLength(spriteSheetName);
            var color      = UnityEngine.Random.ColorHSV(.35f, .85f);

            // 3) Populate components
            List <IComponentData> components = new List <IComponentData> {
                new Position2D {
                    Value = float2.zero
                },
                new Scale {
                    Value = 15
                },
                new SpriteIndex {
                    Value = UnityEngine.Random.Range(0, maxSprites)
                },
                new SpriteSheetAnimation {
                    frameCount = maxSprites, playMode = PlayMode.Loop, framesPerSecond = 10
                },
                new SpriteSheetColor {
                    color = new float4(color.r, color.g, color.b, color.a)
                }
            };

            // 4) Instantiate the entity
            _ = SpriteSheetManager.Instantiate(archetype, components, spriteSheetName);
        }