Пример #1
0
    protected override void AddBaseComp()
    {
        base.AddBaseComp();
        MoveComp comp = AddComponent("MoveComp") as MoveComp;

        comp.Init(this, 0.02f);
    }
Пример #2
0
    private void SetLeader(GameObject go)
    {
        if (followMovementComponent != null)
        {
            return;
        }

        followMovementComponent = go.GetComponent <MovementComponent>();

        if (followMovementComponent == null)
        {
            return;
        }

        followMovementComponent.NewMove += OnNewDirection;
        MoveComp.Move(followMovementComponent.Target - followMovementComponent.transform.position, Settings.UnitMoveSpeed);
    }
Пример #3
0
    private void GetInPaddlock(Collider2D _paddlock)
    {
        if (InPaddock)
        {
            return;
        }

        InPaddock = true;
        followMovementComponent.NewMove -= OnNewDirection;
        followMovementComponent          = null;

        Vector3 position   = new Vector2();
        Vector2 correction = new Vector2(_paddlock.bounds.size.x * 0.3f, _paddlock.bounds.size.y * 0.3f);

        position.x = Random.Range(_paddlock.bounds.min.x + correction.x, _paddlock.bounds.max.x - correction.x);
        position.y = Random.Range(_paddlock.bounds.min.y + correction.y, _paddlock.bounds.max.y - correction.y);
        position.z = transform.position.z;

        MoveComp.Move(position - transform.position, Settings.UnitMoveSpeed);

        ApplicationManager.Instance.GameControl.NewCowCollected();
    }
Пример #4
0
 private void OnNewDirection(Vector3 direction)
 {
     MoveComp.Move(direction, Settings.UnitMoveSpeed);
 }
Пример #5
0
    public void SetNewMoveTarget(Vector3 target)
    {
        Vector3 direction = target - cashedTransform.position;

        MoveComp.Move(direction, Settings.UnitMoveSpeed);
    }
Пример #6
0
    public void DoCommand(BattleCommand command)
    {
        int entityId = command.EntityId;

        if (command.CommandType == BattleCommandType.Move)
        {
            EntitySetting setting    = EntitySetting.Setting[entityId];
            GameEntity    gameEntity = EntityMgr.Instance.GetGameEntity(entityId);
            MoveComp      moveComp   = gameEntity.GetComponent(GameComponentsLookup.MoveComp) as MoveComp;
            moveComp.DestPos   = command.MoveInfo.DestPos;
            moveComp.IsArrived = false;
            moveComp.Speed     = setting.MoveSpeed;
            moveComp.IsAniMove = false;
            moveComp.Forward   = Vector3.Normalize(moveComp.DestPos - moveComp.CurPos);

            BattleCommand command1 = new BattleCommand();
            command1.CommandType         = BattleCommandType.PlayAni;
            command1.EntityId            = entityId;
            command1.PlayAniInfo         = new BattleCommand.CommandPlayAniInfo();
            command1.PlayAniInfo.AniName = "walk";
            BattleLoop.Instance.AddCommand(command1);
        }
        else if (command.CommandType == BattleCommandType.PutSkill)
        {
            SkillSetting   setting    = SkillSetting.SkillSettingDict[command.PutSkillInfo.SkillId];
            GameEntity     gameEntity = EntityMgr.Instance.GetGameEntity(entityId);
            MoveComp       moveComp   = gameEntity.GetComponent(GameComponentsLookup.MoveComp) as MoveComp;
            PutedSkillInfo skillInfo  = new PutedSkillInfo();

            skillInfo.EntityId     = entityId;
            skillInfo.PutSkillTime = Time.time;
            skillInfo.SkillId      = command.PutSkillInfo.SkillId;

            moveComp.Speed     = 0.1f;
            moveComp.IsAniMove = false;
            moveComp.IsBlock   = false;

            if (setting.IsBlockWalk == true)
            {
                moveComp.DestPos   = moveComp.CurPos;
                moveComp.IsArrived = true;
            }

            if (setting.IsNeedAniMove == true)
            {
                moveComp.Speed     = 0.5f;
                moveComp.IsArrived = false;
                moveComp.IsAniMove = true;
                moveComp.DestPos   = moveComp.CurPos + moveComp.Forward * 3.0f;
            }

            if (setting.IsBulletShoot == true)
            {
                moveComp.IsBlock = true;
                Timer.Instance.AddTimer(BattleTimerName.BulletMove, () =>
                {
                    Contexts contexts = EntityMgr.Instance.GetContexts();
                    HashSet <GameEntity> gameEntities = contexts.game.GetEntitiesWithEntityInfoCompEntityType(EntityType.Monster);
                    int monsterId = 1;
                    float dist    = 10000.0f;
                    foreach (var item in gameEntities)
                    {
                        float diff = (item.moveComp.CurPos - gameEntity.moveComp.CurPos).sqrMagnitude;
                        if (diff < dist)
                        {
                            dist      = diff;
                            monsterId = item.entityInfoComp.Id;
                        }
                    }

                    if (monsterId != 1)
                    {
                        GameEntity bullet = EntityMgr.Instance.CreateBullet();
                        bullet.entityBulletMoveComp.CurPos       = gameEntity.moveComp.CurPos + new Vector3(0, 2.0f, 0);
                        bullet.entityBulletMoveComp.DestEntityId = monsterId;
                        mPutedSkillInfos.Insert(0, skillInfo);
                    }

                    moveComp.IsBlock = false;

                    if (gameEntity.moveComp.IsArrived == false)
                    {
                        BattleCommand command2       = new BattleCommand();
                        command2.CommandType         = BattleCommandType.PlayAni;
                        command2.EntityId            = entityId;
                        command2.PlayAniInfo         = new BattleCommand.CommandPlayAniInfo();
                        command2.PlayAniInfo.AniName = "walk";
                        BattleLoop.Instance.AddCommand(command2);
                    }
                }, 0.6f, false);
            }
            else
            {
                mPutedSkillInfos.Insert(0, skillInfo);
            }

            BattleCommand command1 = new BattleCommand();
            command1.CommandType         = BattleCommandType.PlayAni;
            command1.EntityId            = entityId;
            command1.PlayAniInfo         = new BattleCommand.CommandPlayAniInfo();
            command1.PlayAniInfo.AniName = setting.AniName;
            BattleLoop.Instance.AddCommand(command1);
        }
        else if (command.CommandType == BattleCommandType.PlayAni)
        {
            if (command.PlayAniInfo.AniName.Equals("attacked") == true)
            {
                GameEntity gameEntity = EntityMgr.Instance.GetGameEntity(entityId);
                gameEntity.moveComp.IsArrived = true;
                Timer.Instance.AddTimer(BattleTimerName.AttackedTimer, () =>
                {
                    if (gameEntity.hasEntityAiComp == true)
                    {
                        gameEntity.entityAiComp.IsAIEnded = true;
                    }
                }, 1.0f, false);
            }

            BattleRenderCommand renderCommand = new BattleRenderCommand();
            renderCommand.EntityId = entityId;
            renderCommand.AniName  = command.PlayAniInfo.AniName;
            BattleRenderMgr.Instance.AddCommand(renderCommand);
        }
    }