Bitmap









How do I use Bitmap
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(true);
31             for (int i = 0; i < fontTransforms.Length; i++)
32             {
33                 if (fontTransforms[i].gameObject.GetComponent() != null)
34                 {
35                     fontTransforms[i].gameObject.layer = LayerMask.NameToLayer("GUI");
36                     fontTransforms[i].gameObject.GetComponent().sortingLayerName = "GUI";
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(true);
46             for (int i = 0; i < fontTransforms.Length; i++)
47             {
48
49                 if (fontTransforms[i].gameObject.GetComponent() != null)
50                 {
51                     fontTransforms[i].gameObject.layer = LayerMask.NameToLayer("GUI");
52                     fontTransforms[i].gameObject.GetComponent().sortingLayerName = "GUI";
53                 }
54             }
55
56             BitmapFont bitmapFont2 = new BitmapFont(bitmapFont, label2);
57             bitmapFont2.setText(line2, 0, 15);
58             Transform[] fontTransforms2 = label2.GetComponentsInChildren(true);
59             for (int i = 0; i < fontTransforms2.Length; i++)
60             {
61                 if (fontTransforms2[i].gameObject.GetComponent() != null)
62                 {
63                     fontTransforms2[i].gameObject.layer = LayerMask.NameToLayer("GUI");
64                     fontTransforms2[i].gameObject.GetComponent().sortingLayerName = "GUI";
65                 }
66             }
67         }
File name: Combo.cs Copy
42         public void setFont(BitmapFont comboFont)
43         {
44             fontCombo = new BitmapFont(comboFont, label);
45         }
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().sprite = starSprite;
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: ButtonSkills.cs Copy
23         public void Start()
24         {
25             float[] btX = new float[] {1.75f, 2.65f, 3.55f};
26             int[] skills = Attr.currentSkills;
27             //int skillNumber = 0;
28             labels = new GameObject[3];
29             for (int i = 0; i < 3; i++)
30             {
31                 if (skills[i] >= 0)
32                 {
33                     buttonSkills[skillNumber].GetComponent().sprite = skillSprites[skills[i]];
34                     buttonSkills[skillNumber].AddComponent().skillType = SkillRandom.getSkillType(skills[i]);
35                     addClickListener(buttonSkills[skillNumber], skillSprites[skills[i]], skillSpriteLocks[skills[i]]);
36                     boardObjects[skillNumber].GetComponent().sprite = boardSprite;
37                     labels[skillNumber] = new GameObject("SkillNumber");
38                     labels[skillNumber].transform.parent = gameObject.transform;
39                     skillNumber++;
40                 }
41             }
42
43             for (int i = skillNumber - 1; i >= 0; i--)
44             {
45                 Vector3 p = buttonSkills[i].gameObject.transform.localPosition;
46                 buttonSkills[i].gameObject.transform.localPosition = new Vector3(btX[2 - i], p.y, p.z);
47                 boardObjects[i].transform.localPosition = new Vector3(btX[2 - i] + 0.2f, p.y - 0.25f, -1);
48
49                 labels[i].transform.localPosition = new Vector3(btX[2-i] + 0.1f , p.y - 0.35f, -1);
50             }
51             fontSkills = new BitmapFont[3];
52         }
File name: ButtonSkills.cs Copy
64         public void setFonts(BitmapFont shopFont)
65         {
66             for (int i = 0; i < skillNumber; i++)
67             {
68                 //if (Attr.currentSkills[i] >= 0)
69                 if (buttonSkills[i].GetComponent() != null)
70                 {
71                     fontSkills[i] = new BitmapFont(shopFont, labels[i]);
72                     fontSkills[i].setText("" + numberSkills[i], 0, 0, "GUI", "GUI");
73                     buttonSkills[i].GetComponent().setEnabled(numberSkills[i] > 0);
74                 }
75                 //else
76                 //{
77                 // fontSkills[i] = null;
78                 // if(Attr.currentSkills[i] >= 0)
79                  // buttonSkills[i].SetActive(false);
80                 //}
81             }
82         }
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(true);
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         }

Download file with original file name:Bitmap

Bitmap 105 lượt xem

Gõ tìm kiếm nhanh...