Xml
How do I use Xml
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
File name: DialogUnity.cs
Copy
26 public void setText(string oneline)
27 {
28 bitmapFont = new BitmapFont("Fonts/shop_font", "Fonts/shop_font_xml", label1);
29 bitmapFont.setText(oneline, 0, 15);
30 Transform[] fontTransforms = label1.GetComponentsInChildren
31 for (int i = 0; i < fontTransforms.Length; i++)
32 {
33 if (fontTransforms[i].gameObject.GetComponent
34 {
35 fontTransforms[i].gameObject.layer = LayerMask.NameToLayer("GUI");
36 fontTransforms[i].gameObject.GetComponent
37 }
38 }
39 }
File name: DialogUnity.cs
Copy
41 public void setText(string line1, string line2)
42 {
43 bitmapFont = new BitmapFont("Fonts/shop_font", "Fonts/shop_font_xml", label1);
44 bitmapFont.setText(line1, 0, 15);
45 Transform[] fontTransforms = label1.GetComponentsInChildren
46 for (int i = 0; i < fontTransforms.Length; i++)
47 {
48
49 if (fontTransforms[i].gameObject.GetComponent
50 {
51 fontTransforms[i].gameObject.layer = LayerMask.NameToLayer("GUI");
52 fontTransforms[i].gameObject.GetComponent
53 }
54 }
55
56 BitmapFont bitmapFont2 = new BitmapFont(bitmapFont, label2);
57 bitmapFont2.setText(line2, 0, 15);
58 Transform[] fontTransforms2 = label2.GetComponentsInChildren
59 for (int i = 0; i < fontTransforms2.Length; i++)
60 {
61 if (fontTransforms2[i].gameObject.GetComponent
62 {
63 fontTransforms2[i].gameObject.layer = LayerMask.NameToLayer("GUI");
64 fontTransforms2[i].gameObject.GetComponent
65 }
66 }
67 }
File name: LevelText.cs
Copy
9 void Start()
10 {
11 BitmapFont fontResult = new BitmapFont("Fonts/font_result", "Fonts/font_result_xml", gameObject);
12 fontResult.setText("Level " + ((Attr.currentWorld * 15) + Attr.currentLevel + 1), -1, 15, "GUI", "GUI");
13 }
File name: PurposeLabel.cs
Copy
16 void Start()
17 {
18 BitmapFont purposeFont1 = new BitmapFont("Fonts/shop_font", "Fonts/shop_font_xml", purposeLabel1);
19 BitmapFont purposeFont2 = new BitmapFont(purposeFont1, purposeLabel2);
20 BitmapFont purposeFont3 = new BitmapFont(purposeFont1, purposeLabel3);
21
22 purposeFont1.setText("5th place or better : 50 #", 0, 12, "GUI", "GUI");
23 purposeFont2.setText("3rd place or better : 100 #", 0, 12, "GUI", "GUI");
24 purposeFont3.setText("1st place : 200 #", 0, 12, "GUI", "GUI");
25
26 purposeLabel1.transform.localScale = new Vector3(0.8f, 0.8f, purposeLabel1.transform.localScale.z);
27 purposeLabel2.transform.localScale = new Vector3(0.8f, 0.8f, purposeLabel2.transform.localScale.z);
28 purposeLabel3.transform.localScale = new Vector3(0.8f, 0.8f, purposeLabel3.transform.localScale.z);
29
30 int star = Data.getData(Data.KEY_STAR + (Attr.currentWorld * 15 + Attr.currentLevel));
31 for (int i = 0; i < 3; i++)
32 {
33 if (i < star)
34 {
35 stars[i].GetComponent
36 }
37 }
38
39 }
File name: ResultLayer.cs
Copy
178 public void setParams(int score, int place, int gold, float time)
179 {
180 this.score = score;
181 this.m_gold = gold + getBonus(place);
182 isShown = true;
183 if (place == 1) star = 3;
184 else if (place > 1 && place <= 3) star = 2;
185 else if (place > 3 && place <= 5) star = 1;
186 else star = 0;
187
188 BitmapFont scoreFont = new BitmapFont("Fonts/font_result", "Fonts/font_result_xml", scoreLabel);
189 scoreFont.setText("" + score, 0, 0, "GUI", "GUI");
190 scoreLabel.transform.localPosition = new Vector3(scoreLabel.transform.localPosition.x - scoreFont.width/2,
191 scoreLabel.transform.localPosition.y, scoreLabel.transform.localPosition.z);
192
193 BitmapFont desFont = new BitmapFont("Fonts/shop_font", "Fonts/shop_font_xml", gameObject);
194
195 BitmapFont bonusFont = new BitmapFont(desFont, labels[0]);
196 bonusFont.setText("BONUS: " + getBonus(place), 0, 15, "GUI", "GUI");
197
198 BitmapFont timeFont = new BitmapFont(desFont, labels[1]);
199 timeFont.setText("TIME: " + ((int)(time * 100))/100f, 0, 15, "GUI","GUI");
200
201 BitmapFont placeFont = new BitmapFont(desFont, labels[2]);
202 placeFont.setText("PLACE: " + place, 0, 15, "GUI", "GUI");
203
204 BitmapFont goldFont = new BitmapFont(desFont, labels[3]);
205 goldFont.setText("GOLD: " + gold, 0, 15, "GUI", "GUI");
206 }
File name: Animals.cs
Copy
14 public void Start()
15 {
16 string[] names = new string[] { "dog", "monkey", "pig", "fox", "giraffe", "panda", "rhino", "tiger", "elephant", "lion" };
17
18 animals = new List
19 int animalIndex = 0;
20
21 UpgradeInfo upgradeInfo = new UpgradeInfo();
22
23 GameObject animalPlayer = (GameObject)Instantiate(Resources.Load
24 animalPlayer.transform.parent = gameObject.transform;
25 animalPlayer.transform.localPosition = new Vector3(-3.5f + 0.7f * animalIndex, -0.9f, 0);
26 setSortingLayer(animalPlayer, "Animal8");
27 Animal player = animalPlayer.AddComponent
28 player.setAnimalName(names[Attr.currentAnimal]);
29 player.animalIndex = animalIndex;
30 player.gameScreen = gameScreen;
31 float speedPlayer = upgradeInfo.getItem(Attr.currentAnimal, 0, false);
32 float jumpPlayer = upgradeInfo.getItem(Attr.currentAnimal, 1, false);
33 player.setAnimalProperties(speedPlayer, jumpPlayer);
34 animalPlayer.layer = LayerMask.NameToLayer("Animal1");
35
36 animals.Add(animalPlayer);
37 animalIndex++;
38
39 animalPlayer.GetComponent
40 //animalPlayer.GetComponent
41
42 TextAsset xml = Resources.Load
43 XmlDocument xmlDoc = new XmlDocument();
44 xmlDoc.Load(new StringReader(xml.text));
45
46 XmlNodeList xmlNodeList = xmlDoc.DocumentElement.ChildNodes;
47 XmlNodeList levelNodeList = xmlNodeList.Item(Attr.currentLevel).ChildNodes;
48 for (int i = 0; i < levelNodeList.Count; i++)
49 {
50 int numberAnimal = int.Parse(levelNodeList.Item(i).Attributes.Item(0).Value);
51 string animalName = levelNodeList.Item(i).Attributes.Item(1).Value.ToLower();
52
53 for (int k = 0; k < numberAnimal; k++)
54 {
55 GameObject animalObject = (GameObject)Instantiate(Resources.Load
56 animalObject.transform.parent = gameObject.transform;
57 animalObject.transform.localPosition = new Vector3(-3.5f + 0.7f*animalIndex, -0.9f, 0);
58 setSortingLayer(animalObject, "Animal" + animalIndex);
59 Animal animal = animalObject.AddComponent
60 animal.setAnimalName(animalName.ToLower() + "_blue");
61 animal.animalIndex = animalIndex;
62 animal.gameScreen = gameScreen;
63 float speed = upgradeInfo.getSpeed(i);
64 float jump = upgradeInfo.getJump(i);
65 animal.setAnimalProperties(speed, jump);
66 animalObject.layer = LayerMask.NameToLayer("Animal" + (animalIndex + 1));
67 animals.Add(animalObject);
68 animalIndex++;
69
70 animalObject.GetComponent
71
72 //animalObject.GetComponent
73 }
74 }
75 }
File name: GameScreen.cs
Copy
62 public void Start()
63 {
64 InputController.Name = InputNames.DIALOG;
65
66 string[] mapNames = new string[] {"jungle","southpole","desert","volcano"};
67 int[] lvs = new int[] { 1, 2, 3, 2, 3, 4, 3, 4, 5, 1, 2, 4, 3, 4, 5 };
68
69 Debug.Log("WorldIndex : " + Attr.currentWorld + ", LevelIndex : " + Attr.currentLevel);
70
71 mapObject = (GameObject)Instantiate(Resources.Load("Maps/" + mapNames[Attr.currentWorld] + lvs[Attr.currentLevel]), new Vector3(-4, 2.5f, 0), Quaternion.identity);
72 mapObject.transform.localScale = new Vector3(0.01f, 0.01f, mapObject.transform.localScale.z);
73
74 revivalPositions = new List
75
76 getSkillChoosed();
77
78 setupMap(mapObject);
79
80 int mapLayer = LayerMask.NameToLayer("Map");
81 mapObject.layer = mapLayer;
82
83 Transform[] transforms = mapObject.GetComponentsInChildren
84 for (int i = 0; i < transforms.Length; i++)
85 {
86 transforms[i].gameObject.layer = mapLayer;
87 }
88
89 shopFont = new BitmapFont("Fonts/shop_font", "Fonts/shop_font_xml", null);
90
91 BitmapFont comboFont = new BitmapFont("Fonts/font_combo", "Fonts/font_combo_xml", null);
92 combo1.setFont(comboFont);
93 combo2.setFont(comboFont);
94
95 createDialog();
96
97 m_gold = 0;
98 m_time = 0;
99 m_score = 0;
100
101 perSkills = new int[] { 30, 30, 35, 35, 40, 40, 45, 45, 50, 55, 60, 60, 65, 65, 70 };
102
103 isRunning = true;
104 //prepareGame();//khong goi o day vi co the chua chay het cac ham Start
105 isPrepare = true;
106 }
File name: TaskBar.cs
Copy
23 public void Start()
24 {
25 rankFont = new BitmapFont("Fonts/font_rank", "Fonts/font_rank_xml", rankLabel);
26
27 fontTime = new BitmapFont("Fonts/font_time", "Fonts/font_time_xml", timeLabel);
28 fontGold = new BitmapFont(fontTime, goldLabel);
29 fontScore = new BitmapFont(fontTime, scoreLabel);
30 }
File name: BoardLevel.cs
Copy
13 public void Awake()
14 {
15 font = new BitmapFont("Fonts/font_banchoi", "Fonts/font_banchoi_xml", gameObject);
16 }
File name: BuyLayer.cs
Copy
18 public void setFont(BitmapFont fontShop)
19 {
20 starLabel.setFont(fontShop);
21 goldLabel.setFont(fontShop);
22 desFont = new BitmapFont("Fonts/bitmapfont1", "Fonts/bitmapfont1_xml", null);
23 boosterLabel.setFont(desFont);
24 springsLabel.setFont(desFont);
25 }
Download file with original file name:Xml
Xml 126 lượt xem
Gõ tìm kiếm nhanh...