/// <summary>
 /// 初始化坦克攻击组件
 /// </summary>
 private void InitTankAttack(TankManager tank, TankModuleHead.AttackProperties properties)
 {
     tank.tankAttack = tank.gameObject.AddComponent(properties.attackScript.GetClass()) as TankAttack;
     tank.stateController.attackManager = tank.tankAttack;
     tank.tankAttack.forceSlider        = tank.GetComponent <TankManager>().aimSlider;
     tank.tankAttack.chargingClip       = properties.chargingClip;
     tank.tankAttack.fireClip           = properties.fireClip;
     tank.tankAttack.ResetSliderValue(properties.minLaunchForce, properties.maxLaunchForce, properties.maxChargeTime);
     tank.tankAttack.damage       = properties.damage;
     tank.tankAttack.coolDownTime = properties.coolDownTime;
     tank.tankAttack.CDTimer.Reset(properties.coolDownTime);
     System.Type type = tank.tankAttack.GetType();
     if (type == typeof(TankAttackShooting))
     {
         TankAttackShooting attack = tank.tankAttack as TankAttackShooting;
         attack.ammoPool       = head.attackProperties.ammoPool;
         attack.ammoSpawnPoint = new Point(head.ammoSpawnPoint);
     }
     else if (type == typeof(TankAttackBoxing))
     {
         TankAttackBoxing attack = tank.tankAttack as TankAttackBoxing;
         attack.springBoxingGlove = headObj.GetComponentInChildren <SpringBoxingGloveManager>();
         attack.launchDistance    = new AnimationCurve(new Keyframe(0, 0, 0, 3.5f), new Keyframe(0.3f, 1, 0, 0));
     }
 }
Example #2
0
 /// <summary>
 /// 初始化坦克攻击组件
 /// </summary>
 private void InitTankAttack(TankManager tank, TankModuleHead head)
 {
     TankModuleHead.AttackProperties properties = head.attackProperties;
     tank.tankAttack = tank.GetComponentInChildren <TankAttack>();
     if (tank.tankAttack == null)
     {
         Debug.LogError("Tank Head Need 'TankAttack' Component!");
         return;
     }
     tank.stateController.attackManager = tank.tankAttack;
     tank.stateController.defaultConfig = properties.aiConfig;
     tank.tankAttack.forceSlider        = tank.GetComponent <TankManager>().aimSlider;
     tank.tankAttack.chargingClip       = properties.chargingClip;
     tank.tankAttack.fireClip           = properties.fireClip;
     tank.tankAttack.ResetSliderValue(properties.minLaunchForce, properties.maxLaunchForce, properties.maxChargeTime);
     tank.tankAttack.damage       = properties.damage;
     tank.tankAttack.coolDownTime = properties.coolDownTime;
     tank.tankAttack.CDTimer.Reset(properties.coolDownTime);
     System.Type type = tank.tankAttack.GetType();
     if (type == typeof(TankAttackShooting))
     {
         TankAttackShooting attack = tank.tankAttack as TankAttackShooting;
         //attack.ammoPool = head.attackProperties.ammoPool;
         attack.ammoSpawnPoint = new Point(head.ammoSpawnPoint);
     }
     else if (type == typeof(TankAttackBoxing))
     {
         TankAttackBoxing attack = tank.tankAttack as TankAttackBoxing;
         attack.springBoxingGlove = headObj.GetComponentInChildren <SpringBoxingGloveManager>();
         attack.launchDistance    = new AnimationCurve(new Keyframe(0, 0, 0, 3.5f), new Keyframe(0.3f, 1, 0, 0));
     }
 }
    public override object Process(TankManager manager, object state = null)
    {
        AITankControllerState aiState = (AITankControllerState)state;

        if (aiState != null)
        {
            TankManager lastTarget = aiState.target;
            aiState.target = FindTarget(manager);

            if (aiState.target != null)
            {
                manager.GetComponent <Pathfinding.Seeker>().StartPath(manager.transform.position, aiState.target.transform.position, (Path p) => { aiState.currentPath = p; aiState.currentWaypoint = 0; Debug.Log("Ai found Path"); });
            }
            Debug.Log("Ai update");

            if (aiState.currentPath != null)
            {
                if (aiState.currentWaypoint >= aiState.currentPath.vectorPath.Count)
                {
                    manager.tankMovement.targetSpeed = 0;
                    return(aiState);
                }
                else
                {
                    Vector2 waypoint = aiState.currentPath.vectorPath[aiState.currentWaypoint];
                    if (Vector2.Distance(manager.transform.position, waypoint) <= 5)
                    {
                        aiState.currentWaypoint++;
                        return(aiState);
                    }

                    Vector2 direction = (waypoint - (Vector2)manager.transform.position).normalized;

                    manager.tankMovement.targetSpeed  = 1;
                    manager.tankMovement.targetVector = direction;
                }
            }

            return(aiState);
        }
        return(state);
    }
Example #4
0
    public override void OnTankHit(TankManager tank)
    {
        Vector2 direction = (gameObject.transform.position - tank.transform.position).normalized;

        tank.GetComponent <Rigidbody2D>().AddForce(-direction * 100, ForceMode2D.Impulse);
    }