/// <summary>
		/// Save session data to disk.
		/// </summary>
		/// <param name="sessionData">The session to save.</param>
		public static void SaveSessionData(HEU_SessionData sessionData)
		{
#if UNITY_EDITOR && HOUDINIENGINEUNITY_ENABLED
			string jsonStr = JsonUtility.ToJson(sessionData);
			UnityEditor.EditorPrefs.SetString(HEU_Defines.PLUGIN_SESSION_DATA, jsonStr);
#endif
		}
		/// <summary>
		/// Clears the session info.
		/// </summary>
		protected virtual void ClearSessionInfo()
		{
			if (_sessionData != null)
			{
				_sessionData.SessionID = -1;
				_sessionData.ProcessID = -1;
				_sessionData = null;
			}
		}
        /// <summary>
        /// Connect to a running instance of Houdini with SessionSync enabled.
        /// </summary>
        void ConnectSessionSync(HEU_SessionSyncData syncData)
        {
            if (syncData != null && syncData.SyncStatus != HEU_SessionSyncData.Status.Stopped)
            {
                return;
            }

            Log("Connecting To Houdini...");

            HEU_SessionManager.RecreateDefaultSessionData();

            if (syncData == null)
            {
                HEU_SessionData sessionData = HEU_SessionManager.GetSessionData();
                if (sessionData != null)
                {
                    syncData = sessionData.GetOrCreateSessionSync();
                }
                else
                {
                    syncData = new HEU_SessionSyncData();
                }
            }

            bool result = InternalConnect(_sessionMode, _pipeName,
                                          HEU_PluginSettings.Session_Localhost, _port,
                                          HEU_PluginSettings.Session_AutoClose,
                                          HEU_PluginSettings.Session_Timeout,
                                          true);

            if (result)
            {
                try
                {
                    HEU_SessionManager.InitializeDefaultSession();

                    HEU_SessionManager.GetDefaultSession().GetSessionData().SetSessionSync(syncData);

                    syncData.SyncStatus = HEU_SessionSyncData.Status.Connected;
                    Log("Connected!");
                }
                catch (HEU_HoudiniEngineError ex)
                {
                    syncData.SyncStatus = HEU_SessionSyncData.Status.Stopped;

                    Log("Connection errored!");
                    Log(ex.ToString());
                }
            }
            else
            {
                Log("Connection failed!");
            }
        }
		/// <summary>
		/// Load session data from disk.
		/// </summary>
		/// <returns>Loaded session data.</returns>
		public static HEU_SessionData LoadSessionData()
		{
#if UNITY_EDITOR && HOUDINIENGINEUNITY_ENABLED
			string jsonStr = UnityEditor.EditorPrefs.GetString(HEU_Defines.PLUGIN_SESSION_DATA);
			//Debug.Log("LOAD json: " + jsonStr);
			HEU_SessionData sessionData = JsonUtility.FromJson<HEU_SessionData>(jsonStr);
			return sessionData;
#else
			return null;
#endif
		}
		public static HEU_SessionData LoadSessionData(long SessionID)
		{
			// TODO: combine session string + session ID and look up in EditorPrefs
			// return the found session data
#if UNITY_EDITOR && HOUDINIENGINEUNITY_ENABLED
			string sessionKeyStr = string.Format("{0}_{1}", HEU_Defines.PLUGIN_SESSION_DATA, SessionID);
			string jsonStr = UnityEditor.EditorPrefs.GetString(sessionKeyStr);
			//Debug.Log("LOAD json: " + jsonStr);
			HEU_SessionData sessionData = JsonUtility.FromJson<HEU_SessionData>(jsonStr);
			return sessionData;
#else
			return null;
#endif
		}
        /// <summary>
        /// Returns the local HEU_SessionSyncData state.
        /// </summary>
        HEU_SessionSyncData GetSessionSyncData()
        {
            HEU_SessionSyncData syncData = _connectionSyncData;

            if (syncData == null)
            {
                HEU_SessionData sessionData = HEU_SessionManager.GetSessionData();
                if (sessionData != null)
                {
                    // On domain reload, re-acquire serialized SessionSync
                    // if session exists
                    syncData = sessionData.GetOrCreateSessionSync();
                }
            }
            return(syncData);
        }
        /// <summary>
        /// Launch Houdini with SessionSync enabled and automatically connect to it.
        /// </summary>
        void StartAndConnectToHoudini(HEU_SessionSyncData syncData)
        {
            if (syncData != null && syncData.SyncStatus != HEU_SessionSyncData.Status.Stopped)
            {
                return;
            }

            if (!OpenHoudini())
            {
                return;
            }

            // Now attempt to connect to it by moving into Connecting state

            HEU_SessionManager.RecreateDefaultSessionData();

            if (syncData == null)
            {
                HEU_SessionData sessionData = HEU_SessionManager.GetSessionData();
                if (sessionData != null)
                {
                    syncData = sessionData.GetOrCreateSessionSync();
                }
                else
                {
                    syncData = new HEU_SessionSyncData();
                }

                syncData._validForConnection = true;
            }

            syncData.SyncStatus = HEU_SessionSyncData.Status.Connecting;

            _connectionSyncData = syncData;
            Log("Connecting...");

            syncData._timeStartConnection = Time.realtimeSinceStartup;
            syncData._timeLastUpdate      = Time.realtimeSinceStartup;
        }
		/// <summary>
		/// Returns list of session data retrieved from storage.
		/// </summary>
		/// <returns>List of HEU_SessionData stored on disk.</returns>
		public static List<HEU_SessionData> LoadAllSessionData()
		{
			// Retrieve saved JSON string from storage, and parse it to create the session datas.
			List<HEU_SessionData> sessions = new List<HEU_SessionData>();
#if UNITY_EDITOR && HOUDINIENGINEUNITY_ENABLED
			string jsonStr = UnityEditor.EditorPrefs.GetString(HEU_Defines.PLUGIN_SESSION_DATA);
			if (jsonStr != null && !string.IsNullOrEmpty(jsonStr))
			{
				string[] jsonSplit = jsonStr.Split(';');
				foreach(string entry in jsonSplit)
				{
					if (!string.IsNullOrEmpty(entry))
					{
						HEU_SessionData sessionData = JsonUtility.FromJson<HEU_SessionData>(entry);
						if(sessionData != null)
						{
							sessions.Add(sessionData);
						}
					}
				}
			}
#endif
			return sessions;
		}
		/// <summary>
		/// Returns list of session data retrieved from storage.
		/// </summary>
		/// <returns>List of HEU_SessionData stored on disk.</returns>
		public static List<HEU_SessionData> LoadAllSessionData()
		{
			// Retrieve saved JSON string from storage, and parse it to create the session datas.
			List<HEU_SessionData> sessions = new List<HEU_SessionData>();
#if UNITY_EDITOR && HOUDINIENGINEUNITY_ENABLED
			string jsonStr = HEU_Platform.ReadAllText(SessionFilePath());
			if (!string.IsNullOrEmpty(jsonStr))
			{
				string[] jsonSplit = jsonStr.Split(';');
				foreach(string entry in jsonSplit)
				{
					if (!string.IsNullOrEmpty(entry))
					{
						HEU_SessionData sessionData = JsonUtility.FromJson<HEU_SessionData>(entry);
						if(sessionData != null)
						{
							sessions.Add(sessionData);
						}
					}
				}
			}
#endif
			return sessions;
		}
		/// <summary>
		/// Set the session data for this session.
		/// </summary>
		/// <param name="sessionData">Session data to set</param>
		public void SetSessionData(HEU_SessionData sessionData)
		{
			_sessionData = sessionData;
		}
Example #11
0
        /// <summary>
        /// Return Houdini Engine installation and session information.
        /// Tries to use existing or creates new session to find information.
        /// </summary>
        /// <returns>String containing installation and session information.</returns>
        public static string GetHoudiniEngineInstallationInfo()
        {
#if HOUDINIENGINEUNITY_ENABLED
            StringBuilder sb = new StringBuilder();

            sb.AppendFormat("Required Houdini Version: {0}.{1}.{2}\nRequired Houdini Engine Version: {3}.{4}.{5}\n\n",
                            HEU_HoudiniVersion.HOUDINI_MAJOR,
                            HEU_HoudiniVersion.HOUDINI_MINOR,
                            HEU_HoudiniVersion.HOUDINI_BUILD,
                            HEU_HoudiniVersion.HOUDINI_ENGINE_MAJOR,
                            HEU_HoudiniVersion.HOUDINI_ENGINE_MINOR,
                            HEU_HoudiniVersion.HOUDINI_ENGINE_API);

            // Check if existing session is valid, or create a new session. Then query installation information.
            HEU_SessionBase session = HEU_SessionManager.GetDefaultSession();
            if (session != null && session.IsSessionValid())
            {
                int hMajor = session.GetEnvInt(HAPI_EnvIntType.HAPI_ENVINT_VERSION_HOUDINI_MAJOR);
                int hMinor = session.GetEnvInt(HAPI_EnvIntType.HAPI_ENVINT_VERSION_HOUDINI_MINOR);
                int hBuild = session.GetEnvInt(HAPI_EnvIntType.HAPI_ENVINT_VERSION_HOUDINI_BUILD);

                int heuPatch = session.GetEnvInt(HAPI_EnvIntType.HAPI_ENVINT_VERSION_HOUDINI_PATCH);

                int heuMajor = session.GetEnvInt(HAPI_EnvIntType.HAPI_ENVINT_VERSION_HOUDINI_ENGINE_MAJOR);
                int heuMinor = session.GetEnvInt(HAPI_EnvIntType.HAPI_ENVINT_VERSION_HOUDINI_ENGINE_MINOR);
                int heuAPI   = session.GetEnvInt(HAPI_EnvIntType.HAPI_ENVINT_VERSION_HOUDINI_ENGINE_API);

                sb.AppendFormat("Installed Houdini Version: {0}.{1}.{2}{3}\n", hMajor, hMinor, hBuild, (heuPatch > 0) ? "." + heuPatch.ToString() : "");
                sb.AppendFormat("Installed Houdini Engine Version: {0}.{1}.{2}\n\n", heuMajor, heuMinor, heuAPI);

                sb.AppendFormat("Houdini Binaries Path: {0}\n", HEU_Platform.GetHoudiniEnginePath() + HEU_HoudiniVersion.HAPI_BIN_PATH);
                sb.AppendFormat("Unity Plugin Version: {0}\n\n", HEU_HoudiniVersion.UNITY_PLUGIN_VERSION);

                HEU_SessionData sessionData = session.GetSessionData();
                if (sessionData != null)
                {
                    sb.AppendFormat("Session ID: {0}\n", sessionData.SessionID);
                    sb.AppendFormat("Session Type: {0}\n", sessionData.SessionType);
                    sb.AppendFormat("Process ID: {0}\n", sessionData.ProcessID);

                    if (sessionData.SessionType == HAPI_SessionType.HAPI_SESSION_THRIFT)
                    {
                        sb.AppendFormat("Pipe name: {0}\n", sessionData.PipeName);
                    }

                    sb.AppendLine();
                }

                sb.Append("License Type Acquired: ");
                HAPI_License license = HEU_SessionManager.GetCurrentLicense(false);
                switch (license)
                {
                case HAPI_License.HAPI_LICENSE_NONE: sb.Append("None\n"); break;

                case HAPI_License.HAPI_LICENSE_HOUDINI_ENGINE: sb.Append("Houdini Engine\n"); break;

                case HAPI_License.HAPI_LICENSE_HOUDINI: sb.Append("Houdini (Escape)\n"); break;

                case HAPI_License.HAPI_LICENSE_HOUDINI_FX: sb.Append("Houdini FX\n"); break;

                case HAPI_License.HAPI_LICENSE_HOUDINI_ENGINE_INDIE: sb.Append("Houdini Engine Indie"); break;

                case HAPI_License.HAPI_LICENSE_HOUDINI_INDIE: sb.Append("Houdini Indie\n"); break;

                default: sb.Append("Unknown\n"); break;
                }
            }
            else             // Unable to establish a session
            {
                sb.AppendLine("Unable to detect Houdini Engine installation.");
                sb.AppendLine("License Type Acquired: Unknown\n");
                if (session != null)
                {
                    sb.AppendLine("Failure possibly due to: " + session.GetLastSessionError());
                }
            }

            sb.AppendLine();
            sb.Append("PATH: \n" + GetEnvironmentPath());

            Debug.Log(sb.ToString());

            return(sb.ToString());
#else
            return("");
#endif
        }