/// <summary> /// Returns a valid session by either reconnecting to an existing session, or creating a new session. /// Note that this will display error (once) if unable to get a valid session. /// </summary> /// <returns>A session object (new or existing). Session might not actually have connected successfully. Check IsSessionValid() and error message./returns> public static HEU_SessionBase GetOrCreateDefaultSession(bool bNotifyUserError = true) { if (_defaultSession == null) { // After a code refresh, _defaultSession might be null. So try loading stored plugin data to see if we can get it back. HEU_PluginStorage.InstantiateAndLoad(); } if (_defaultSession != null && _defaultSession.IsSessionValid()) { return _defaultSession; } else if (_defaultSession == null || _defaultSession.ConnectionState == SessionConnectionState.NOT_CONNECTED) { // Try creating it if we haven't tried yet bNotifyUserError &= !CreateThriftPipeSession(HEU_PluginSettings.Session_PipeName, HEU_PluginSettings.Session_AutoClose, HEU_PluginSettings.Session_Timeout, bNotifyUserError); } if (bNotifyUserError && !_defaultSession.UserNotifiedSessionInvalid) { _defaultSession.UserNotifiedSessionInvalid = true; HEU_EditorUtility.DisplayErrorDialog(HEU_Defines.HEU_ERROR_TITLE, HEU_SessionManager.GetLastSessionError(), "OK"); HEU_EditorUtility.DisplayDialog(HEU_Defines.HEU_INSTALL_INFO, HEU_HAPIUtility.GetHoudiniEngineInstallationInfo(), "OK"); } return _defaultSession; }
/// <summary> /// Tries to load a stored default session. This would be after a code refresh /// or if the Houdini session is still running but Unity hasn't connected to it. /// </summary> /// <returns>True if successfully reconnected to a stored session.</returns> public static bool LoadStoredDefaultSession() { // By forcing our plugin and session data to be loaded here, it will // result in all stored sessions to be recreated, including _defaultSession // being initialized if found in storage. HEU_PluginStorage.InstantiateAndLoad(); return (_defaultSession != null && _defaultSession.IsSessionValid()); }