PropertyField









How do I use Property Field
Below are practical examples compiled from projects for learning and reference purposes

Featured Snippets


File name: PhotonRigidbody2DViewEditor.cs Copy
7     public override void OnInspectorGUI()
8     {
9         PhotonGUI.ContainerHeader("Options");
10
11         Rect containerRect = PhotonGUI.ContainerBody(EditorGUIUtility.singleLineHeight*2 + 10);
12
13         Rect propertyRect = new Rect(containerRect.xMin + 5, containerRect.yMin + 5, containerRect.width, EditorGUIUtility.singleLineHeight);
14         EditorGUI.PropertyField(propertyRect, serializedObject.FindProperty("m_SynchronizeVelocity"), new GUIContent("Synchronize Velocity"));
15
16         propertyRect.y += EditorGUIUtility.singleLineHeight;
17         EditorGUI.PropertyField(propertyRect, serializedObject.FindProperty("m_SynchronizeAngularVelocity"), new GUIContent("Synchronize Angular Velocity"));
18     }
File name: PhotonRigidbodyViewEditor.cs Copy
7     public override void OnInspectorGUI()
8     {
9         PhotonGUI.ContainerHeader("Options");
10
11         Rect containerRect = PhotonGUI.ContainerBody(EditorGUIUtility.singleLineHeight*2 + 10);
12
13         Rect propertyRect = new Rect(containerRect.xMin + 5, containerRect.yMin + 5, containerRect.width, EditorGUIUtility.singleLineHeight);
14         EditorGUI.PropertyField(propertyRect, serializedObject.FindProperty("m_SynchronizeVelocity"), new GUIContent("Synchronize Velocity"));
15
16         propertyRect.y += EditorGUIUtility.singleLineHeight;
17         EditorGUI.PropertyField(propertyRect, serializedObject.FindProperty("m_SynchronizeAngularVelocity"), new GUIContent("Synchronize Angular Velocity"));
18     }
File name: PhotonTransformViewEditor.cs Copy
181     private void DrawSynchronizePositionDataGizmos(ref Rect propertyRect)
182     {
183         GUI.enabled = true;
184         /*PhotonGUI.DrawGizmoOptions(propertyRect, "Synchronized Position Gizmo",
185             serializedObject.FindProperty("m_PositionModel.DrawNetworkGizmo"),
186             serializedObject.FindProperty("m_PositionModel.NetworkGizmoColor"),
187             serializedObject.FindProperty("m_PositionModel.NetworkGizmoType"),
188             serializedObject.FindProperty("m_PositionModel.NetworkGizmoSize"));
189         propertyRect.y += EDITOR_LINE_HEIGHT;
190
191         PhotonGUI.DrawGizmoOptions(propertyRect, "Extrapolated Position Gizmo",
192             serializedObject.FindProperty("m_PositionModel.DrawExtrapolatedGizmo"),
193             serializedObject.FindProperty("m_PositionModel.ExtrapolatedGizmoColor"),
194             serializedObject.FindProperty("m_PositionModel.ExtrapolatedGizmoType"),
195             serializedObject.FindProperty("m_PositionModel.ExtrapolatedGizmoSize"));
196         propertyRect.y += EDITOR_LINE_HEIGHT;*/
197
198         EditorGUI.PropertyField(propertyRect, serializedObject.FindProperty("m_PositionModel.DrawErrorGizmo"),
199             new GUIContent("Draw synchronized position error"));
200         propertyRect.y += EDITOR_LINE_HEIGHT;
201     }
File name: PhotonTransformViewEditor.cs Copy
220     private void DrawPropertyWithHelpIcon(ref Rect propertyRect, ref bool isHelpOpen, SerializedProperty property, string tooltip)
221     {
222         Rect propertyFieldRect = new Rect(propertyRect.xMin, propertyRect.yMin, propertyRect.width - 20, propertyRect.height);
223         string propertyName = ObjectNames.NicifyVariableName(property.name);
224         EditorGUI.PropertyField(propertyFieldRect, property, new GUIContent(propertyName, tooltip));
225
226         Rect helpIconRect = new Rect(propertyFieldRect.xMax + 5, propertyFieldRect.yMin, 20, propertyFieldRect.height);
227         isHelpOpen = GUI.Toggle(helpIconRect, isHelpOpen, PhotonGUI.HelpIcon, GUIStyle.none);
228
229         propertyRect.y += EDITOR_LINE_HEIGHT;
230     }
File name: PhotonTransformViewEditor.cs Copy
232     private void DrawSynchronizePositionDataExtrapolation(ref Rect propertyRect, SerializedProperty extrapolatePositionProperty, PhotonTransformViewPositionModel.ExtrapolateOptions extrapolateOption)
233     {
234         DrawPropertyWithHelpIcon(ref propertyRect, ref this.m_ExtrapolateHelpOpen, extrapolatePositionProperty, EXTRAPOLATE_TOOLTIP);
235         DrawHelpBox(ref propertyRect, this.m_ExtrapolateHelpOpen, GetExtrapolateHelpBoxHeight(), EXTRAPOLATE_HELP, EXTRAPOLATE_HELP_URL);
236
237         if (extrapolateOption != PhotonTransformViewPositionModel.ExtrapolateOptions.Disabled)
238         {
239             EditorGUI.PropertyField(propertyRect, serializedObject.FindProperty("m_PositionModel.ExtrapolateIncludingRoundTripTime"));
240             propertyRect.y += EDITOR_LINE_HEIGHT;
241         }
242
243         switch (extrapolateOption)
244         {
245             case PhotonTransformViewPositionModel.ExtrapolateOptions.FixedSpeed:
246                 EditorGUI.PropertyField(propertyRect, serializedObject.FindProperty("m_PositionModel.ExtrapolateSpeed"));
247                 propertyRect.y += EDITOR_LINE_HEIGHT;
248                 break;
249         }
250     }
File name: PhotonTransformViewEditor.cs Copy
252     private void DrawTeleport(ref Rect propertyRect)
253     {
254         EditorGUI.PropertyField(propertyRect, serializedObject.FindProperty("m_PositionModel.TeleportEnabled"),
255             new GUIContent("Enable teleport for great distances"));
256         propertyRect.y += EDITOR_LINE_HEIGHT;
257
258         EditorGUI.PropertyField(propertyRect, serializedObject.FindProperty("m_PositionModel.TeleportIfDistanceGreaterThan"),
259             new GUIContent("Teleport if distance greater than"));
260         propertyRect.y += EDITOR_LINE_HEIGHT;
261     }
File name: PhotonTransformViewEditor.cs Copy
264         PhotonTransformViewPositionModel.InterpolateOptions interpolateOption)
265     {
266         DrawPropertyWithHelpIcon(ref propertyRect, ref this.m_InterpolateHelpOpen, interpolatePositionProperty, INTERPOLATE_TOOLTIP);
267         DrawHelpBox(ref propertyRect, this.m_InterpolateHelpOpen, GetInterpolateHelpBoxHeight(), INTERPOLATE_HELP, INTERPOLATE_HELP_URL);
268
269         switch (interpolateOption)
270         {
271             case PhotonTransformViewPositionModel.InterpolateOptions.FixedSpeed:
272                 EditorGUI.PropertyField(propertyRect, serializedObject.FindProperty("m_PositionModel.InterpolateMoveTowardsSpeed"),
273                     new GUIContent("MoveTowards Speed"));
274                 propertyRect.y += EDITOR_LINE_HEIGHT;
275                 break;
276
277             case PhotonTransformViewPositionModel.InterpolateOptions.Lerp:
278                 EditorGUI.PropertyField(propertyRect, serializedObject.FindProperty("m_PositionModel.InterpolateLerpSpeed"), new GUIContent("Lerp Speed"));
279                 propertyRect.y += EDITOR_LINE_HEIGHT;
280                 break;
281
282             /*case PhotonTransformViewPositionModel.InterpolateOptions.MoveTowardsComplex:
283                 Rect curveRect = new Rect(propertyRect.xMin, propertyRect.yMin, propertyRect.width - 100, propertyRect.height);
284                 EditorGUI.PropertyField(curveRect, serializedObject.FindProperty("m_PositionModel.InterpolateSpeedCurve"), new GUIContent("MoveTowards Speed Curve"));
285
286                 Rect labelRect = new Rect(propertyRect.xMax - 95, propertyRect.yMin, 10, propertyRect.height);
287                 GUI.Label(labelRect, "x");
288
289                 Rect multiplierRect = new Rect(propertyRect.xMax - 80, propertyRect.yMin, 80, propertyRect.height);
290                 EditorGUI.PropertyField(multiplierRect, serializedObject.FindProperty("m_PositionModel.InterpolateMoveTowardsSpeed"), GUIContent.none);
291                 propertyRect.y += EDITOR_LINE_HEIGHT;
292
293                 EditorGUI.PropertyField(propertyRect, serializedObject.FindProperty("m_PositionModel.InterpolateMoveTowardsAcceleration"),
294                     new GUIContent("Acceleration"));
295                 propertyRect.y += EDITOR_LINE_HEIGHT;
296
297                 EditorGUI.PropertyField(propertyRect, serializedObject.FindProperty("m_PositionModel.InterpolateMoveTowardsDeceleration"),
298                     new GUIContent("Deceleration"));
299                 propertyRect.y += EDITOR_LINE_HEIGHT;
300                 break;*/
301         }
302     }
File name: PhotonTransformViewEditor.cs Copy
309     private void DrawSynchronizeRotationData()
310     {
311         if (this.m_SynchronizeRotationProperty == null || this.m_SynchronizeRotationProperty.boolValue == false)
312         {
313             return;
314         }
315
316         SerializedProperty interpolateRotationProperty = serializedObject.FindProperty("m_RotationModel.InterpolateOption");
317         PhotonTransformViewRotationModel.InterpolateOptions interpolateOption =
318             (PhotonTransformViewRotationModel.InterpolateOptions) interpolateRotationProperty.enumValueIndex;
319
320         float containerHeight = 20;
321
322         switch (interpolateOption)
323         {
324             case PhotonTransformViewRotationModel.InterpolateOptions.RotateTowards:
325             case PhotonTransformViewRotationModel.InterpolateOptions.Lerp:
326                 containerHeight += EDITOR_LINE_HEIGHT;
327                 break;
328         }
329
330         if (this.m_InterpolateRotationHelpOpen == true)
331         {
332             containerHeight += GetInterpolateHelpBoxHeight();
333         }
334
335         Rect rect = PhotonGUI.ContainerBody(containerHeight);
336         Rect propertyRect = new Rect(rect.xMin + 5, rect.yMin + 2, rect.width - 10, EditorGUIUtility.singleLineHeight);
337
338         DrawPropertyWithHelpIcon(ref propertyRect, ref this.m_InterpolateRotationHelpOpen, interpolateRotationProperty, INTERPOLATE_TOOLTIP);
339         DrawHelpBox(ref propertyRect, this.m_InterpolateRotationHelpOpen, GetInterpolateHelpBoxHeight(), INTERPOLATE_HELP, INTERPOLATE_HELP_URL);
340
341         switch (interpolateOption)
342         {
343             case PhotonTransformViewRotationModel.InterpolateOptions.RotateTowards:
344                 EditorGUI.PropertyField(propertyRect, serializedObject.FindProperty("m_RotationModel.InterpolateRotateTowardsSpeed"),
345                     new GUIContent("RotateTowards Speed"));
346                 break;
347             case PhotonTransformViewRotationModel.InterpolateOptions.Lerp:
348                 EditorGUI.PropertyField(propertyRect, serializedObject.FindProperty("m_RotationModel.InterpolateLerpSpeed"), new GUIContent("Lerp Speed"));
349                 break;
350         }
351     }
File name: PhotonTransformViewEditor.cs Copy
358     private void DrawSynchronizeScaleData()
359     {
360         if (this.m_SynchronizeScaleProperty == null || this.m_SynchronizeScaleProperty.boolValue == false)
361         {
362             return;
363         }
364
365         SerializedProperty interpolateScaleProperty = serializedObject.FindProperty("m_ScaleModel.InterpolateOption");
366         PhotonTransformViewScaleModel.InterpolateOptions interpolateOption = (PhotonTransformViewScaleModel.InterpolateOptions) interpolateScaleProperty.enumValueIndex;
367
368         float containerHeight = EDITOR_LINE_HEIGHT;
369
370         switch (interpolateOption)
371         {
372             case PhotonTransformViewScaleModel.InterpolateOptions.MoveTowards:
373             case PhotonTransformViewScaleModel.InterpolateOptions.Lerp:
374                 containerHeight += EDITOR_LINE_HEIGHT;
375                 break;
376         }
377
378         if (this.m_InterpolateScaleHelpOpen == true)
379         {
380             containerHeight += GetInterpolateHelpBoxHeight();
381         }
382
383         Rect rect = PhotonGUI.ContainerBody(containerHeight);
384         Rect propertyRect = new Rect(rect.xMin + 5, rect.yMin + 2, rect.width - 10, EditorGUIUtility.singleLineHeight);
385
386         DrawPropertyWithHelpIcon(ref propertyRect, ref this.m_InterpolateScaleHelpOpen, interpolateScaleProperty, INTERPOLATE_TOOLTIP);
387         DrawHelpBox(ref propertyRect, this.m_InterpolateScaleHelpOpen, GetInterpolateHelpBoxHeight(), INTERPOLATE_HELP, INTERPOLATE_HELP_URL);
388
389         switch (interpolateOption)
390         {
391             case PhotonTransformViewScaleModel.InterpolateOptions.MoveTowards:
392                 EditorGUI.PropertyField(propertyRect, serializedObject.FindProperty("m_ScaleModel.InterpolateMoveTowardsSpeed"),
393                     new GUIContent("MoveTowards Speed"));
394                 break;
395             case PhotonTransformViewScaleModel.InterpolateOptions.Lerp:
396                 EditorGUI.PropertyField(propertyRect, serializedObject.FindProperty("m_ScaleModel.InterpolateLerpSpeed"), new GUIContent("Lerp Speed"));
397                 break;
398         }
399     }
File name: PhotonGUI.cs Copy
197         SerializedProperty gizmoSizeProperty )
198     {
199         float height = EditorGUIUtility.singleLineHeight;
200         float flexibleWidth = Mathf.Max( 40, position.width - EditorGUIUtility.labelWidth - 20 - 75 - 5 - 40 - 5 );
201
202         Rect labelRect = new Rect( position.xMin, position.yMin, EditorGUIUtility.labelWidth, height );
203         GUI.Label( labelRect, label );
204
205         Rect enabledRect = new Rect( labelRect.xMax, labelRect.yMin, 20, height );
206         EditorGUI.PropertyField( enabledRect, gizmoEnabledProperty, GUIContent.none );
207
208         bool oldGUIEnabled = GUI.enabled;
209         GUI.enabled = gizmoEnabledProperty.boolValue;
210
211         Rect colorRect = new Rect( enabledRect.xMax + 5, labelRect.yMin, 70, height );
212         EditorGUI.PropertyField( colorRect, gizmoColorProperty, GUIContent.none );
213
214         Rect typeRect = new Rect( colorRect.xMax + 5, labelRect.yMin, flexibleWidth * 0.7f, height );
215         EditorGUI.PropertyField( typeRect, gizmoTypeProperty, GUIContent.none );
216
217         Rect sizeLabelRect = new Rect( typeRect.xMax + 10, labelRect.yMin, 30, height );
218         GUI.Label( sizeLabelRect, "Size" );
219
220         Rect sizeRect = new Rect( sizeLabelRect.xMax + 5, labelRect.yMin, flexibleWidth * 0.3f, height );
221         EditorGUI.PropertyField( sizeRect, gizmoSizeProperty, GUIContent.none );
222
223         GUI.enabled = oldGUIEnabled;
224     }

PropertyField 101 lượt xem

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