示例#1
0
        public void LoadXML()
        {
            string group = TagController.GetInstance().group.ToString();

            xml.Load(Global.path);
            XmlElement root           = xml.DocumentElement;
            XmlNode    groupNode      = root.SelectSingleNode("/root/" + group);
            Transform  groupTransform = scrollView.Find(group);

            if (groupNode.Attributes["save"].Value == false.ToString())
            {
                return;
            }

            Transform   leaderTransform = groupTransform.Find("leader");
            XmlNode     leaderNode      = groupNode.SelectSingleNode("leader");
            XmlNodeList leaderNodeList  = leaderNode.ChildNodes;

            foreach (XmlNode cardNode in leaderNodeList)
            {
                Transform card = leaderTransform.Find(cardNode.Name);
                card.Find("Control - Simple Checkbox").GetComponent <UIToggle>().value = true;
            }

            Transform   specialTransform = groupTransform.Find("special");
            XmlNode     specialNode      = groupNode.SelectSingleNode("special");
            XmlNodeList specialNodeList  = specialNode.ChildNodes;

            foreach (XmlNode cardNode in specialNodeList)
            {
                Transform card = specialTransform.Find(cardNode.Name);
                card.Find("Control - Simple Checkbox").GetComponent <UIToggle>().value = true;
                card.GetComponent <CardPlus>().WriteTotal(int.Parse(cardNode.Attributes["total"].Value));
            }

            Transform   monsterTransform = groupTransform.Find("monster");
            XmlNode     monsterNode      = groupNode.SelectSingleNode("monster");
            XmlNodeList monsterNodeList  = monsterNode.ChildNodes;

            foreach (XmlNode cardNode in monsterNodeList)
            {
                Transform card = monsterTransform.Find(cardNode.Name);
                card.Find("Control - Simple Checkbox").GetComponent <UIToggle>().value = true;
                card.GetComponent <CardPlus>().WriteTotal(int.Parse(cardNode.Attributes["total"].Value));
            }

            Transform   neutralTransform = groupTransform.Find("neutral");
            XmlNode     neutralNode      = groupNode.SelectSingleNode("neutral");
            XmlNodeList neutralNodeList  = neutralNode.ChildNodes;

            foreach (XmlNode cardNode in neutralNodeList)
            {
                Transform card = neutralTransform.Find(cardNode.Name);
                card.Find("Control - Simple Checkbox").GetComponent <UIToggle>().value = true;
                card.GetComponent <CardPlus>().WriteTotal(int.Parse(cardNode.Attributes["total"].Value));
            }
        }
示例#2
0
        public void UpdateXML(Transform card)
        {
            string     group = TagController.GetInstance().group.ToString();
            string     list  = TagController.GetInstance().list.ToString();
            XmlElement root  = xml.DocumentElement;
            XmlNode    node  = root.SelectSingleNode(string.Format("/root/{0}/{1}", group, list));

            if (node.SelectSingleNode(card.name) == null)
            {
                if (card.Find("Control - Simple Checkbox").GetComponent <UIToggle>().value)
                {
                    XmlElement cardElement = xml.CreateElement(card.name);
                    if (list == "leader")
                    {
                        cardElement.SetAttribute("sprite", card.GetComponent <UISprite>().spriteName);
                        cardElement.SetAttribute("behavior", card.GetComponent <PlayerLeaderBehavior>().GetType().ToString());
                        cardElement.SetAttribute("message", card.GetComponent <PlayerLeaderBehavior>().message);
                    }
                    else
                    {
                        cardElement.SetAttribute("total", card.GetComponent <CardPlus>().total.ToString());
                        cardElement.SetAttribute("sprite", card.GetComponent <UISprite>().spriteName);
                        CardProperty cardProperty = card.GetComponent <CardProperty>();
                        cardElement.SetAttribute("line", cardProperty.line.ToString());
                        cardElement.SetAttribute("effect", cardProperty.effect.ToString());
                        cardElement.SetAttribute("gold", cardProperty.gold.ToString());
                        cardElement.SetAttribute("power", cardProperty.power.ToString());
                    }
                    node.AppendChild(cardElement);
                }
            }
            else
            {
                XmlNode cardNode = node.SelectSingleNode(card.name);
                if (card.Find("Control - Simple Checkbox").GetComponent <UIToggle>().value)
                {
                    if (list != "leader")
                    {
                        cardNode.Attributes["total"].Value = card.GetComponent <CardPlus>().total.ToString();
                    }
                }
                else
                {
                    node.RemoveChild(cardNode);
                }
            }

            NumberController.GetInstance().Number();
        }
示例#3
0
        public void OnClick()
        {
            try
            {
                if (NumberController.GetInstance().leaderCount != 1)
                {
                    throw new SaveException();
                }
                if (NumberController.GetInstance().specialCount > 10)
                {
                    throw new SaveException();
                }
                if (NumberController.GetInstance().monsterCount < 25 || NumberController.GetInstance().monsterCount > 40)
                {
                    throw new SaveException();
                }

                XmlElement root      = xml.DocumentElement;
                XmlNode    groupNode = root.SelectSingleNode(string.Format("/root/{0}", TagController.GetInstance().group.ToString()));
                groupNode.Attributes["save"].Value = true.ToString();
                xml.Save(Global.path);
                StartCoroutine(ShowLabel("保存成功"));
            }
            catch (SaveException)
            {
                StartCoroutine(ShowLabel("卡牌数量不满足条件,保存失败"));
            }
        }
示例#4
0
        // Use this for initialization
        void Start()
        {
            if (!File.Exists(Global.enemyPath))
            {
                XmlDocument xml  = new XmlDocument();
                XmlElement  root = xml.CreateElement("root");

                XmlElement northern       = xml.CreateElement("northern");
                Transform  groupTransform = TagController.GetInstance().groups[0].transform;

                XmlElement leader1          = xml.CreateElement("leader");
                Transform  leader1Transform = groupTransform.Find("leader");
                for (int i = 0; i < leader1Transform.childCount; i++)
                {
                    Transform  card        = leader1Transform.GetChild(i);
                    XmlElement cardElement = xml.CreateElement(card.name);
                    cardElement.SetAttribute("sprite", card.GetComponent <UISprite>().spriteName);
                    cardElement.SetAttribute("behavior", card.GetComponent <EnemyLeaderBehavior>().GetType().ToString());
                    leader1.AppendChild(cardElement);
                }

                XmlElement special1          = xml.CreateElement("special");
                Transform  special1Transform = groupTransform.Find("special");
                for (int i = 0; i < special1Transform.childCount; i++)
                {
                    Transform  card        = special1Transform.GetChild(i);
                    XmlElement cardElement = xml.CreateElement(card.name);
                    cardElement.SetAttribute("max", card.GetComponent <CardPlus>().max.ToString());
                    cardElement.SetAttribute("sprite", card.GetComponent <UISprite>().spriteName);
                    CardProperty cardProperty = card.GetComponent <CardProperty>();
                    cardElement.SetAttribute("line", cardProperty.line.ToString());
                    cardElement.SetAttribute("effect", cardProperty.effect.ToString());
                    cardElement.SetAttribute("gold", cardProperty.gold.ToString());
                    cardElement.SetAttribute("power", cardProperty.power.ToString());
                    special1.AppendChild(cardElement);
                }

                XmlElement monster1          = xml.CreateElement("monster");
                Transform  monster1Transform = groupTransform.Find("monster");
                for (int i = 0; i < monster1Transform.childCount; i++)
                {
                    Transform  card        = monster1Transform.GetChild(i);
                    XmlElement cardElement = xml.CreateElement(card.name);
                    cardElement.SetAttribute("max", card.GetComponent <CardPlus>().max.ToString());
                    cardElement.SetAttribute("sprite", card.GetComponent <UISprite>().spriteName);
                    CardProperty cardProperty = card.GetComponent <CardProperty>();
                    cardElement.SetAttribute("line", cardProperty.line.ToString());
                    cardElement.SetAttribute("effect", cardProperty.effect.ToString());
                    cardElement.SetAttribute("gold", cardProperty.gold.ToString());
                    cardElement.SetAttribute("power", cardProperty.power.ToString());
                    monster1.AppendChild(cardElement);
                }

                XmlElement neutral1          = xml.CreateElement("neutral");
                Transform  neutral1Transform = groupTransform.Find("neutral");
                for (int i = 0; i < neutral1Transform.childCount; i++)
                {
                    Transform  card        = neutral1Transform.GetChild(i);
                    XmlElement cardElement = xml.CreateElement(card.name);
                    cardElement.SetAttribute("max", card.GetComponent <CardPlus>().max.ToString());
                    cardElement.SetAttribute("sprite", card.GetComponent <UISprite>().spriteName);
                    CardProperty cardProperty = card.GetComponent <CardProperty>();
                    cardElement.SetAttribute("line", cardProperty.line.ToString());
                    cardElement.SetAttribute("effect", cardProperty.effect.ToString());
                    cardElement.SetAttribute("gold", cardProperty.gold.ToString());
                    cardElement.SetAttribute("power", cardProperty.power.ToString());
                    neutral1.AppendChild(cardElement);
                }

                northern.AppendChild(leader1);
                northern.AppendChild(special1);
                northern.AppendChild(monster1);
                northern.AppendChild(neutral1);

                XmlElement nilfgaardian = xml.CreateElement("nilfgaardian");
                groupTransform = TagController.GetInstance().groups[1].transform;

                XmlElement leader2          = xml.CreateElement("leader");
                Transform  leader2Transform = groupTransform.Find("leader");
                for (int i = 0; i < leader2Transform.childCount; i++)
                {
                    Transform  card        = leader2Transform.GetChild(i);
                    XmlElement cardElement = xml.CreateElement(card.name);
                    cardElement.SetAttribute("sprite", card.GetComponent <UISprite>().spriteName);
                    cardElement.SetAttribute("behavior", card.GetComponent <EnemyLeaderBehavior>().GetType().ToString());
                    leader2.AppendChild(cardElement);
                }

                XmlElement special2          = xml.CreateElement("special");
                Transform  special2Transform = groupTransform.Find("special");
                for (int i = 0; i < special2Transform.childCount; i++)
                {
                    Transform  card        = special2Transform.GetChild(i);
                    XmlElement cardElement = xml.CreateElement(card.name);
                    cardElement.SetAttribute("max", card.GetComponent <CardPlus>().max.ToString());
                    cardElement.SetAttribute("sprite", card.GetComponent <UISprite>().spriteName);
                    CardProperty cardProperty = card.GetComponent <CardProperty>();
                    cardElement.SetAttribute("line", cardProperty.line.ToString());
                    cardElement.SetAttribute("effect", cardProperty.effect.ToString());
                    cardElement.SetAttribute("gold", cardProperty.gold.ToString());
                    cardElement.SetAttribute("power", cardProperty.power.ToString());
                    special2.AppendChild(cardElement);
                }

                XmlElement monster2          = xml.CreateElement("monster");
                Transform  monster2Transform = groupTransform.Find("monster");
                for (int i = 0; i < monster2Transform.childCount; i++)
                {
                    Transform  card        = monster2Transform.GetChild(i);
                    XmlElement cardElement = xml.CreateElement(card.name);
                    cardElement.SetAttribute("max", card.GetComponent <CardPlus>().max.ToString());
                    cardElement.SetAttribute("sprite", card.GetComponent <UISprite>().spriteName);
                    CardProperty cardProperty = card.GetComponent <CardProperty>();
                    cardElement.SetAttribute("line", cardProperty.line.ToString());
                    cardElement.SetAttribute("effect", cardProperty.effect.ToString());
                    cardElement.SetAttribute("gold", cardProperty.gold.ToString());
                    cardElement.SetAttribute("power", cardProperty.power.ToString());
                    monster2.AppendChild(cardElement);
                }

                XmlElement neutral2          = xml.CreateElement("neutral");
                Transform  neutral2Transform = groupTransform.Find("neutral");
                for (int i = 0; i < neutral2Transform.childCount; i++)
                {
                    Transform  card        = neutral2Transform.GetChild(i);
                    XmlElement cardElement = xml.CreateElement(card.name);
                    cardElement.SetAttribute("max", card.GetComponent <CardPlus>().max.ToString());
                    cardElement.SetAttribute("sprite", card.GetComponent <UISprite>().spriteName);
                    CardProperty cardProperty = card.GetComponent <CardProperty>();
                    cardElement.SetAttribute("line", cardProperty.line.ToString());
                    cardElement.SetAttribute("effect", cardProperty.effect.ToString());
                    cardElement.SetAttribute("gold", cardProperty.gold.ToString());
                    cardElement.SetAttribute("power", cardProperty.power.ToString());
                    neutral2.AppendChild(cardElement);
                }

                nilfgaardian.AppendChild(leader2);
                nilfgaardian.AppendChild(special2);
                nilfgaardian.AppendChild(monster2);
                nilfgaardian.AppendChild(neutral2);

                XmlElement monster = xml.CreateElement("monster");
                groupTransform = TagController.GetInstance().groups[2].transform;

                XmlElement leader3          = xml.CreateElement("leader");
                Transform  leader3Transform = groupTransform.Find("leader");
                for (int i = 0; i < leader3Transform.childCount; i++)
                {
                    Transform  card        = leader3Transform.GetChild(i);
                    XmlElement cardElement = xml.CreateElement(card.name);
                    cardElement.SetAttribute("sprite", card.GetComponent <UISprite>().spriteName);
                    cardElement.SetAttribute("behavior", card.GetComponent <EnemyLeaderBehavior>().GetType().ToString());
                    leader3.AppendChild(cardElement);
                }

                XmlElement special3          = xml.CreateElement("special");
                Transform  special3Transform = groupTransform.Find("special");
                for (int i = 0; i < special3Transform.childCount; i++)
                {
                    Transform  card        = special3Transform.GetChild(i);
                    XmlElement cardElement = xml.CreateElement(card.name);
                    cardElement.SetAttribute("max", card.GetComponent <CardPlus>().max.ToString());
                    cardElement.SetAttribute("sprite", card.GetComponent <UISprite>().spriteName);
                    CardProperty cardProperty = card.GetComponent <CardProperty>();
                    cardElement.SetAttribute("line", cardProperty.line.ToString());
                    cardElement.SetAttribute("effect", cardProperty.effect.ToString());
                    cardElement.SetAttribute("gold", cardProperty.gold.ToString());
                    cardElement.SetAttribute("power", cardProperty.power.ToString());
                    special3.AppendChild(cardElement);
                }

                XmlElement monster3          = xml.CreateElement("monster");
                Transform  monster3Transform = groupTransform.Find("monster");
                for (int i = 0; i < monster3Transform.childCount; i++)
                {
                    Transform  card        = monster3Transform.GetChild(i);
                    XmlElement cardElement = xml.CreateElement(card.name);
                    cardElement.SetAttribute("max", card.GetComponent <CardPlus>().max.ToString());
                    cardElement.SetAttribute("sprite", card.GetComponent <UISprite>().spriteName);
                    CardProperty cardProperty = card.GetComponent <CardProperty>();
                    cardElement.SetAttribute("line", cardProperty.line.ToString());
                    cardElement.SetAttribute("effect", cardProperty.effect.ToString());
                    cardElement.SetAttribute("gold", cardProperty.gold.ToString());
                    cardElement.SetAttribute("power", cardProperty.power.ToString());
                    monster3.AppendChild(cardElement);
                }

                XmlElement neutral3          = xml.CreateElement("neutral");
                Transform  neutral3Transform = groupTransform.Find("neutral");
                for (int i = 0; i < neutral3Transform.childCount; i++)
                {
                    Transform  card        = neutral3Transform.GetChild(i);
                    XmlElement cardElement = xml.CreateElement(card.name);
                    cardElement.SetAttribute("max", card.GetComponent <CardPlus>().max.ToString());
                    cardElement.SetAttribute("sprite", card.GetComponent <UISprite>().spriteName);
                    CardProperty cardProperty = card.GetComponent <CardProperty>();
                    cardElement.SetAttribute("line", cardProperty.line.ToString());
                    cardElement.SetAttribute("effect", cardProperty.effect.ToString());
                    cardElement.SetAttribute("gold", cardProperty.gold.ToString());
                    cardElement.SetAttribute("power", cardProperty.power.ToString());
                    neutral3.AppendChild(cardElement);
                }

                monster.AppendChild(leader3);
                monster.AppendChild(special3);
                monster.AppendChild(monster3);
                monster.AppendChild(neutral3);

                XmlElement scoiatael = xml.CreateElement("scoiatael");
                groupTransform = TagController.GetInstance().groups[3].transform;

                XmlElement leader4          = xml.CreateElement("leader");
                Transform  leader4Transform = groupTransform.Find("leader");
                for (int i = 0; i < leader4Transform.childCount; i++)
                {
                    Transform  card        = leader4Transform.GetChild(i);
                    XmlElement cardElement = xml.CreateElement(card.name);
                    cardElement.SetAttribute("sprite", card.GetComponent <UISprite>().spriteName);
                    cardElement.SetAttribute("behavior", card.GetComponent <EnemyLeaderBehavior>().GetType().ToString());
                    leader4.AppendChild(cardElement);
                }

                XmlElement special4          = xml.CreateElement("special");
                Transform  special4Transform = groupTransform.Find("special");
                for (int i = 0; i < special4Transform.childCount; i++)
                {
                    Transform  card        = special4Transform.GetChild(i);
                    XmlElement cardElement = xml.CreateElement(card.name);
                    cardElement.SetAttribute("max", card.GetComponent <CardPlus>().max.ToString());
                    cardElement.SetAttribute("sprite", card.GetComponent <UISprite>().spriteName);
                    CardProperty cardProperty = card.GetComponent <CardProperty>();
                    cardElement.SetAttribute("line", cardProperty.line.ToString());
                    cardElement.SetAttribute("effect", cardProperty.effect.ToString());
                    cardElement.SetAttribute("gold", cardProperty.gold.ToString());
                    cardElement.SetAttribute("power", cardProperty.power.ToString());
                    special4.AppendChild(cardElement);
                }

                XmlElement monster4          = xml.CreateElement("monster");
                Transform  monster4Transform = groupTransform.Find("monster");
                for (int i = 0; i < monster4Transform.childCount; i++)
                {
                    Transform  card        = monster4Transform.GetChild(i);
                    XmlElement cardElement = xml.CreateElement(card.name);
                    cardElement.SetAttribute("max", card.GetComponent <CardPlus>().max.ToString());
                    cardElement.SetAttribute("sprite", card.GetComponent <UISprite>().spriteName);
                    CardProperty cardProperty = card.GetComponent <CardProperty>();
                    cardElement.SetAttribute("line", cardProperty.line.ToString());
                    cardElement.SetAttribute("effect", cardProperty.effect.ToString());
                    cardElement.SetAttribute("gold", cardProperty.gold.ToString());
                    cardElement.SetAttribute("power", cardProperty.power.ToString());
                    monster4.AppendChild(cardElement);
                }

                XmlElement neutral4          = xml.CreateElement("neutral");
                Transform  neutral4Transform = groupTransform.Find("neutral");
                for (int i = 0; i < neutral4Transform.childCount; i++)
                {
                    Transform  card        = neutral4Transform.GetChild(i);
                    XmlElement cardElement = xml.CreateElement(card.name);
                    cardElement.SetAttribute("max", card.GetComponent <CardPlus>().max.ToString());
                    cardElement.SetAttribute("sprite", card.GetComponent <UISprite>().spriteName);
                    CardProperty cardProperty = card.GetComponent <CardProperty>();
                    cardElement.SetAttribute("line", cardProperty.line.ToString());
                    cardElement.SetAttribute("effect", cardProperty.effect.ToString());
                    cardElement.SetAttribute("gold", cardProperty.gold.ToString());
                    cardElement.SetAttribute("power", cardProperty.power.ToString());
                    neutral4.AppendChild(cardElement);
                }

                scoiatael.AppendChild(leader4);
                scoiatael.AppendChild(special4);
                scoiatael.AppendChild(monster4);
                scoiatael.AppendChild(neutral4);

                root.AppendChild(northern);
                root.AppendChild(nilfgaardian);
                root.AppendChild(monster);
                root.AppendChild(scoiatael);

                xml.AppendChild(root);
                xml.Save(Global.enemyPath);
            }
        }
示例#5
0
        public void Number()
        {
            Transform group = transform.Find(TagController.GetInstance().group.ToString());

            leaderCount  = 0;
            specialCount = 0;
            monsterCount = 0;

            Transform leader = group.transform.Find("leader");

            for (int i = 0; i < leader.childCount; i++)
            {
                Transform card = leader.GetChild(i);
                if (card.Find("Control - Simple Checkbox").GetComponent <UIToggle>().value)
                {
                    leaderCount++;
                }
            }

            Transform special = group.transform.Find("special");

            for (int i = 0; i < special.childCount; i++)
            {
                Transform card = special.GetChild(i);
                if (card.Find("Control - Simple Checkbox").GetComponent <UIToggle>().value)
                {
                    for (int ii = 0; ii < card.GetComponent <CardPlus>().total; ii++)
                    {
                        specialCount++;
                    }
                }
            }

            Transform monster = group.transform.Find("monster");

            for (int i = 0; i < monster.childCount; i++)
            {
                Transform card = monster.GetChild(i);
                if (card.Find("Control - Simple Checkbox").GetComponent <UIToggle>().value)
                {
                    for (int ii = 0; ii < card.GetComponent <CardPlus>().total; ii++)
                    {
                        monsterCount++;
                    }
                }
            }

            Transform neutral = group.transform.Find("neutral");

            for (int i = 0; i < neutral.childCount; i++)
            {
                Transform card = neutral.GetChild(i);
                if (card.Find("Control - Simple Checkbox").GetComponent <UIToggle>().value)
                {
                    for (int ii = 0; ii < card.GetComponent <CardPlus>().total; ii++)
                    {
                        monsterCount++;
                    }
                }
            }

            labels[0].text = string.Format("领导牌:{0}/1", leaderCount);
            labels[1].text = string.Format("特殊牌:{0}/10", specialCount);
            labels[2].text = string.Format("生物牌:25/{0}/40", monsterCount);
        }