IsPlaying









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

Featured Snippets


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: PhotonTransformViewEditor.cs Copy
70     private void DrawIsPlayingWarning()
71     {
72         if (Application.isPlaying == false)
73         {
74             return;
75         }
76
77         GUILayout.BeginVertical(GUI.skin.box);
78         {
79             GUILayout.Label("Editing is disabled in play mode so the two objects don't go out of sync");
80         }
81         GUILayout.EndVertical();
82     }
File name: PhotonEditor.cs Copy
250     private static void ImportWin8Support()
251     {
252         if (EditorApplication.isCompiling || EditorApplication.isPlayingOrWillChangePlaymode)
253         {
254             return; // don't import while compiling
255         }
256
257         #if UNITY_4_2 || UNITY_4_3 || UNITY_4_4 || UNITY_4_5 || UNITY_4_6 || UNITY_5 || UNITY_5_1 || UNITY_5_2
258         const string win8Package = "Assets/Plugins/Photon3Unity3D-Win8.unitypackage";
259
260         bool win8LibsExist = File.Exists("Assets/Plugins/WP8/Photon3Unity3D.dll") && File.Exists("Assets/Plugins/Metro/Photon3Unity3D.dll");
261         if (!win8LibsExist && File.Exists(win8Package))
262         {
263             AssetDatabase.ImportPackage(win8Package, false);
264         }
265         #endif
266     }
File name: PhotonEditor.cs Copy
318     private static void OnUpdate()
319     {
320         // after a compile, check RPCs to create a cache-list
321         if (!postCompileActionsDone && !EditorApplication.isCompiling && !EditorApplication.isPlayingOrWillChangePlaymode && PhotonEditor.Current != null)
322         {
323             #if UNITY_4_2 || UNITY_4_3 || UNITY_4_4 || UNITY_4_5 || UNITY_4_6 || UNITY_5 || UNITY_5_1 || UNITY_5_2
324             if (EditorApplication.isUpdating) return;
325             #endif
326
327             PhotonEditor.UpdateRpcList();
328             postCompileActionsDone = true; // on compile, this falls back to false (without actively doing anything)
329
330             #if UNITY_4_2 || UNITY_4_3 || UNITY_4_4 || UNITY_4_5 || UNITY_4_6 || UNITY_5 || UNITY_5_1 || UNITY_5_2
331             PhotonEditor.ImportWin8Support();
332             #endif
333         }
334     }
File name: PhotonEditor.cs Copy
367     // called in editor on change of play-mode (used to show a message popup that connection settings are incomplete)
368     private static void PlaymodeStateChanged()
369     {
370         if (dontCheckPunSetup || EditorApplication.isPlaying || !EditorApplication.isPlayingOrWillChangePlaymode)
371         {
372             return;
373         }
374
375         if (PhotonEditor.Current.HostType == ServerSettings.HostingOption.NotSet)
376         {
377             EditorUtility.DisplayDialog(CurrentLang.SetupWizardWarningTitle, CurrentLang.SetupWizardWarningMessage, CurrentLang.OkButton);
378         }
379     }
File name: PhotonViewHandler.cs Copy
25     internal static void HierarchyChange()
26     {
27         if (Application.isPlaying)
28         {
29             //Debug.Log("HierarchyChange ignored, while running.");
30             CheckSceneForStuckHandlers = true; // done once AFTER play mode.
31             return;
32         }
33
34         if (CheckSceneForStuckHandlers)
35         {
36             CheckSceneForStuckHandlers = false;
37             PhotonNetwork.InternalCleanPhotonMonoFromSceneIfStuck();
38         }
39
40         HashSet pvInstances = new HashSet();
41         HashSet usedInstanceViewNumbers = new HashSet();
42         bool fixedSomeId = false;
43
44         //// the following code would be an option if we only checked scene objects (but we can check all PVs)
45         //PhotonView[] pvObjects = GameObject.FindSceneObjectsOfType(typeof(PhotonView)) as PhotonView[];
46         //Debug.Log("HierarchyChange. PV Count: " + pvObjects.Length);
47
48         string levelName = Application.loadedLevelName;
49         #if UNITY_EDITOR
50         levelName = System.IO.Path.GetFileNameWithoutExtension(EditorApplication.currentScene);
51         #endif
52         int minViewIdInThisScene = PunSceneSettings.MinViewIdForScene(levelName);
53         //Debug.Log("Level '" + Application.loadedLevelName + "' has a minimum ViewId of: " + minViewIdInThisScene);
54
55         PhotonView[] pvObjects = Resources.FindObjectsOfTypeAll(typeof(PhotonView)) as PhotonView[];
56
57         foreach (PhotonView view in pvObjects)
58         {
59             // first pass: fix prefabs to viewID 0 if they got a view number assigned (cause they should not have one!)
60             if (EditorUtility.IsPersistent(view.gameObject))
61             {
62                 if (view.viewID != 0 || view.prefixBackup != -1 || view.instantiationId != -1)
63                 {
64                     Debug.LogWarning("PhotonView on persistent object being fixed (id and prefix must be 0). Was: " + view);
65                     view.viewID = 0;
66                     view.prefixBackup = -1;
67                     view.instantiationId = -1;
68                     EditorUtility.SetDirty(view);
69                     fixedSomeId = true;
70                 }
71             }
72             else
73             {
74                 // keep all scene-instanced PVs for later re-check
75                 pvInstances.Add(view);
76             }
77         }
78
79         Dictionary idPerObject = new Dictionary();
80
81         // second pass: check all used-in-scene viewIDs for duplicate viewIDs (only checking anything non-prefab)
82         // scene-PVs must have user == 0 (scene/room) and a subId != 0
83         foreach (PhotonView view in pvInstances)
84         {
85             if (view.ownerId > 0)
86             {
87                 Debug.Log("Re-Setting Owner ID of: " + view);
88             }
89             view.ownerId = 0; // simply make sure no owner is set (cause room always uses 0)
90             view.prefix = -1; // TODO: prefix could be settable via inspector per scene?!
91
92             if (view.viewID != 0)
93             {
94                 if (view.viewID < minViewIdInThisScene || usedInstanceViewNumbers.Contains(view.viewID))
95                 {
96                     view.viewID = 0; // avoid duplicates and negative values by assigning 0 as (temporary) number to be fixed in next pass
97                 }
98                 else
99                 {
100                     usedInstanceViewNumbers.Add(view.viewID); // builds a list of currently used viewIDs
101
102                     int instId = 0;
103                     if (idPerObject.TryGetValue(view.gameObject, out instId))
104                     {
105                         view.instantiationId = instId;
106                     }
107                     else
108                     {
109                         view.instantiationId = view.viewID;
110                         idPerObject[view.gameObject] = view.instantiationId;
111                     }
112                 }
113             }
114
115         }
116
117         // third pass: anything that's now 0 must get a new (not yet used) ID (starting at 0)
118         int lastUsedId = (minViewIdInThisScene > 0) ? minViewIdInThisScene - 1 : 0;
119
120         foreach (PhotonView view in pvInstances)
121         {
122             if (view.viewID == 0)
123             {
124                 // Debug.LogWarning("setting scene ID: " + view.gameObject.name + " ID: " + view.subId.ID + " scene ID: " + view.GetSceneID() + " IsPersistent: " + EditorUtility.IsPersistent(view.gameObject) + " IsSceneViewIDFree: " + IsSceneViewIDFree(view.subId.ID, view));
125                 int nextViewId = PhotonViewHandler.GetID(lastUsedId, usedInstanceViewNumbers);
126
127                 view.viewID = nextViewId;
128
129                 int instId = 0;
130                 if (idPerObject.TryGetValue(view.gameObject, out instId))
131                 {
132                     Debug.Log("Set inst ID");
133                     view.instantiationId = instId;
134                 }
135                 else
136                 {
137                     view.instantiationId = view.viewID;
138                     idPerObject[view.gameObject] = nextViewId;
139                 }
140
141                 //// when using the Editor's serialization (view.subId in this case), this is not needed, it seems
142                 //PrefabUtility.RecordPrefabInstancePropertyModifications(view);
143
144                 lastUsedId = nextViewId;
145                 EditorUtility.SetDirty(view);
146                 fixedSomeId = true;
147             }
148         }
149
150
151         if (fixedSomeId)
152         {
153             //Debug.LogWarning("Some subId was adjusted."); // this log is only interesting for Exit Games
154         }
155     }
File name: PhotonViewInspector.cs Copy
21     public override void OnInspectorGUI()
22     {
23         #if UNITY_3_5
24         EditorGUIUtility.LookLikeInspector();
25         #endif
26         //EditorGUI.indentLevel = 1;
27
28         m_Target = (PhotonView)this.target;
29         bool isProjectPrefab = EditorUtility.IsPersistent(m_Target.gameObject);
30
31         if( m_Target.ObservedComponents == null )
32         {
33             m_Target.ObservedComponents = new System.Collections.Generic.List();
34         }
35
36         if( m_Target.ObservedComponents.Count == 0 )
37         {
38             m_Target.ObservedComponents.Add( null );
39         }
40
41         EditorGUILayout.BeginHorizontal();
42         // Owner
43         if (isProjectPrefab)
44         {
45             EditorGUILayout.LabelField("Owner:", "Set at runtime");
46         }
47         else if (m_Target.isSceneView)
48         {
49             EditorGUILayout.LabelField("Owner", "Scene");
50         }
51         else
52         {
53             PhotonPlayer owner = m_Target.owner;
54             string ownerInfo = (owner != null) ? owner.name : "";
55
56             if (string.IsNullOrEmpty(ownerInfo))
57             {
58                 ownerInfo = "";
59             }
60
61             EditorGUILayout.LabelField("Owner", "[" + m_Target.ownerId + "] " + ownerInfo);
62         }
63
64         // ownership requests
65         EditorGUI.BeginDisabledGroup(Application.isPlaying);
66         m_Target.ownershipTransfer = (OwnershipOption)EditorGUILayout.EnumPopup(m_Target.ownershipTransfer, GUILayout.Width(100));
67         EditorGUI.EndDisabledGroup();
68
69         EditorGUILayout.EndHorizontal();
70
71
72         // View ID
73         if (isProjectPrefab)
74         {
75             EditorGUILayout.LabelField("View ID", "Set at runtime");
76         }
77         else if (EditorApplication.isPlaying)
78         {
79             EditorGUILayout.LabelField("View ID", m_Target.viewID.ToString());
80         }
81         else
82         {
83             int idValue = EditorGUILayout.IntField("View ID [1.."+(PhotonNetwork.MAX_VIEW_IDS-1)+"]", m_Target.viewID);
84             m_Target.viewID = idValue;
85         }
86
87
88
89         // Locally Controlled
90         if (EditorApplication.isPlaying)
91         {
92             string masterClientHint = PhotonNetwork.isMasterClient ? "(master)" : "";
93             EditorGUILayout.Toggle("Controlled locally: " + masterClientHint, m_Target.isMine);
94         }
95
96
97
98         //DrawOldObservedItem();
99         ConvertOldObservedItemToObservedList();
100
101
102         // ViewSynchronization (reliability)
103         if (m_Target.synchronization == ViewSynchronization.Off)
104         {
105             GUI.color = Color.grey;
106         }
107
108         EditorGUILayout.PropertyField( serializedObject.FindProperty( "synchronization" ), new GUIContent( "Observe option:" ) );
109
110         if( m_Target.synchronization != ViewSynchronization.Off &&
111             m_Target.ObservedComponents.FindAll( item => item != null ).Count == 0 )
112         {
113             GUILayout.BeginVertical( GUI.skin.box );
114             GUILayout.Label( "Warning", EditorStyles.boldLabel );
115             GUILayout.Label( "Setting the synchronization option only makes sense if you observe something." );
116             GUILayout.EndVertical();
117         }
118
119         /*ViewSynchronization vsValue = (ViewSynchronization)EditorGUILayout.EnumPopup("Observe option:", m_Target.synchronization);
120         if (vsValue != m_Target.synchronization)
121         {
122             m_Target.synchronization = vsValue;
123             if (m_Target.synchronization != ViewSynchronization.Off && m_Target.observed == null)
124             {
125                 EditorUtility.DisplayDialog("Warning", "Setting the synchronization option only makes sense if you observe something.", "OK, I will fix it.");
126             }
127         }*/
128
129         DrawSpecificTypeSerializationOptions();
130
131         GUI.color = Color.white;
132         DrawObservedComponentsList();
133
134         // Cleanup: save and fix look
135         if (GUI.changed)
136         {
137             EditorUtility.SetDirty(m_Target);
138             PhotonViewHandler.HierarchyChange(); // TODO: check if needed
139         }
140
141         GUI.color = Color.white;
142         EditorGUIUtility.LookLikeControls();
143     }
File name: PhotonAnimatorView.cs Copy
189     public void SetLayerSynchronized( int layerIndex, SynchronizeType synchronizeType )
190     {
191         if( Application.isPlaying == true )
192         {
193             m_WasSynchronizeTypeChanged = true;
194         }
195
196         int index = m_SynchronizeLayers.FindIndex( item => item.LayerIndex == layerIndex );
197
198         if( index == -1 )
199         {
200             m_SynchronizeLayers.Add( new SynchronizedLayer { LayerIndex = layerIndex, SynchronizeType = synchronizeType } );
201         }
202         else
203         {
204             m_SynchronizeLayers[ index ].SynchronizeType = synchronizeType;
205         }
206     }
File name: PhotonAnimatorView.cs Copy
213     public void SetParameterSynchronized( string name, ParameterType type, SynchronizeType synchronizeType )
214     {
215         if( Application.isPlaying == true )
216         {
217             m_WasSynchronizeTypeChanged = true;
218         }
219
220         int index = m_SynchronizeParameters.FindIndex( item => item.Name == name );
221
222         if( index == -1 )
223         {
224             m_SynchronizeParameters.Add( new SynchronizedParameter { Name = name, Type = type, SynchronizeType = synchronizeType } );
225         }
226         else
227         {
228             m_SynchronizeParameters[ index ].SynchronizeType = synchronizeType;
229         }
230     }
File name: NetworkingPeer.cs Copy
2688     public void RegisterPhotonView(PhotonView netView)
2689     {
2690         if (!Application.isPlaying)
2691         {
2692             this.photonViewList = new Dictionary();
2693             return;
2694         }
2695
2696         if (netView.viewID == 0)
2697         {
2698             // don't register views with ID 0 (not initialized). they register when a ID is assigned later on
2699             Debug.Log("PhotonView register is ignored, because viewID is 0. No id assigned yet to: " + netView);
2700             return;
2701         }
2702
2703         if (this.photonViewList.ContainsKey(netView.viewID))
2704         {
2705             // if some other view is in the list already, we got a problem. it might be undestructible. print out error
2706             if (netView != photonViewList[netView.viewID])
2707             {
2708                 Debug.LogError(string.Format("PhotonView ID duplicate found: {0}. New: {1} old: {2}. Maybe one wasn't destroyed on scene load?! Check for 'DontDestroyOnLoad'. Destroying old entry, adding new.", netView.viewID, netView, photonViewList[netView.viewID]));
2709             }
2710
2711             //this.photonViewList.Remove(netView.viewID); // TODO check if we chould Destroy the GO of this view?!
2712             this.RemoveInstantiatedGO(photonViewList[netView.viewID].gameObject, true);
2713         }
2714
2715         // Debug.Log("adding view to known list: " + netView);
2716         this.photonViewList.Add(netView.viewID, netView);
2717         //Debug.LogError("view being added. " + netView); // Exit Games internal log
2718
2719         if (PhotonNetwork.logLevel >= PhotonLogLevel.Full)
2720             Debug.Log("Registered PhotonView: " + netView.viewID);
2721     }

IsPlaying 126 lượt xem

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