Esempio n. 1
0
 public static Vector2 Inside(this IRandomProvider random, Rect rect)
 {
     return(rect.position + new Vector2
            (
                x: random.Between(0f, rect.width),
                y: random.Between(0f, rect.height)
            ));
 }
        protected override void ExecuteSubtask(int execID, int index)
        {
            Vector3 position = random.Inside(spawnArea);
            Vector3 velocity = Vector3.forward * random.Between(10f, 15f);

            var entity = context.CreateEntity();

            context.SetComponent(entity, new TransformComponent(Float3x4.FromPosition(position)));
            context.SetComponent(entity, new VelocityComponent(velocity: velocity));
            context.SetComponent(entity, new GraphicComponent(graphicID: 0));
            context.SetComponent(entity, new AgeComponent());
            context.SetComponent(entity, new LifetimeComponent(totalLifetime: random.Between(30f, 35f)));
            context.SetComponent(entity, new ColliderComponent(size: new Vector3(3, 2, 3)));
            context.SetTag <SpaceshipTag>(entity);
        }
Esempio n. 3
0
        public static T PickRandom <T>(this IRandomProvider random, IReadOnlyList <T> list)
        {
            if (list.Count == 0)
            {
                return(default(T));
            }
            int index = random.Between(0, list.Count);

            return(list[index]);
        }
Esempio n. 4
0
 public static int Between(this IRandomProvider random, int minValue, int maxValue)
 {
     return(Mathf.FloorToInt(random.Between((float)minValue, (float)maxValue)));
 }