Exemple #1
0
    // Use this for initialization
    void Start()
    {
        BtlMgr      btlMgr      = Global.Instance.btlMgr;
        BtlPlaneMgr btlPlaneMgr = btlMgr.btlPlaneMgr;

        {
            #region 加载用户飞机
            BtlPlane plane = btlPlaneMgr.btlPlaneUser;
            plane.xmlPlane = Global.Instance.xmlPlaneMgr.Find(1);

            plane.camp     = EnumCamp.Blue;
            plane.isVisble = true;
            plane.hpMax    = 1000;
            plane.hp       = plane.hpMax;
            GameObject planePrefabs = (GameObject)Resources.Load(plane.xmlPlane.prefabs);
            if (null == planePrefabs)
            {
                Debug.LogErrorFormat("BtlFG未找到{0}", plane.xmlPlane.prefabs);
            }
            Vector3 newPosition = transform.position;
            newPosition.x = 0;
            newPosition.y = -Camera.main.orthographicSize;

            plane.gameObject = Instantiate(planePrefabs, newPosition, transform.rotation);
            plane.gameObject.transform.SetParent(transform);
            plane.gameObject.layer = (int)EnumLayer.User;


            Rigidbody2D rigidbody2D = plane.gameObject.AddComponent <Rigidbody2D>();
            //无引力
            rigidbody2D.gravityScale = 0;
            BoxCollider2D boxCollider2D = plane.gameObject.AddComponent <BoxCollider2D>();
            boxCollider2D.isTrigger = true;

            //移动速度
            plane.btlMove.speed = new Vector2(plane.xmlPlane.speedX, plane.xmlPlane.speedY);

            BtlUserMove btlUserMove = plane.gameObject.AddComponent <BtlUserMove>();
            btlUserMove.parent = plane;

            BtlHit btlHit = plane.gameObject.AddComponent <BtlHit>();
            btlHit.parent = plane;

            BtlUserEnterScene battleUserEnterScene = plane.gameObject.AddComponent <BtlUserEnterScene>();
            battleUserEnterScene.parent = plane;

            //加载子弹
            foreach (var v in plane.xmlPlane.bulletList)
            {
                XmlBullet xmlBullet = Global.Instance.xmlBulletMgr.Find(v);

                plane.btlBulletMgr.Add(xmlBullet);
                BtlFire btlFire = plane.gameObject.AddComponent <BtlFire>();
                btlFire.parent = plane;
            }
            #endregion
        }
        {
            #region 加载飞机的闪电特效
            BtlPlane userPlane = Global.Instance.btlMgr.GetUserPlane();

            {
                GameObject prefabs = (GameObject)Resources.Load("Prefabs/Anim/p_09d_36");
                if (null == prefabs)
                {
                    Debug.LogErrorFormat("Prefabs/Anim/p_09d_36未找到");
                }
                GameObject gameObject = Instantiate(prefabs, userPlane.gameObject.transform.position, userPlane.gameObject.transform.rotation);
                gameObject.transform.SetParent(userPlane.gameObject.transform);
                gameObject.layer = (int)EnumLayer.User;
            }
            #endregion
        }
    }
Exemple #2
0
    //敌机入场
    private void EnemyFly()
    {
        #region 判断玩家飞机是否入场
        if (!Global.Instance.btlMgr.GetUserPlane().isEnterSceneEnd)
        {
            return;
        }
        #endregion

        this.enemyLayerFlyTime += Time.deltaTime;

        #region 从停机坪 -> 起飞战斗
        List <BtlPlane> btlPlaneEnemyList             = Global.Instance.btlMgr.btlPlaneMgr.btlPlaneEnemyList;
        List <BtlPlane> parkingApronBtlPlaneEnemyList = Global.Instance.btlMgr.btlPlaneMgr.parkingApronBtlPlaneEnemyList;

        for (int i = parkingApronBtlPlaneEnemyList.Count - 1; i >= 0; i--)
        {
            BtlPlane plane = parkingApronBtlPlaneEnemyList[i];
            if (this.enemyLayerFlyTime < plane.xmlGameLevelEnemy.enterTime)
            {
                continue;
            }

            btlPlaneEnemyList.Add(plane);
            parkingApronBtlPlaneEnemyList.RemoveAt(i);

            plane.isEnterSceneEnd = true;
            #region 添加组件
            Rigidbody2D rigidbody2D = plane.gameObject.AddComponent <Rigidbody2D>();
            //无引力
            rigidbody2D.gravityScale = 0;
            BoxCollider2D boxCollider2D = plane.gameObject.AddComponent <BoxCollider2D>();
            boxCollider2D.isTrigger = true;

            BtlPlaneMove btlPlaneMove = plane.gameObject.AddComponent <BtlPlaneMove>();
            btlPlaneMove.parent = plane;

            BtlHit btlHit = plane.gameObject.AddComponent <BtlHit>();
            btlHit.parent = plane;

            //移动速度
            plane.btlMove.speed     = new Vector2(plane.xmlPlane.speedX, plane.xmlPlane.speedY);
            plane.btlMove.direction = new Vector2(plane.xmlGameLevelEnemy.directionX, plane.xmlGameLevelEnemy.directionY);
            plane.btlMove.moveTrace = EnumMoveTrace.Line;

            //入场位置
            Vector3 newPosition = plane.gameObject.transform.position;
            newPosition.x = plane.xmlGameLevelEnemy.enterX;
            newPosition.y = plane.xmlGameLevelEnemy.enterY;
            plane.gameObject.transform.position = newPosition;


            //加载子弹
            foreach (var v in plane.xmlPlane.bulletList)
            {
                XmlBullet xmlBullet = Global.Instance.xmlBulletMgr.Find(v);

                plane.btlBulletMgr.Add(xmlBullet);
                BtlFire btlFire = plane.gameObject.AddComponent <BtlFire>();
                btlFire.parent = plane;
            }

            #endregion
        }

        #endregion
    }