N0
How do I use N0
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
File name: GameplayController.cs
Copy
55 void InitializeCoins(){
56 coins = 0;
57 coinText.text = coins.ToString ();
58 currentCoinText.text = GameController.instance.coins.ToString("N0");
59 }
File name: GameplayController.cs
Copy
211 public void GameOver(){
212 gameoverPanel.SetActive (true);
213 gameoverCoinText.text = coins.ToString ("N0");
214 scoreText.text = coins.ToString ("N0");
215 if(GameController.instance.coins != null){
216 GameController.instance.coins += coins;
217 GameController.instance.Save ();
218 }
219 }
File name: GameplayController.cs
Copy
65 void UpdateGameplayController(){
66 scoreText.text = GameController.instance.score.ToString("N0");
67 shotText.text = "X" + PlayerBullet ();
68 }
File name: GameplayController.cs
Copy
70 void InitializeVariables(){
71 gameInProgress = true;
72 enemies = new List
73 objects = new List
74 distance = 10f;
75 if(GameController.instance != null){
76 GameController.instance.score = 0;
77 prevLevel = GameController.instance.currentLevel;
78 highscore.transform.GetChild (0).transform.GetComponent
79
80 if(GameController.instance.highscore[GameController.instance.currentLevel - 1] > 0){
81 highscore.gameObject.SetActive (true);
82 }
83
84 }
85
86 }
File name: GameplayController.cs
Copy
140 void GameWin(){
141 if(GameController.instance != null && MusicController.instance != null){
142 if(GameController.instance.isMusicOn){
143 AudioSource.PlayClipAtPoint (MusicController.instance.winSound, Camera.main.transform.position);
144 }
145
146 if(GameController.instance.score > GameController.instance.highscore[ GameController.instance.currentLevel - 1]){
147 GameController.instance.highscore [ GameController.instance.currentLevel - 1] = GameController.instance.score;
148 }
149
150 highscore.text = GameController.instance.highscore [GameController.instance.currentLevel].ToString ("N0");
151
152 int level = GameController.instance.currentLevel;
153 level++;
154 if(!(level-1 >= GameController.instance.levels.Length)){
155 GameController.instance.levels [level - 1] = true;
156 }
157
158 GameController.instance.Save ();
159 GameController.instance.currentLevel = level;
160 }
161 gameWinPanel.SetActive (true);
162
163 }
File name: Filters.cs
Copy
25 public static bool GrayScale(Bitmap b)
26 {
27 // GDI+ still lies to us - the return format is BGR, NOT RGB.
28 BitmapData bmData = b.LockBits(new Rectangle(0, 0, b.Width, b.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
29
30 //dia chi o nho chua diem anh dau tien
31 int stride = bmData.Stride;
32
33 //so byte tren 1 hang
34 System.IntPtr Scan0 = bmData.Scan0;
35 //kiem soat con tro(ma ko an toan)
36 unsafe
37 {
38 //khai bao con tro p co dia chi o scan0
39 byte * p = (byte *)(void *)Scan0;
40 //ria cua anh, de con tro chay den hang thu 2
41 int nOffset = stride - b.Width*3;
42
43 byte red, green, blue;
44 //cho chay het 1 cot
45 for(int y=0;y
46 {
47 //cho theo hang
48 for(int x=0; x < b.Width; ++x )
49 {
50 blue = p[0];
51 green = p[1];
52 red = p[2];
53 //cong thuc bien doi anh xam
54 p[0] = p[1] = p[2] = (byte)(.299 * red + .587 * green + .114 * blue);
55 //sang diem anh ke tiep
56 p += 3;
57 }
58 //xuong hang ke tiep(ria cua anh)
59 p += nOffset;
60 }
61 }
62 //giai phong bien bmData
63 b.UnlockBits(bmData);
64
65 return true;
66 }
File name: Filters.cs
Copy
68 public static bool Color(Bitmap b, int red, int green, int blue)
69 {
70 if (red < -255 || red > 255) return false;
71 if (green < -255 || green > 255) return false;
72 if (blue < -255 || blue > 255) return false;
73
74 // GDI+ still lies to us - the return format is BGR, NOT RGB.
75 BitmapData bmData = b.LockBits(new Rectangle(0, 0, b.Width, b.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
76
77 int stride = bmData.Stride;
78 System.IntPtr Scan0 = bmData.Scan0;
79
80 unsafe
81 {
82 byte * p = (byte *)(void *)Scan0;
83
84 int nOffset = stride - b.Width*3;
85 int nPixel;
86
87 for(int y=0;y
88 {
89 for(int x=0; x < b.Width; ++x )
90 {
91 nPixel = p[2] + red;
92 nPixel = Math.Max(nPixel, 0);
93 p[2] = (byte)Math.Min(255, nPixel);
94
95 nPixel = p[1] + green;
96 nPixel = Math.Max(nPixel, 0);
97 p[1] = (byte)Math.Min(255, nPixel);
98
99 nPixel = p[0] + blue;
100 nPixel = Math.Max(nPixel, 0);
101 p[0] = (byte)Math.Min(255, nPixel);
102
103 p += 3;
104 }
105 p += nOffset;
106 }
107 }
108
109 b.UnlockBits(bmData);
110
111 return true;
112 }
File name: Filters.cs
Copy
114 public static bool Conv3x3(Bitmap b, ConvMatrix m)
115 {
116 // Avoid divide by zero errors
117 if (0 == m.Factor) return false;
118
119 Bitmap bSrc = (Bitmap)b.Clone();
120
121 // GDI+ still lies to us - the return format is BGR, NOT RGB.
122 BitmapData bmData = b.LockBits(new Rectangle(0, 0, b.Width, b.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
123 BitmapData bmSrc = bSrc.LockBits(new Rectangle(0, 0, bSrc.Width, bSrc.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
124
125 int stride = bmData.Stride;
126 int stride2 = stride * 2;
127 System.IntPtr Scan0 = bmData.Scan0;
128 System.IntPtr SrcScan0 = bmSrc.Scan0;
129
130 unsafe
131 {
132 byte * p = (byte *)(void *)Scan0;
133 byte * pSrc = (byte *)(void *)SrcScan0;
134
135 int nOffset = stride + 6 - b.Width*3;
136 int nWidth = b.Width - 2;
137 int nHeight = b.Height - 2;
138
139 int nPixel;
140
141 for(int y=0;y < nHeight;++y)
142 {
143 for(int x=0; x < nWidth; ++x )
144 {
145 nPixel = ( ( ( (pSrc[2] * m.TopLeft) + (pSrc[5] * m.TopMid) + (pSrc[8] * m.TopRight) +
146 (pSrc[2 + stride] * m.MidLeft) + (pSrc[5 + stride] * m.Pixel) + (pSrc[8 + stride] * m.MidRight) +
147 (pSrc[2 + stride2] * m.BottomLeft) + (pSrc[5 + stride2] * m.BottomMid) + (pSrc[8 + stride2] * m.BottomRight)) / m.Factor) + m.Offset);
148
149 if (nPixel < 0) nPixel = 0;
150 if (nPixel > 255) nPixel = 255;
151
152 p[5 + stride]= (byte)nPixel;
153
154 nPixel = ( ( ( (pSrc[1] * m.TopLeft) + (pSrc[4] * m.TopMid) + (pSrc[7] * m.TopRight) +
155 (pSrc[1 + stride] * m.MidLeft) + (pSrc[4 + stride] * m.Pixel) + (pSrc[7 + stride] * m.MidRight) +
156 (pSrc[1 + stride2] * m.BottomLeft) + (pSrc[4 + stride2] * m.BottomMid) + (pSrc[7 + stride2] * m.BottomRight)) / m.Factor) + m.Offset);
157
158 if (nPixel < 0) nPixel = 0;
159 if (nPixel > 255) nPixel = 255;
160
161 p[4 + stride] = (byte)nPixel;
162
163 nPixel = ( ( ( (pSrc[0] * m.TopLeft) + (pSrc[3] * m.TopMid) + (pSrc[6] * m.TopRight) +
164 (pSrc[0 + stride] * m.MidLeft) + (pSrc[3 + stride] * m.Pixel) + (pSrc[6 + stride] * m.MidRight) +
165 (pSrc[0 + stride2] * m.BottomLeft) + (pSrc[3 + stride2] * m.BottomMid) + (pSrc[6 + stride2] * m.BottomRight)) / m.Factor) + m.Offset);
166
167 if (nPixel < 0) nPixel = 0;
168 if (nPixel > 255) nPixel = 255;
169
170 p[3 + stride] = (byte)nPixel;
171
172 p += 3;
173 pSrc += 3;
174 }
175
176 p += nOffset;
177 pSrc += nOffset;
178 }
179 }
180
181 b.UnlockBits(bmData);
182 bSrc.UnlockBits(bmSrc);
183
184 return true;
185 }
Download file with original file name:N0
N0 165 lượt xem
Gõ tìm kiếm nhanh...