Image
How do I use Image
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
File name: PhotonConverter.cs
Copy
160 static void ConvertScripts(List161 {
162 bool ignoreWarningIsLogged = false;
163
164 foreach (string script in scriptPathList)
165 {
166 if (script.Contains("PhotonNetwork")) //Don't convert this file (and others)
167 {
168 if (!ignoreWarningIsLogged)
169 {
170 ignoreWarningIsLogged = true;
171 Debug.LogWarning("Conversion to PUN ignores all files with \"PhotonNetwork\" in their file-path.\nCheck: " + script);
172 }
173 continue;
174 }
175 if (script.Contains("Image Effects"))
176 {
177 continue;
178 }
179
180 ConvertToPhotonAPI(script);
181 }
182
183 foreach (string script in scriptPathList)
184 {
185 AssetDatabase.ImportAsset(script, ImportAssetOptions.ForceUpdate);
186 }
187 }
File name: PhotonGUI.cs
Copy
69 {
70 get
71 {
72 if( m_DefaultRemoveButtonStyle == null )
73 {
74 m_DefaultRemoveButtonStyle = new GUIStyle();
75 m_DefaultRemoveButtonStyle.fixedWidth = 30;
76 m_DefaultRemoveButtonStyle.fixedHeight = 20;
77 m_DefaultRemoveButtonStyle.active.background = ReorderableListResources.CreatePixelTexture( "Dark Pixel (List GUI)", new Color32( 18, 18, 18, 255 ) );
78 m_DefaultRemoveButtonStyle.imagePosition = ImagePosition.ImageOnly;
79 m_DefaultRemoveButtonStyle.alignment = TextAnchor.MiddleCenter;
80 }
81
82 return m_DefaultRemoveButtonStyle;
83 }
84 }
File name: ReorderableListResources.cs
Copy
168 private static void LoadResourceAssets()
169 {
170 var skin = EditorGUIUtility.isProSkin ? s_DarkSkin : s_LightSkin;
171 s_Cached = new Texture2D[ skin.Length ];
172
173 for( int i = 0; i < s_Cached.Length; ++i )
174 {
175 // Get image data (PNG) from base64 encoded strings.
176 byte[] imageData = Convert.FromBase64String( skin[ i ] );
177
178 // Gather image size from image data.
179 int texWidth, texHeight;
180 GetImageSize( imageData, out texWidth, out texHeight );
181
182 // Generate texture asset.
183 var tex = new Texture2D( texWidth, texHeight, TextureFormat.ARGB32, false, true );
184 tex.hideFlags = HideFlags.HideAndDontSave;
185 tex.name = "(Generated) ReorderableList:" + i;
186 tex.filterMode = FilterMode.Point;
187 tex.LoadImage( imageData );
188
189 s_Cached[ i ] = tex;
190 }
191
192 s_LightSkin = null;
193 s_DarkSkin = null;
194 }
File name: ReorderableListResources.cs
Copy
202 private static void GetImageSize( byte[] imageData, out int width, out int height )
203 {
204 width = ReadInt( imageData, 3 + 15 );
205 height = ReadInt( imageData, 3 + 15 + 2 + 2 );
206 }
File name: ReorderableListResources.cs
Copy
208 private static int ReadInt( byte[] imageData, int offset )
209 {
210 return ( imageData[ offset ] << 8 ) | imageData[ offset + 1 ];
211 }
File name: GameManagerScript.cs
Copy
97 public void ifPlayerDiedScore(int score) {
98 bestScore.text = "Best Score: " + PlayerMoveScript.instance.scoreCount;
99
100 if (score > Scores.instance.GetHighScore ()) {
101 Scores.instance.SetHighScore (score);
102 newHighScoreText.gameObject.SetActive (true);
103 highScoresImage.gameObject.SetActive (true);
104 audioSource.PlayOneShot (cheerClip);
105 Debug.Log ("New High Score");
106 }
107
108 bestScore.text = "Best Score: " + Scores.instance.GetHighScore ();
109 }
File name: GameManagerScript.cs
Copy
111 public void ifPlayerDiedCoinScore(int score) {
112 highCoinScore.text = "Best Coin Score: " + coinScore;
113
114 if (score > Scores.instance.GetHighCoinScore ()) {
115 Scores.instance.SetHighCoinScore (score);
116 newHighCoinText.gameObject.SetActive (true);
117 highScoresImage.gameObject.SetActive (true);
118 audioSource.PlayOneShot (cheerClip);
119 }
120
121 highCoinScore.text = "Best Coin Score: " + Scores.instance.GetHighCoinScore ();
122 }
File name: MenuManager.cs
Copy
33 public void instructionMenu () {
34 instructionPanel.SetActive (true);
35 playButton.gameObject.SetActive (false);
36 quitButton.gameObject.SetActive (false);
37 menuButton.gameObject.SetActive (false);
38 image.SetActive (false);
39 }
File name: MenuManager.cs
Copy
45 public void closeInstruction () {
46 instructionPanel.SetActive (false);
47 playButton.gameObject.SetActive (true);
48 quitButton.gameObject.SetActive (true);
49 menuButton.gameObject.SetActive (true);
50 image.SetActive (true);
51 }
File name: GameManager.cs
Copy
38 void CheckToPlayMusic() {
39 if (Game.GetMusicState() == 1)
40 {
41 MusicController.instance.PlayMusic(true);
42 musicBtn.image.sprite = musicIcons[1];
43 } else {
44 MusicController.instance.PlayMusic(false);
45 musicBtn.image.sprite = musicIcons[0];
46 }
47 }
Download file with original file name:Image
Image 225 lượt xem
Gõ tìm kiếm nhanh...