private void InitComponent(EnemyData data, EnemyType type, Sprite sprite, ITrajectoryData trajectoryData)
    {
        //更新飞机图片
        Renderer = gameObject.AddOrGet <RenderComponent>();
        Renderer.Init();
        Renderer.SetSprite(sprite);
        //路径初始化
        _path = new PathMgr();
        _path.Init(transform, data, trajectoryData);

        gameObject.AddOrGet <CameraMove>().enabled = _path.NeedMoveWithCamera();
        gameObject.AddOrGet <AutoDespawnComponent>();
        gameObject.AddOrGet <EnemyTypeComponent>().Init(type);
        var lifeC = gameObject.AddOrGet <LifeComponent>();

        lifeC.Init(data.life);
        gameObject.AddOrGet <EnemyBehaviour>().Init(data);
        _moveComponent = gameObject.AddOrGet <MoveComponent>();
        _moveComponent.Init((float)data.speed);
        gameObject.AddOrGet <ColliderComponent>();
        gameObject.AddOrGet <PlaneCollideMsgComponent>();
        var bulletMgr = transform.Find("BulletRoot").AddOrGet <EnemyBulletMgr>();

        bulletMgr.Init(data);

        if (_lifeView == null)
        {
            var lifeGo = LoadMgr.Single.LoadPrefabAndInstantiate(Paths.PREFAB_ENEMY_LIFE, transform);
            _lifeView = lifeGo.AddComponent <EnemyLifeView>();
        }

        _lifeView.Init();
    }
Exemple #2
0
 public void AddComponent(RenderComponent cmp)
 {
     components.Add(cmp);
     cmp.renderManager = this;
     cmp.Init();
 }