Ejemplo n.º 1
0
 public void UpdateGrid(GameEntity entity)
 {
     if (entity.hasTransform)
     {
         var sceenPoint = DirectorUtil.WorldPointInScreen(entity.transform.position);
         m_grid.Update(entity, (int)(sceenPoint.x), (int)(sceenPoint.y));
     }
 }
Ejemplo n.º 2
0
        private EntityCache()
        {
            var sceenRect = DirectorUtil.GetScreenRect();

            m_grid = new Grid2D <GameEntity>();
            m_grid.Init(6, 6, (int)sceenRect.width, (int)sceenRect.height);

            heroMap = new Dictionary <EPlayerType, GameEntity>();
        }
Ejemplo n.º 3
0
        protected override GameEntity OnCreate(string code)
        {
            var entity = CreateGameEntity(code);

            var mobDataCom = entity.CreateComponent <MobDataComponent>(GameComponentsLookup.MobData);
            var healthCom  = entity.CreateComponent <HealthComponent>(GameComponentsLookup.Health);
            var recycleCom = entity.CreateComponent <RecycleComponent>(GameComponentsLookup.Recycle);

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

                {
                    recycleCom.maxStayTime = 3f;
                    recycleCom.stayTime    = 0f;
                    recycleCom.isRecycled  = false;
                    recycleCom.boundary    = DirectorUtil.ScreenRectInWorld(DirectorUtil.GetScreenRect());
                }

                {
                    healthCom.blood         = healthCom.maxBlood;
                    healthCom.trueDeathTime = -1f;
                    healthCom.isTrueDied    = false;
                }

                {
                    entity.collider.obj.data = entity;
                    entity.collider.tag      = ColliderType.Mob;
                    entity.collider.mask     = 0;//不碰撞其他
                    entity.collider.obj.AddShape(new CircleCollider()
                    {
                        radius = 0.1f
                    });
                }
            }

            entity.AddComponent(GameComponentsLookup.MobData, mobDataCom);
            entity.AddComponent(GameComponentsLookup.Health, healthCom);
            entity.AddComponent(GameComponentsLookup.Recycle, recycleCom);
            return(entity);
        }
Ejemplo n.º 4
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();
                }
            }
        }
Ejemplo n.º 5
0
        public List <GameEntity> GetGridEntities(GameEntity entity)
        {
            var sceenPoint = DirectorUtil.WorldPointInScreen(entity.transform.position);

            return(m_grid.GetByPosition((int)(sceenPoint.x), (int)(sceenPoint.y)));
        }
Ejemplo n.º 6
0
        protected override GameEntity OnCreate(string code)
        {
            var entity        = CreateGameEntity(code);
            var bulletDataCom = entity.CreateComponent <BulletDataComponent>(GameComponentsLookup.BulletData);

            var healthCom  = entity.CreateComponent <HealthComponent>(GameComponentsLookup.Health);
            var recycleCom = entity.CreateComponent <RecycleComponent>(GameComponentsLookup.Recycle);

            entity.AddComponent(GameComponentsLookup.BulletData, bulletDataCom);
            entity.AddComponent(GameComponentsLookup.Health, healthCom);
            entity.AddComponent(GameComponentsLookup.Recycle, recycleCom);

            if (entity.hasEntityData)
            {
                entity.movement.moveSpeed.y = entity.entityData.entityData["speed"].ToFloat();
                entity.view.view            = ComponentUtil.CreateView(entity);
                entity.ReplaceComponent(GameComponentsLookup.View, entity.view);

                {
                    recycleCom.maxStayTime = 1f;
                    recycleCom.stayTime    = 0f;
                    recycleCom.isRecycled  = false;
                    //用的是左下角为起点
                    recycleCom.boundary = DirectorUtil.ScreenRectInWorld(DirectorUtil.GetScreenRect());
                }

                {
                    healthCom.blood         = healthCom.maxBlood;
                    healthCom.trueDeathTime = -1f;
                    healthCom.isTrueDied    = false;
                }

                {
                    entity.collider.obj.data = entity;
                    entity.collider.obj.AddShape(new CircleCollider()
                    {
                        radius = 0.1f
                    });
                }

                //TODO:先简单通过种类区分阵营
                var campType = (ECampType)entity.entityData.entityData["category"].ToInt();
                if (campType == ECampType.Hero)
                {
                    var heroBulletFlagCom = entity.CreateComponent <HeroBulletFlagComponent>(GameComponentsLookup.HeroBulletFlag);

                    {
                        entity.collider.tag  = ColliderType.HeroBullet;
                        entity.collider.mask = ColliderType.Mob | ColliderType.Boss;
                    }

                    entity.AddComponent(GameComponentsLookup.HeroBulletFlag, heroBulletFlagCom);
                }
                else if (campType == ECampType.Entity)
                {
                    var entityBulletFlagCom = entity.CreateComponent <EntityBulletFlagComponent>(GameComponentsLookup.EntityBulletFlag);

                    {
                        entity.collider.tag  = ColliderType.EntityBullet;
                        entity.collider.mask = 0;
                    }

                    entity.AddComponent(GameComponentsLookup.EntityBulletFlag, entityBulletFlagCom);
                }
                entity.bulletData.campType = campType;
            }
            return(entity);
        }