コード例 #1
0
    //显示一个一开始沿直线运动进入屏幕,然后在屏幕某一点停住的敌人

    /* prefab: 构造敌人用到的prefab
    ** count: 显示的敌人的数量
    ** birthPosition:敌人出现的位置
    ** anchorPoint:敌人停驻的位置
    */
    private void ShowEnterAnchorEnemies(GameObject prefab, int count, Vector3 birthPosition, Vector3 anchorPoint, float speed = 1f, BulletType type = BulletType.LAZER_BULLET)
    {
        MovementArg arg = new MovementArg();

        arg.positionArg = anchorPoint;
        arg.speed       = speed;
        arg.bulletType  = type;
        arg.type        = MovementType.ENTER_ANCHOR_MOVEMENT;
        GenerateEnemyHelpr.GenerateEnterAnchorEnemies(prefab, count, birthPosition, arg, enemyParent, this);
    }
コード例 #2
0
    //一下三个方法为创建并显示一个特定类型的敌人,包装后可以方便其他组员编写其各自的关卡逻辑

    //显示一个运动路线为直线的敌人(水平,垂直或者斜线)
    //根据birthPosition和direction可以确定运动的轨迹(两点确定一条直线)

    /* prefab: 构造敌人用到的prefab
    ** count: 显示的敌人的数量
    ** birthPosition:敌人出现的位置
    ** direction: 敌人运动的方向,与birthPosition共同确定
    */
    private void ShowLineMovementEnemies(GameObject prefab, int count, Vector3 birthPosition, Vector3 direction, float speed = 1f, BulletType type = BulletType.LAZER_BULLET)
    {
        MovementArg arg = new MovementArg();

        arg.positionArg = direction;
        arg.speed       = speed;
        arg.bulletType  = type;
        arg.type        = MovementType.LINE_MOVEMENT;
        GenerateEnemyHelpr.GenerateLineEnemies(prefab, count, birthPosition, arg, enemyParent, this);
    }
コード例 #3
0
    //显示一个按照V字形运动的敌人:先直线进入屏幕,然后停住一段时间,然后再按照另一条直线离开屏幕

    /* prefab: 构造敌人用到的prefab
    ** count: 显示的敌人的数量
    ** birthPosition:敌人出现的位置
    ** turningPoint: 敌人停驻的位置
    ** anchorTime:敌人停驻的时间长短
    */
    private void ShowVeeMovementEnemies(GameObject prefab, int count, Vector3 birthPosition, Vector3 turningPoint, float anchorTime, float speed = 1f, BulletType type = BulletType.LAZER_BULLET)
    {
        MovementArg arg = new MovementArg();

        arg.positionArg = turningPoint;
        arg.anchorTime  = anchorTime;
        arg.speed       = speed;
        arg.bulletType  = type;
        arg.type        = MovementType.VEE_MOVEMENT;
        GenerateEnemyHelpr.GenerateVeeEnemies(prefab, count, birthPosition, arg, enemyParent, this);
    }
コード例 #4
0
    //一架敌机被构造出来后,该方法将会被调用,在里面设置敌机的移动参数
    void StartMove(MovementArg arg)
    {
        speed = arg.speed;
        shotController.setBulletType(arg.bulletType);
        switch (arg.type)
        {
        case MovementType.LINE_MOVEMENT:
            LineMovement(arg.positionArg);
            break;

        case MovementType.VEE_MOVEMENT:
            VeeMovement(arg.positionArg, arg.anchorTime);
            break;

        case MovementType.ENTER_ANCHOR_MOVEMENT:
            EnterAnchorMovement(arg.positionArg);
            break;
        }
    }
コード例 #5
0
 private static IEnumerator GenerateEnemies(GameObject prefab, int count, Vector3 birthPosition, MovementArg arg, GameObject parent, float gapTime)
 {
     for (int i = 0; ;)
     {
         GameObject enemy = GeneratorHelper.GeneratorGameObject(birthPosition, prefab, parent);
         enemy.SendMessage("StartMove", arg);
         i++;
         if (i < count)
         {
             yield return(new WaitForSeconds(gapTime));
         }
         else
         {
             break;
         }
     }
 }
コード例 #6
0
 public static void GenerateVeeEnemies(GameObject prefab, int count, Vector3 birthPosition, MovementArg arg, GameObject parent, MonoBehaviour behaviour)
 {
     behaviour.StartCoroutine(GenerateEnemies(prefab, count, birthPosition, arg, parent, 0.3f));
 }