/// <summary> /// Unity callback to draw this UI. /// </summary> void OnGUI() { SetupUI(); HEU_SessionSyncData syncData = GetSessionSyncData(); EditorGUI.BeginChangeCheck(); bool bSessionStarted = (syncData != null && syncData.SyncStatus != HEU_SessionSyncData.Status.Stopped); bool bSessionCanStart = !bSessionStarted; if (bSessionCanStart) { // Only able to start a session if no session exists. HEU_SessionBase session = HEU_SessionManager.GetDefaultSession(); if (session != null && session.IsSessionValid()) { bSessionCanStart = false; } } HEU_HoudiniAssetUI.DrawHeaderSection(); // Draw SessionSync status. if (syncData != null) { if (syncData.SyncStatus == HEU_SessionSyncData.Status.Stopped) { if (!bSessionCanStart) { EditorGUILayout.LabelField("Another session already running. Disconnect it to start SessionSync."); } else { EditorGUILayout.LabelField("Status: " + syncData.SyncStatus); } } else { EditorGUILayout.LabelField("Status: " + syncData.SyncStatus); } } else { if (!bSessionCanStart) { EditorGUILayout.LabelField("Another session already running. Disconnect it to start SessionSync."); } else { EditorGUILayout.LabelField("No active session."); } } EditorGUILayout.Separator(); EditorGUI.indentLevel++; // Draw initial connection buttons (Start, Connect) using (new EditorGUILayout.HorizontalScope()) { using (new EditorGUI.DisabledScope(bSessionStarted || !bSessionCanStart)) { if (GUILayout.Button("Start Houdini")) { StartAndConnectToHoudini(syncData); } else if (GUILayout.Button("Connect to Houdini")) { ConnectSessionSync(syncData); } } } using (new EditorGUI.DisabledScope((syncData == null || !bSessionStarted) && bSessionCanStart)) { if (GUILayout.Button("Disconnect")) { Disconnect(syncData); } } EditorGUILayout.Separator(); // Draw Connection Settings EditorGUILayout.LabelField("Connection Settings"); using (new EditorGUI.DisabledScope(bSessionStarted)) { SessionMode newSessionMode = (SessionMode)EditorGUILayout.EnumPopup("Type", _sessionMode); if (_sessionMode != newSessionMode) { _sessionMode = newSessionMode; HEU_PluginSettings.Session_Mode = newSessionMode; } EditorGUI.indentLevel++; if (_sessionMode == SessionMode.Pipe) { string newPipeName = EditorGUILayout.DelayedTextField("Pipe Name", _pipeName); if (_pipeName != newPipeName) { HEU_PluginSettings.Session_PipeName = newPipeName; _pipeName = newPipeName; } } else if (_sessionMode == SessionMode.Socket) { int newPort = EditorGUILayout.DelayedIntField("Port", _port); HEU_PluginSettings.Session_Port = newPort; if (_port != newPort) { HEU_PluginSettings.Session_Port = newPort; _port = newPort; } } EditorGUI.indentLevel--; } EditorGUILayout.Separator(); // The rest requires syncData // Synchronization settings, and new nodes if (syncData != null) { using (new EditorGUI.DisabledScope(syncData.SyncStatus != HEU_SessionSyncData.Status.Connected)) { EditorGUILayout.LabelField("Synchronization Settings"); EditorGUI.indentLevel++; HEU_PluginSettings.SessionSyncAutoCook = HEU_EditorUI.DrawToggleLeft(HEU_PluginSettings.SessionSyncAutoCook, "Sync With Houdini Cook"); bool enableHoudiniTime = HEU_EditorUI.DrawToggleLeft(syncData._syncInfo.cookUsingHoudiniTime, "Cook Using Houdini Time"); if (syncData._syncInfo.cookUsingHoudiniTime != enableHoudiniTime) { syncData._syncInfo.cookUsingHoudiniTime = enableHoudiniTime; UploadSessionSyncInfo(null, syncData); } bool enableSyncViewport = HEU_EditorUI.DrawToggleLeft(syncData._syncInfo.syncViewport, "Sync Viewport"); if (syncData._syncInfo.syncViewport != enableSyncViewport) { syncData._syncInfo.syncViewport = enableSyncViewport; UploadSessionSyncInfo(null, syncData); } EditorGUI.indentLevel--; } EditorGUILayout.Separator(); EditorGUILayout.LabelField("New Node"); using (new EditorGUI.DisabledScope(syncData.SyncStatus != HEU_SessionSyncData.Status.Connected)) { EditorGUI.indentLevel++; syncData._newNodeName = EditorGUILayout.TextField("Name", syncData._newNodeName); syncData._nodeTypeIndex = EditorGUILayout.Popup("Type", syncData._nodeTypeIndex, _nodeTypesLabels); using (new EditorGUI.DisabledGroupScope(string.IsNullOrEmpty(syncData._newNodeName))) { using (new EditorGUILayout.VerticalScope()) { if (GUILayout.Button("Create")) { if (syncData._nodeTypeIndex >= 0 && syncData._nodeTypeIndex < 3) { HEU_NodeSync.CreateNodeSync(null, _nodeTypes[syncData._nodeTypeIndex], syncData._newNodeName); } else if (syncData._nodeTypeIndex == 3) { CreateCurve(syncData._newNodeName); } else if (syncData._nodeTypeIndex == 4) { CreateInput(syncData._newNodeName); } } if (GUILayout.Button("Load NodeSync")) { LoadNodeSyncDialog(syncData._newNodeName); } } } EditorGUI.indentLevel--; } EditorGUILayout.Separator(); // Log using (new EditorGUILayout.VerticalScope(_backgroundStyle)) { using (new EditorGUILayout.HorizontalScope()) { EditorGUILayout.PrefixLabel(_eventMessageContent); if (GUILayout.Button("Clear")) { ClearLog(); } } string logMsg = GetLog(); using (var scrollViewScope = new EditorGUILayout.ScrollViewScope(_eventMessageScrollPos, GUILayout.Height(120))) { _eventMessageScrollPos = scrollViewScope.scrollPosition; GUILayout.Label(logMsg, _eventMessageStyle); } } } EditorGUI.indentLevel--; if (EditorGUI.EndChangeCheck() && syncData != null) { HEU_SessionBase sessionBase = HEU_SessionManager.GetDefaultSession(); if (sessionBase != null) { HEU_SessionManager.SaveAllSessionData(); } } }
static void OnBeforeAssemblyReload() { // Save the session before code domain reload so // that the session file has the latest session state. HEU_SessionManager.SaveAllSessionData(); }