ApplyModifiedProperties









How do I use Apply Modified Properties
Below are practical examples compiled from projects for learning and reference purposes

Featured Snippets


File name: PhotonAnimatorViewEditor.cs Copy
18     public override void OnInspectorGUI()
19     {
20         //base.OnInspectorGUI();
21
22         if (this.m_Animator == null)
23         {
24             GUILayout.BeginVertical(GUI.skin.box);
25             GUILayout.Label("GameObject doesn't have an Animator component to synchronize");
26             GUILayout.EndVertical();
27             return;
28         }
29
30         DrawWeightInspector();
31
32         if (this.m_Animator.layerCount == 0)
33         {
34             GUILayout.BeginVertical(GUI.skin.box);
35             GUILayout.Label("Animator doesn't have any layers setup to synchronize");
36             GUILayout.EndVertical();
37         }
38
39         DrawParameterInspector();
40
41         if (GetParameterCount() == 0)
42         {
43             GUILayout.BeginVertical(GUI.skin.box);
44             GUILayout.Label("Animator doesn't have any parameters setup to synchronize");
45             GUILayout.EndVertical();
46         }
47
48         serializedObject.ApplyModifiedProperties();
49
50         //GUILayout.Label( "m_SynchronizeLayers " + serializedObject.FindProperty( "m_SynchronizeLayers" ).arraySize );
51         //GUILayout.Label( "m_SynchronizeParameters " + serializedObject.FindProperty( "m_SynchronizeParameters" ).arraySize );
52     }
File name: PhotonTransformViewEditor.cs Copy
47     public override void OnInspectorGUI()
48     {
49         this.m_Target = (PhotonTransformView) target;
50
51         DrawIsPlayingWarning();
52         GUI.enabled = !Application.isPlaying;
53
54         DrawSynchronizePositionHeader();
55         DrawSynchronizePositionData();
56
57         GUI.enabled = !Application.isPlaying;
58         DrawSynchronizeRotationHeader();
59         DrawSynchronizeRotationData();
60
61         GUI.enabled = !Application.isPlaying;
62         DrawSynchronizeScaleHeader();
63         DrawSynchronizeScaleData();
64
65         serializedObject.ApplyModifiedProperties();
66
67         GUI.enabled = true;
68     }
File name: PhotonViewInspector.cs Copy
258     void DrawObservedComponentsList()
259     {
260         GUILayout.Space( 5 );
261         SerializedProperty listProperty = serializedObject.FindProperty( "ObservedComponents" );
262
263         if( listProperty == null )
264         {
265             return;
266         }
267
268         float containerElementHeight = 22;
269         float containerHeight = listProperty.arraySize * containerElementHeight;
270
271         bool isOpen = PhotonGUI.ContainerHeaderFoldout( "Observed Components (" + GetObservedComponentsCount() + ")", serializedObject.FindProperty( "ObservedComponentsFoldoutOpen" ).boolValue );
272         serializedObject.FindProperty( "ObservedComponentsFoldoutOpen" ).boolValue = isOpen;
273
274         if( isOpen == false )
275         {
276             containerHeight = 0;
277         }
278
279         //Texture2D statsIcon = AssetDatabase.LoadAssetAtPath( "Assets/Photon Unity Networking/Editor/PhotonNetwork/PhotonViewStats.png", typeof( Texture2D ) ) as Texture2D;
280
281         Rect containerRect = PhotonGUI.ContainerBody( containerHeight );
282         bool wasObservedComponentsEmpty = m_Target.ObservedComponents.FindAll( item => item != null ).Count == 0;
283         if( isOpen == true )
284         {
285             for( int i = 0; i < listProperty.arraySize; ++i )
286             {
287                 Rect elementRect = new Rect( containerRect.xMin, containerRect.yMin + containerElementHeight * i, containerRect.width, containerElementHeight );
288                 {
289                     Rect texturePosition = new Rect( elementRect.xMin + 6, elementRect.yMin + elementRect.height / 2f - 1, 9, 5 );
290                     ReorderableListResources.DrawTexture( texturePosition, ReorderableListResources.texGrabHandle );
291
292                     Rect propertyPosition = new Rect( elementRect.xMin + 20, elementRect.yMin + 3, elementRect.width - 45, 16 );
293                     EditorGUI.PropertyField( propertyPosition, listProperty.GetArrayElementAtIndex( i ), new GUIContent() );
294
295                     //Debug.Log( listProperty.GetArrayElementAtIndex( i ).objectReferenceValue.GetType() );
296                     //Rect statsPosition = new Rect( propertyPosition.xMax + 7, propertyPosition.yMin, statsIcon.width, statsIcon.height );
297                     //ReorderableListResources.DrawTexture( statsPosition, statsIcon );
298
299                     Rect removeButtonRect = new Rect( elementRect.xMax - PhotonGUI.DefaultRemoveButtonStyle.fixedWidth,
300                                                         elementRect.yMin + 2,
301                                                         PhotonGUI.DefaultRemoveButtonStyle.fixedWidth,
302                                                         PhotonGUI.DefaultRemoveButtonStyle.fixedHeight );
303
304                     GUI.enabled = listProperty.arraySize > 1;
305                     if( GUI.Button( removeButtonRect, new GUIContent( ReorderableListResources.texRemoveButton ), PhotonGUI.DefaultRemoveButtonStyle ) )
306                     {
307                         listProperty.DeleteArrayElementAtIndex( i );
308                     }
309                     GUI.enabled = true;
310
311                     if( i < listProperty.arraySize - 1 )
312                     {
313                         texturePosition = new Rect( elementRect.xMin + 2, elementRect.yMax, elementRect.width - 4, 1 );
314                         PhotonGUI.DrawSplitter( texturePosition );
315                     }
316                 }
317             }
318         }
319
320         if( PhotonGUI.AddButton() )
321         {
322             listProperty.InsertArrayElementAtIndex( Mathf.Max( 0, listProperty.arraySize - 1 ) );
323         }
324
325         serializedObject.ApplyModifiedProperties();
326
327         bool isObservedComponentsEmpty = m_Target.ObservedComponents.FindAll( item => item != null ).Count == 0;
328
329         if( wasObservedComponentsEmpty == true && isObservedComponentsEmpty == false && m_Target.synchronization == ViewSynchronization.Off )
330         {
331             m_Target.synchronization = ViewSynchronization.UnreliableOnChange;
332             EditorUtility.SetDirty( m_Target );
333             serializedObject.Update();
334         }
335
336         if( wasObservedComponentsEmpty == false && isObservedComponentsEmpty == true )
337         {
338             m_Target.synchronization = ViewSynchronization.Off;
339             EditorUtility.SetDirty( m_Target );
340             serializedObject.Update();
341         }
342
343     }
File name: ServerSettingsInspector.cs Copy
17     public override void OnInspectorGUI()
18     {
19         ServerSettings settings = (ServerSettings)this.target;
20
21         #if UNITY_3_5
22         EditorGUIUtility.LookLikeInspector();
23         #endif
24
25
26         settings.HostType = (ServerSettings.HostingOption)EditorGUILayout.EnumPopup("Hosting", settings.HostType);
27         EditorGUI.indentLevel = 1;
28
29         switch (settings.HostType)
30         {
31             case ServerSettings.HostingOption.BestRegion:
32             case ServerSettings.HostingOption.PhotonCloud:
33                 if (settings.HostType == ServerSettings.HostingOption.PhotonCloud)
34                     settings.PreferredRegion = (CloudRegionCode)EditorGUILayout.EnumPopup("Region", settings.PreferredRegion);
35                 settings.AppID = EditorGUILayout.TextField("AppId", settings.AppID);
36                 settings.Protocol = (ConnectionProtocol)EditorGUILayout.EnumPopup("Protocol", settings.Protocol);
37
38                 if (string.IsNullOrEmpty(settings.AppID) || settings.AppID.Equals("master"))
39                 {
40                     EditorGUILayout.HelpBox("The Photon Cloud needs an AppId (GUID) set.\nYou can find it online in your Dashboard.", MessageType.Warning);
41                 }
42                 break;
43
44             case ServerSettings.HostingOption.SelfHosted:
45                 bool hidePort = false;
46                 if (settings.Protocol == ConnectionProtocol.Udp && (settings.ServerPort == 4530 || settings.ServerPort == 0))
47                 {
48                     settings.ServerPort = 5055;
49                 }
50                 else if (settings.Protocol == ConnectionProtocol.Tcp && (settings.ServerPort == 5055 || settings.ServerPort == 0))
51                 {
52                     settings.ServerPort = 4530;
53                 }
54                 #if RHTTP
55                 if (settings.Protocol == ConnectionProtocol.RHttp)
56                 {
57                     settings.ServerPort = 0;
58                     hidePort = true;
59                 }
60                 #endif
61                 settings.ServerAddress = EditorGUILayout.TextField("Server Address", settings.ServerAddress);
62                 settings.ServerAddress = settings.ServerAddress.Trim();
63                 if (!hidePort)
64                 {
65                     settings.ServerPort = EditorGUILayout.IntField("Server Port", settings.ServerPort);
66                 }
67                 settings.Protocol = (ConnectionProtocol)EditorGUILayout.EnumPopup("Protocol", settings.Protocol);
68                 settings.AppID = EditorGUILayout.TextField("AppId", settings.AppID);
69                 break;
70
71             case ServerSettings.HostingOption.OfflineMode:
72                 EditorGUI.indentLevel = 0;
73                 EditorGUILayout.HelpBox("In 'Offline Mode', the client does not communicate with a server.\nAll settings are hidden currently.", MessageType.Info);
74                 break;
75
76             case ServerSettings.HostingOption.NotSet:
77                 EditorGUI.indentLevel = 0;
78                 EditorGUILayout.HelpBox("Hosting is 'Not Set'.\nConnectUsingSettings() will not be able to connect.\nSelect another option or run the PUN Wizard.", MessageType.Info);
79                 break;
80
81             default:
82                 DrawDefaultInspector();
83                 break;
84         }
85
86         if (PhotonEditor.CheckPunPlus())
87         {
88             settings.Protocol = ConnectionProtocol.Udp;
89             EditorGUILayout.HelpBox("You seem to use PUN+.\nPUN+ only supports reliable UDP so the protocol is locked.", MessageType.Info);
90         }
91
92         settings.AppID = settings.AppID.Trim();
93
94         EditorGUI.indentLevel = 0;
95         SerializedObject sObj = new SerializedObject(this.target);
96         SerializedProperty sRpcs = sObj.FindProperty("RpcList");
97         EditorGUILayout.PropertyField(sRpcs, true);
98         sObj.ApplyModifiedProperties();
99
100         GUILayout.BeginHorizontal();
101         GUILayout.Space(20);
102         if (GUILayout.Button("Refresh RPCs"))
103         {
104             PhotonEditor.UpdateRpcList();
105             Repaint();
106         }
107         if (GUILayout.Button("Clear RPCs"))
108         {
109             PhotonEditor.ClearRpcList();
110         }
111         if (GUILayout.Button("Log HashCode"))
112         {
113             Debug.Log("RPC-List HashCode: " + RpcListHashCode() + ". Make sure clients that send each other RPCs have the same RPC-List.");
114         }
115         GUILayout.Space(20);
116         GUILayout.EndHorizontal();
117
118         //SerializedProperty sp = serializedObject.FindProperty("RpcList");
119         //EditorGUILayout.PropertyField(sp, true);
120
121         if (GUI.changed)
122         {
123             EditorUtility.SetDirty(target);
124         }
125     }

ApplyModifiedProperties 114 lượt xem

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