EditorPrefs
How do I use Editor Prefs
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
File name: PunStartup.cs
Copy
25 static PunStartup()
26 {
27 bool doneBefore = EditorPrefs.GetBool("PunDemosOpenedBefore");
28 if (!doneBefore)
29 {
30 EditorApplication.update += OnUpdate;
31 }
32 }
File name: PunStartup.cs
Copy
34 static void OnUpdate()
35 {
36 bool doneBefore = EditorPrefs.GetBool("PunDemosOpenedBefore");
37 if (doneBefore)
38 {
39 EditorApplication.update -= OnUpdate;
40 return;
41 }
42
43 if (String.IsNullOrEmpty(EditorApplication.currentScene) && EditorBuildSettings.scenes.Length == 0)
44 {
45 #if UNITY_4_2 || UNITY_4_3 || UNITY_4_4 || UNITY_4_5 || UNITY_4_6 || UNITY_5 || UNITY_5_1 || UNITY_5_2
46 if (EditorApplication.isUpdating) return;
47 #endif
48
49 LoadPunDemoHub();
50 SetPunDemoBuildSettings();
51 EditorPrefs.SetBool("PunDemosOpenedBefore", true);
52 Debug.Log("No scene was open. Loaded PUN Demo Hub Scene and added demos to build settings. Ready to go! This auto-setup is now disabled in this Editor.");
53 }
54 }
File name: VSCode.cs
Copy
48 {
49 get
50 {
51 string current = EditorPrefs.GetString("VSCode_CodePath", "");
52 if(current == "" || !VSCodeExists(current))
53 {
54 //Value not set, set to "" or current path is invalid, try to autodetect it
55 //If autodetect fails, a error will be printed and the default value set
56 EditorPrefs.SetString("VSCode_CodePath", AutodetectCodePath());
57 //If its not installed or the install folder isn't a "normal" one,
58 //AutodetectCodePath will print a error message to the Unity Console
59 }
60 return EditorPrefs.GetString("VSCode_CodePath", current);
61 }
62 set
63 {
64 EditorPrefs.SetString("VSCode_CodePath", value);
65 }
66 }
File name: VSCode.cs
Copy
88 {
89 get
90 {
91 return EditorPrefs.GetBool("VSCode_Debug", false);
92 }
93 set
94 {
95 EditorPrefs.SetBool("VSCode_Debug", value);
96 }
97 }
File name: VSCode.cs
Copy
106 {
107 get
108 {
109 return EditorPrefs.GetBool("VSCode_Enabled", false);
110 }
111 set
112 {
113 // When turning the plugin on, we should remove all the previous project files
114 if (!Enabled && value)
115 {
116 ClearProjectFiles();
117 }
118 EditorPrefs.SetBool("VSCode_Enabled", value);
119 }
120 }
File name: VSCode.cs
Copy
122 {
123 get
124 {
125 return EditorPrefs.GetBool("VSCode_UseUnityDebugger", false);
126 }
127 set
128 {
129 if ( value != UseUnityDebugger ) {
130
131 // Set value
132 EditorPrefs.SetBool("VSCode_UseUnityDebugger", value);
133
134 // Do not write the launch JSON file because the debugger uses its own
135 if ( value ) {
136 WriteLaunchFile = false;
137 }
138
139 // Update launch file
140 UpdateLaunchFile();
141 }
142 }
143 }
File name: VSCode.cs
Copy
149 {
150 get
151 {
152 return EditorPrefs.GetBool("VSCode_AutoOpenEnabled", false);
153 }
154 set
155 {
156 EditorPrefs.SetBool("VSCode_AutoOpenEnabled", value);
157 }
158 }
File name: VSCode.cs
Copy
167 {
168 get
169 {
170 return EditorPrefs.GetBool("VSCode_WriteLaunchFile", true);
171 }
172 set
173 {
174 EditorPrefs.SetBool("VSCode_WriteLaunchFile", value);
175 }
176 }
File name: VSCode.cs
Copy
182 {
183 get
184 {
185 return EditorPrefs.GetBool("VSCode_AutomaticUpdates", false);
186 }
187 set
188 {
189 EditorPrefs.SetBool("VSCode_AutomaticUpdates", value);
190 }
191 }
File name: VSCode.cs
Copy
194 {
195 get
196 {
197 return EditorPrefs.GetFloat("VSCode_GitHubVersion", Version);
198 }
199 set
200 {
201 EditorPrefs.SetFloat("VSCode_GitHubVersion", value);
202 }
203 }
EditorPrefs 106 lượt xem
Gõ tìm kiếm nhanh...