static void EditorUpdate() { if (ServerSetting == null || (!checkedPhotonWizard && ServerSetting.HostType == ServerSettings.HostingOption.NotSet)) { // Debug.Log("EditorUpdate open Wizard. " + ServerSetting + " checkedPhotonWizard " + checkedPhotonWizard); checkedPhotonWizard = true; PhotonEditor window = (PhotonEditor)GetWindow(typeof(PhotonEditor), false, "PUN Setup wizard", true); window.SetSetupWizard(); window.Show(); } // Workaround for TCP crash. Plus this surpresses any other recompile errors. if (EditorApplication.isCompiling) { if (PhotonNetwork.connected) { if (lastWarning > EditorApplication.timeSinceStartup - 3) { //Prevent error spam Debug.LogWarning("Unity recompile forced a Photon Disconnect"); lastWarning = EditorApplication.timeSinceStartup; } PhotonNetwork.Disconnect(); } } else if (!EditorApplication.isPlaying) { //The following code could be optimized if Unity provides the right callbacks. // The current performance is 'OK' as we do check if the list changes (add/remove/duplicate should always change the length) //We are currently checking all selected PhotonViews every editor-frame //Instead, we only want to check this when an asset is placed in a scene (at editor time) //We need some sort of "OnCreated" call for scene objects. UnityEngine.Object[] objs = Selection.GetFiltered(typeof(PhotonView), SelectionMode.ExcludePrefab | SelectionMode.Editable | SelectionMode.Deep); if (objs.Length != lastPhotonViewListLength) { bool changed = false; foreach (UnityEngine.Object obj in objs) { PhotonView view = obj as PhotonView; if (!PhotonViewInspector.VerifySceneView(view)) { changed = true; } } if (changed) { Debug.Log("PUN: Corrected one or more scene-PhotonViews."); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); } lastPhotonViewListLength = objs.Length; } // Check the newly opened scene for wrong PhotonViews // This can happen when changing a prefab while viewing scene A. Instances in scene B will not be corrected. if (lastScene != EditorApplication.currentScene && EditorApplication.currentScene != "") { lastScene = EditorApplication.currentScene; PhotonViewInspector.VerifyAllSceneViews(); } } }
// called in editor, opens wizard for initial setup, keeps scene PhotonViews up to date and closes connections when compiling (to avoid issues) private static void EditorUpdate() { if (dontCheckPunSetup) { return; } // serverSetting is null when the file gets deleted. otherwise, the wizard should only run once and only if hosting option is not (yet) set if (!PhotonEditor.Current.DisableAutoOpenWizard && PhotonEditor.Current.HostType == ServerSettings.HostingOption.NotSet) { ShowRegistrationWizard(); } // Workaround for TCP crash. Plus this surpresses any other recompile errors. if (EditorApplication.isCompiling) { if (PhotonNetwork.connected) { if (lastWarning > EditorApplication.timeSinceStartup - 3) { // Prevent error spam Debug.LogWarning("Unity recompile forced a Photon Disconnect"); lastWarning = EditorApplication.timeSinceStartup; } PhotonNetwork.Disconnect(); } } else if (!EditorApplication.isPlaying) { // The following code could be optimized if Unity provides the right callbacks. // The current performance is 'OK' as we do check if the list changes (add/remove/duplicate should always change the length) // We are currently checking all selected PhotonViews on hierarchy- and on project-change // Instead, we only want to check this when an NEW asset is placed in a scene (at editor time) // We need some sort of "OnCreated" call for scene objects. UnityEngine.Object[] objs = Selection.GetFiltered(typeof(PhotonView), SelectionMode.ExcludePrefab | SelectionMode.Editable | SelectionMode.Deep); if (objs.Length > 0 && (objs.Length != lastPhotonViewListLength || (lastFirstElement != objs[0]))) { bool changed = false; foreach (UnityEngine.Object obj in objs) { PhotonView view = obj as PhotonView; if (!PhotonViewInspector.VerifySceneView(view)) { changed = true; } } if (changed) { Debug.Log("PUN: Corrected one or more scene-PhotonViews."); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); } lastPhotonViewListLength = objs.Length; lastFirstElement = objs[0]; } // Check the newly opened scene for wrong PhotonViews // This can happen when changing a prefab while viewing scene A. Instances in scene B will not be corrected. if (lastScene != EditorApplication.currentScene && EditorApplication.currentScene != string.Empty) { lastScene = EditorApplication.currentScene; PhotonViewInspector.VerifyAllSceneViews(); } } }