Exemple #1
0
 protected override void OnCreateManager()
 {
     base.OnCreateManager();
     Assert.IsFalse(float_resource_.IsCreated);
     float_resource_ = new AtomicFloatResource(1024, Allocator.Persistent);
     random_         = RandomMaker.create();
     stopwatch_      = new System.Diagnostics.Stopwatch();
     stopwatch_.Start();
 }
Exemple #2
0
        public void spawn(ref float3 position,
                          ref quaternion rotation,
                          ref RandomLocal random,
                          ref AtomicFloatResource float_resource)
        {
            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,
            });
            entity_manager.SetComponentData(entity, new Rotation {
                Value = rotation,
            });
            entity_manager.SetComponentData(entity, new RigidbodyRotation(10f /* damper */));
            entity_manager.SetComponentData(entity, random.create());
            entity_manager.SetComponentData(entity, new SphereCollider {
                offset_position_ = new float3(0f, 0f, 0f),
                radius_          = 1f,
            });
            entity_manager.SetComponentData(entity, AlivePeriod.Create(Time.GetCurrent(), 6f /* period */));
            var enemy = Enemy.Create(ref float_resource);

            entity_manager.SetComponentData(entity, enemy);
            entity_manager.SetComponentData(entity, new Zako {
                target_position_ = new float3(random.range(-20f, 20f), random.range(-20f, 20f), 0f),
            });
            entity_manager.SetComponentData(entity, new MeshRenderBounds {
                Center = new float3(0f, 0f, 0f), Radius = 0.5f,
            });
            var renderer = new MeshInstanceRenderer {
                mesh           = mesh_,
                material       = material_,
                subMesh        = 0,
                castShadows    = UnityEngine.Rendering.ShadowCastingMode.On,
                receiveShadows = true,
            };

            entity_manager.SetSharedComponentData(entity, renderer);

            for (var i = 0; i < locktarget_list_.Length; ++i)
            {
                LockTargetManager.CreateEntity(entity_manager,
                                               locktarget_list_[i].localPosition,
                                               locktarget_list_[i].localRotation,
                                               ref enemy.life_,
                                               entity,
                                               ref random);
            }
        }
        public static Player Create(Entity cursor_entity, ref AtomicFloatResource float_resource)
        {
            var player = new Player {
                pitch_acceleration_ = 0f,
                pitch_velocity_     = 0f,
                pitch_             = 0f,
                roll_              = 0f,
                roll_target_       = 0f,
                cursor_forceXY_    = new float2(0f, 0f),
                cursor_entity_     = cursor_entity,
                fire_bullet_time_  = CV.MaxValue,
                fire_bullet_count_ = 0,
                life_              = float_resource.Create(PLAYER_INITIAL_LIFE),
            };

            return(player);
        }
        public Entity spawn(ref Vector3 position, ref Quaternion rotation, ref AtomicFloatResource float_resource)
        {
            Assert.IsTrue(player_spawn_idx_ < PLAYER_MAX);

            var entity_manager = Unity.Entities.World.Active.GetOrCreateManager <Unity.Entities.EntityManager>();

            var player_entity = entity_manager.CreateEntity(player_archetype_);

            entity_manager.SetComponentData(player_entity, new Position {
                Value = position,
            });
            entity_manager.SetComponentData(player_entity, new Rotation {
                Value = rotation,
            });
            float radius = CV.MAX_RADIUS - CV.PLAYER_WIDTH_HALF;

            entity_manager.SetComponentData(player_entity, new RigidbodyPosition {
                damper_ = 12f, limit_xy_tube_radius_ = radius,
            });
            entity_manager.SetComponentData(player_entity, new SphereCollider {
                offset_position_ = new float3(0f, 0f, 0f),
                radius_          = 1f,
            });
            entity_manager.SetComponentData(player_entity, new PlayerControllerIndex(0 /* index */));
            var renderer = new MeshInstanceRenderer {
                mesh           = mesh_,
                material       = material_,
                subMesh        = 0,
                castShadows    = UnityEngine.Rendering.ShadowCastingMode.On,
                receiveShadows = true,
                // camera = camera_,
            };

            entity_manager.SetSharedComponentData(player_entity, renderer);

            var cursor_entity   = entity_manager.CreateEntity(cursor_archetype_);
            var cursor_position = new Vector3(position.x, position.y, position.z + 32f);

            entity_manager.SetComponentData(cursor_entity, new Position {
                Value = cursor_position,
            });
            entity_manager.SetComponentData(cursor_entity, new RigidbodyPosition(32f /* damper */));
            entity_manager.SetComponentData(cursor_entity, new LocalToWorld {
                Value = float4x4.identity,
            });
            entity_manager.SetComponentData(cursor_entity, Cursor.Create(player_entity));

            entity_manager.SetComponentData(player_entity, Player.Create(cursor_entity, ref float_resource)); // bidirectional reference.

            {
                var burner_entity = entity_manager.CreateEntity(burner_archetype_);
                entity_manager.SetComponentData(burner_entity, new Position {
                    Value = new float3(0.35f, 0.1f, -0.8f),
                });
                // entity_manager.SetComponentData(burner_entity, new Rotation { Value = quaternion.identity, });
                entity_manager.SetComponentData(burner_entity, new TrailData {
                    color_type_ = (int)TrailManager.ColorType.Cyan,
                });
                var buffer = entity_manager.GetBuffer <TrailPoint>(burner_entity);
                for (var i = 0; i < buffer.Capacity; ++i)
                {
                    buffer.Add(new TrailPoint {
                        position_ = position, normal_ = new float3(0f, 0f, 1f),
                    });
                }
                entity_manager.SetSharedComponentData(burner_entity, new TrailRenderer {
                    material_ = TrailManager.Instance.getMaterial(),
                });
                var attach_entity = entity_manager.CreateEntity(typeof(Attach));
                entity_manager.SetComponentData(attach_entity, new Attach {
                    Parent = player_entity, Child = burner_entity,
                });
            }
            {
                var burner_entity = entity_manager.CreateEntity(burner_archetype_);
                entity_manager.SetComponentData(burner_entity, new Position {
                    Value = new float3(-0.35f, 0.1f, -0.8f),
                });
                // entity_manager.SetComponentData(burner_entity, new Rotation { Value = quaternion.identity, });
                entity_manager.SetComponentData(burner_entity, new TrailData {
                    color_type_ = (int)TrailManager.ColorType.Cyan,
                });
                var buffer = entity_manager.GetBuffer <TrailPoint>(burner_entity);
                for (var i = 0; i < buffer.Capacity; ++i)
                {
                    buffer.Add(new TrailPoint {
                        position_ = position, normal_ = new float3(0f, 0f, 1f),
                    });
                }
                entity_manager.SetSharedComponentData(burner_entity, new TrailRenderer {
                    material_ = TrailManager.Instance.getMaterial(),
                });
                var attach_entity = entity_manager.CreateEntity(typeof(Attach));
                entity_manager.SetComponentData(attach_entity, new Attach {
                    Parent = player_entity, Child = burner_entity,
                });
            }

            ++player_spawn_idx_;

            return(player_entity);
        }
 public static Enemy Create(ref AtomicFloatResource float_resource)
 {
     return(new Enemy {
         life_ = float_resource.Create(5f),
     });
 }