Esempio n. 1
0
        void spawn(ref float3 position, TrailManager.ColorType coltype, Entity parent)
        {
            var entity_manager = Unity.Entities.World.Active.GetOrCreateManager <Unity.Entities.EntityManager>();
            var entity         = entity_manager.CreateEntity(archetype_);

            entity_manager.SetComponentData(entity, new Position {
                Value = position,
            });
            var td = new TrailData();

            td.color_type_ = (int)coltype;
            entity_manager.SetComponentData(entity, td);
            {
                var buffer = entity_manager.GetBuffer <TrailPoint>(entity);
                for (var i = 0; i < buffer.Capacity; ++i)
                {
                    buffer.Add(new TrailPoint {
                        position_ = position, normal_ = new float3(0f, 0f, 1f),
                    });
                }
            }
            var renderer = new TrailRenderer {
                material_ = TrailManager.Instance.getMaterial(),
            };

            entity_manager.SetSharedComponentData <TrailRenderer>(entity, renderer);

            var attach = entity_manager.CreateEntity(typeof(Attach));

            entity_manager.SetComponentData(attach, new Attach {
                Parent = parent, Child = entity,
            });
        }
Esempio n. 2
0
        public void spawn_internal(EntityCommandBuffer.Concurrent command_buffer,
                                   ref LockTarget lt,
                                   ref float3 position,
                                   ref quaternion rotation,
                                   ref RandomLocal random,
                                   int index,
                                   Entity target,
                                   float arrive_period,
                                   int job_index)
        {
            command_buffer.CreateEntity(job_index, archetype_);
            command_buffer.SetComponent(job_index, new Position {
                Value = position,
            });
            command_buffer.SetComponent(job_index, new LaserData {
                end_time_      = CV.MaxValue,
                target_entity_ = target,
                arrive_period_ = arrive_period,
                lock_target_   = lt,
            });
            var         rb            = new RigidbodyPosition(0f /* damper */);
            const float FIRE_VEL      = 8f;
            var         fire_velocity = new float3(index % 2 == 0 ? FIRE_VEL * 2f : -FIRE_VEL * 2f,
                                                   random.range(-FIRE_VEL, FIRE_VEL),
                                                   random.range(-FIRE_VEL, FIRE_VEL));

            rb.velocity_ = math.mul(rotation, fire_velocity);
            command_buffer.SetComponent(job_index, rb);
            var td = new TrailData {
                color_type_ = (int)TrailManager.ColorType.Green,
            };

            command_buffer.SetComponent(job_index, td);

            {
                var buffer = command_buffer.SetBuffer <TrailPoint>(job_index);
                for (var i = 0; i < buffer.Capacity; ++i)
                {
                    buffer.Add(new TrailPoint {
                        position_ = position, normal_ = new float3(0f, 0f, 1f),
                    });
                }
            }

            var material = TrailManager.Instance.getMaterial();
            var renderer = new TrailRenderer {
                material_ = material,
            };

            command_buffer.SetSharedComponent <TrailRenderer>(job_index, renderer);
        }