Exemplo n.º 1
0
    public void Add(XmlBullet xmlBullet)
    {
        BtlBullet battleBullet = new BtlBullet();

        battleBullet.parent       = this;
        battleBullet.bulletName   = xmlBullet.prefabs;
        battleBullet.xmlBullet    = xmlBullet;
        battleBullet.fireCoolDown = xmlBullet.coolDown;
        this.btlBulletList.Add(battleBullet);
    }
Exemplo n.º 2
0
    public XmlBullet Find(int bulletId)
    {
        if (this.bulletDictionary.ContainsKey(bulletId))
        {
            return(this.bulletDictionary[bulletId]);
        }
        XmlBullet xmlBullet = new XmlBullet();

        return(xmlBullet);
    }
Exemplo n.º 3
0
    public void LoadXml()
    {
        this.bulletDictionary.Clear();

        XmlDocument xml     = new XmlDocument();
        string      xmlPath = Application.dataPath + "/Config/bullet.xml";

        xml.Load(xmlPath);
        XmlElement  rootElem = xml.DocumentElement;
        XmlNodeList nodes    = rootElem.GetElementsByTagName("bullet");

        foreach (XmlNode node in nodes)
        {
            XmlBullet xmlBullet = new XmlBullet();
            xmlBullet.id      = int.Parse(((XmlElement)node).GetAttribute("id"));
            xmlBullet.prefabs = ((XmlElement)node).GetAttribute("prefabs");
            GameObject planePrefabs = (GameObject)Resources.Load(xmlBullet.prefabs);
            if (null == planePrefabs)
            {
                Debug.LogErrorFormat("XmlBulletMgr未找到{0}", xmlBullet.prefabs);
            }
            xmlBullet.damage = int.Parse(((XmlElement)node).GetAttribute("damage"));
            xmlBullet.speed  = float.Parse(((XmlElement)node).GetAttribute("speed"));
            {
                string   str  = ((XmlElement)node).GetAttribute("directionOffset");
                string[] data = str.Split(',');
                xmlBullet.directionOffsetX = float.Parse(data[0]);
                xmlBullet.directionOffsetY = float.Parse(data[1]);
            }
            {
                string   str  = ((XmlElement)node).GetAttribute("positionOffset");
                string[] data = str.Split(',');
                xmlBullet.positionOffsetX = float.Parse(data[0]);
                xmlBullet.positionOffsetY = float.Parse(data[1]);
            }
            xmlBullet.coolDown = float.Parse(((XmlElement)node).GetAttribute("coolDown"));

            this.bulletDictionary.Add(xmlBullet.id, xmlBullet);
        }
    }
Exemplo n.º 4
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
        }
    }
Exemplo n.º 5
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
    }