Ejemplo n.º 1
0
    public void Convert(Entity _entity, EntityManager dstManager, GameObjectConversionSystem _conversionSystem)
    {
        Translation t = new Translation();

        t.Value = new float3(0f, 0f, 0.0f);

        var moveData = new ObjectMoveData()
        {
            Speed     = 1.0f,
            Direction = t,
        };

        var playerData = new PlayerData()
        {
            Life          = m_life,
            PrevScreenPos = new float2(Screen.width * 0.5f, Screen.height * 0.5f),
        };
        var bulletFactoryData = new BulletFactoryData()
        {
            ParentEntity   = _entity,
            PositionOffset = float3.zero,
            RotationOffset = float3.zero,

            SpawnCycle = m_spawnCycle,
            SpawnTimer = m_spawnCycle,

            /* バレットパラメーター */
            Speed         = 0.1f,
            MoveDirection = new float3(0f, 0f, 1f),
            Damage        = 1,
            BulletType    = 0,
        };


        var bulletFactorySys = World.Active.GetOrCreateSystem <BulletFactorySystem>();

        if (bulletFactorySys != null)
        {
            Camera cam           = Camera.main;
            float  frustumHeight = cam.transform.position.y * Mathf.Tan(cam.fieldOfView * 0.5f * Mathf.Deg2Rad);
            float  frustumWidth  = frustumHeight / Screen.height * Screen.width;

            float maxSize = math.max(frustumHeight * 2.0f, frustumWidth * 2.0f);
            int   count   = BulletFactorySystem.CalcPreloadObjectCount(maxSize, bulletFactoryData.Speed, 1.0f, bulletFactoryData.SpawnCycle);

            bulletFactoryData.BulletListHandler = bulletFactorySys.CreateBulletObject(count, m_bulletObjectPrefab, "MyBullet");
        }

        dstManager.AddComponentData(_entity, moveData);
        dstManager.AddComponentData(_entity, playerData);
        dstManager.AddComponentData(_entity, bulletFactoryData);


        BulletCollisionSystem bulletSys = World.Active.GetOrCreateSystem <BulletCollisionSystem>();

        bulletSys.Initialize(_entity);

        GAME.UI.UISystemManager.I.SetPlayerEntity(_entity);

        World.Active.GetOrCreateSystem <BulletComponentSystem>().Initialize(Camera.main);
    }
Ejemplo n.º 2
0
    public void Convert(Entity _entity, EntityManager dstManager, GameObjectConversionSystem _conversionSystem)
    {
        Entity model = dstManager.Instantiate(GameObjectConversionUtility.ConvertGameObjectHierarchy(m_objectModel, World.Active));

        // Entity 管理に登録
        EnemyComponentSystem enemySys = World.Active.GetOrCreateSystem <EnemyComponentSystem>();
        int enemyId = enemySys.GetInstanceId();

        enemySys.AddEnemyEntity(enemyId, model);

        // Enemy の基本データ
        EnemyData enemyData = new EnemyData()
        {
            Id    = enemyId,
            HP    = m_hitPoint,
            Score = m_score
        };

        dstManager.AddComponentData(model, enemyData);
        Translation initPos = new Translation();

        initPos.Value = new float3(this.transform.position.x, this.transform.position.y, this.transform.position.z);
        dstManager.SetComponentData <Translation>(model, initPos);


        Translation t = new Translation();

        t.Value = new float3(0f, 0f, 0.0f);

        var moveData = new ObjectMoveData()
        {
            Speed     = 0.0f,
            Direction = t,
        };

        dstManager.AddComponentData(model, moveData);



        var    bulletFactorySys = World.Active.GetOrCreateSystem <BulletFactorySystem>();
        Camera cam           = Camera.main;
        float  frustumHeight = cam.transform.position.y * Mathf.Tan(cam.fieldOfView * 0.5f * Mathf.Deg2Rad);
        float  frustumWidth  = frustumHeight / Screen.height * Screen.width;

        float maxSize = math.max(frustumHeight * 2.0f, frustumWidth * 2.0f);

        for (int i = 0; i < m_nway; i++)
        {
            var factoryEntity     = dstManager.CreateEntity();
            var bulletFactoryData = new BulletFactoryData()
            {
                ParentEntity   = model,
                PositionOffset = float3.zero,
                RotationOffset = float3.zero,

                SpawnCycle = m_spawnCycle,
                SpawnTimer = m_spawnCycle,

                /* バレットパラメーター */
                Speed         = m_buleltSpeed,
                MoveDirection = CalcDirection(i, m_nway - 1, new float3(0f, 0f, -1f), m_angle),
                Damage        = 1,
                BulletType    = 1,
            };

            if (bulletFactorySys != null)
            {
                int count = BulletFactorySystem.CalcPreloadObjectCount(maxSize, bulletFactoryData.Speed, 1.0f, bulletFactoryData.SpawnCycle);
                bulletFactoryData.BulletListHandler = bulletFactorySys.CreateBulletObject(count, m_bulletModel);

                dstManager.AddComponentData(factoryEntity, bulletFactoryData);

                // Enemy 管理システムにも登録
                enemySys?.AddBulletFactoryRelation(enemyData.Id, factoryEntity);
            }
        }
    }