Exemple #1
0
        //初始化组件
        protected override void OnInit(GameEntity entity)
        {
            if (entity.hasEntityData)
            {
                var heroType = EntityUtil.GetHeroTypeByCode(entity.entityData.entityCode);
                entity.playerData.heroType = heroType;

                {
                    entity.view.view = ComponentUtil.CreateView(entity);
                    entity.ReplaceComponent(GameComponentsLookup.View, entity.view);
                }

                {
                    entity.cage.movableArea = DirectorUtil.ScreenRectInWorld(DirectorUtil.GetScreenRect());
                    entity.cage.bodySize    = DirectorUtil.ScreenSizeInWorld(entity.entityData.entityData["hitBox"].ToVector3());
                }

                {
                    entity.health.maxNearDeathTime = 1f;
                    entity.health.blood            = entity.health.maxBlood;
                    entity.health.trueDeathTime    = -1f;
                    entity.health.isTrueDied       = false;
                }

                {
                    entity.collider.tag      = ColliderType.Hero;
                    entity.collider.mask     = ColliderType.Mob | ColliderType.Boss | ColliderType.EntityBullet | ColliderType.Prop;
                    entity.collider.obj.data = entity;
                    entity.collider.obj.AddShape(new CircleCollider
                    {
                        radius = 0.1f
                    });
                }

                entity.playerData.moveSpeed = entity.entityData.entityData["speed"].ToFloat();
                entity.health.maxBlood      = entity.entityData.entityData["blood"].ToInt();

                //不同主角特有的
                if (heroType == EHeroType.Reimu)
                {
                    List <GameEntity> wingmans = new List <GameEntity>();
                    //Reimu持有僚机total台: onmyougyoku
                    float[] d     = { -0.3f, 0.3f };
                    int     total = 2;
                    for (int i = 0; i < total; i++)
                    {
                        var onmyougyokuWingman = EntityManager.GetInstance().GetOrNewEntityFactory(EEntityType.Wingman).AsWingman().CreateWingman(EWingmanType.Onmyougyoku);
                        if (onmyougyokuWingman.hasEntityData)
                        {
                            onmyougyokuWingman.onmyougyokuWingman.id    = i;
                            onmyougyokuWingman.movement.rotationSpeed.z = 100f;                                       //自旋
                            onmyougyokuWingman.transform.parent         = entity.transform;
                            onmyougyokuWingman.transform.localPosition  = new Vector3(d[i], 0.3f, 0);                 //偏移一点
                            onmyougyokuWingman.view.view.Scale          = new System.Numerics.Vector3(0.7f, 0.7f, 1); //缩小一点

                            wingmans.Add(onmyougyokuWingman);
                        }
                    }

                    entity.playerData.wingmans = wingmans.ToArray();
                }
            }
        }