UserNamePlayerPref
How do I use User Name Player Pref
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
Line | Code | Ex.. |
---|---|---|
31 | string prefsName = PlayerPrefs.GetString(NamePickGui.UserNamePlayerPref); | 1 |
89 | PlayerPrefs.SetString(NamePickGui.UserNamePlayerPref, this.InputLine); | 2 |
File name: NamePickGui.cs
Copy
15 public void Awake()
16 {
17 this.guiCenteredRect = new Rect(Screen.width/2-GuiSize.x/2, Screen.height/2-GuiSize.y/4, GuiSize.x, GuiSize.y);
18 this.chatComponent = this.GetComponent
19
20 if (this.chatComponent != null && chatComponent.enabled)
21 {
22 Debug.LogWarning("When using the NamePickGui, ChatGui should be disabled initially.");
23
24 if (this.chatComponent.chatClient != null)
25 {
26 this.chatComponent.chatClient.Disconnect();
27 }
28 this.chatComponent.enabled = false;
29 }
30
31 string prefsName = PlayerPrefs.GetString(NamePickGui.UserNamePlayerPref);
32 if (!string.IsNullOrEmpty(prefsName))
33 {
34 this.InputLine = prefsName;
35 }
36 }
File name: NamePickGui.cs
Copy
83 private void StartChat()
84 {
85 this.chatComponent.UserName = this.InputLine;
86 this.chatComponent.enabled = true;
87 this.enabled = false;
88
89 PlayerPrefs.SetString(NamePickGui.UserNamePlayerPref, this.InputLine);
90 }
UserNamePlayerPref 128 lượt xem
Gõ tìm kiếm nhanh...