private void DrawConnectionsSection() { ZView zView = (ZView)this.target; _isConnectionsSectionExpanded = this.DrawSectionHeader("Connections", _connectionsIconTexture, _isConnectionsSectionExpanded, true); if (_isConnectionsSectionExpanded) { bool doActiveConnectionsExist = false; try { // For each connection: int numConnections = zView.GetNumConnections(); for (int i = 0; i < numConnections; ++i) { // Get the connection. IntPtr connection = zView.GetConnection(i); // Get the connection's state. ZView.ConnectionState connectionState = zView.GetConnectionState(connection); if (connectionState != ZView.ConnectionState.Error) { // Display the connection's information. int connectionNumber = i + 1; string initiationStatusString = zView.WasConnectionLocallyInitiated(connection) ? "locally" : "remotely"; EditorGUILayout.LabelField(string.Format("Connection {0} (initiated {1})", connectionNumber, initiationStatusString)); EditorGUI.indentLevel++; { EditorGUILayout.LabelField("Name: " + zView.GetConnectedNodeName(connection)); EditorGUILayout.LabelField("Status: " + zView.GetConnectedNodeStatus(connection)); EditorGUILayout.LabelField("State: " + connectionState); IntPtr mode = zView.GetConnectionMode(connection); string modeString = "Unknown"; if (mode == IntPtr.Zero) { modeString = "None"; } else if (mode == zView.GetStandardMode()) { modeString = "Standard"; } else if (mode == zView.GetAugmentedRealityMode()) { modeString = "Augmented Reality"; } EditorGUILayout.LabelField("Mode: " + modeString); } EditorGUI.indentLevel--; EditorGUILayout.Space(); doActiveConnectionsExist = true; } } } catch { // TODO: Add warning. } if (!doActiveConnectionsExist) { EditorGUILayout.LabelField("No active connections"); EditorGUILayout.Space(); } } }
private void ProcessModeUI() { // Get the current active connection. IntPtr connection = _zView.GetCurrentActiveConnection(); // If connected, get the connection's state. ZView.ConnectionState connectionState = ZView.ConnectionState.Error; if (connection != IntPtr.Zero) { connectionState = _zView.GetConnectionState(connection); } // Handle pausing the current mode. GUI.enabled = (connectionState == ZView.ConnectionState.ModeActive); { if (GUILayout.Button("Pause Mode")) { _zView.PauseMode(connection); } } GUI.enabled = true; // Handle resuming the current mode. GUI.enabled = (connectionState == ZView.ConnectionState.ModePaused); { if (GUILayout.Button("Resume Mode")) { _zView.ResumeMode(connection); } } GUI.enabled = true; // Check if it is safe to switch modes. bool isModeSwitchEnabled = (connectionState == ZView.ConnectionState.NoMode) || (connectionState == ZView.ConnectionState.ModeActive) || (connectionState == ZView.ConnectionState.ModePaused); // Handle switching to no mode. GUI.enabled = isModeSwitchEnabled; { if (GUILayout.Button("Switch To No Mode")) { _zView.SetConnectionMode(connection, IntPtr.Zero); } } GUI.enabled = true; // Handle switching to standard mode. GUI.enabled = isModeSwitchEnabled && this.IsModeAvailable(connection, _zView.GetStandardMode()); { if (GUILayout.Button("Switch To Standard Mode")) { _zView.SetConnectionMode(connection, _zView.GetStandardMode()); } } GUI.enabled = true; // Handle switching to augmented reality mode. GUI.enabled = isModeSwitchEnabled && this.IsModeAvailable(connection, _zView.GetAugmentedRealityMode()); { if (GUILayout.Button("Switch To Augmented Reality Mode")) { _zView.SetConnectionMode(connection, _zView.GetAugmentedRealityMode()); } } GUI.enabled = true; // Handle moving and resizing the augmented reality overlay. GUI.enabled = isModeSwitchEnabled && (_zView.GetConnectionMode(connection) == _zView.GetAugmentedRealityMode()); { // Restore defaults. if (GUILayout.Button("Reset Overlay Position and Size")) { _zView.SetSetting(connection, ZView.SettingKey.OverlayOffsetX, 0.0f); _zView.SetSetting(connection, ZView.SettingKey.OverlayOffsetY, 0.0f); _zView.SetSetting(connection, ZView.SettingKey.OverlayScaleX, 1.0f); _zView.SetSetting(connection, ZView.SettingKey.OverlayScaleY, 1.0f); } // Handle move. GUILayout.BeginHorizontal(); { GUILayout.Label("Move Overlay: "); // Move left by 1 pixel: if (GUILayout.Button("Left")) { float overlayOffsetX = _zView.GetSettingFloat(connection, ZView.SettingKey.OverlayOffsetX); _zView.SetSetting(connection, ZView.SettingKey.OverlayOffsetX, overlayOffsetX - 1.0f); } // Move right by 1 pixel: if (GUILayout.Button("Right")) { float overlayOffsetX = _zView.GetSettingFloat(connection, ZView.SettingKey.OverlayOffsetX); _zView.SetSetting(connection, ZView.SettingKey.OverlayOffsetX, overlayOffsetX + 1.0f); } // Move up by 1 pixel: if (GUILayout.Button("Up")) { float overlayOffsetY = _zView.GetSettingFloat(connection, ZView.SettingKey.OverlayOffsetY); _zView.SetSetting(connection, ZView.SettingKey.OverlayOffsetY, overlayOffsetY + 1.0f); } // Move down by 1 pixel: if (GUILayout.Button("Down")) { float overlayOffsetY = _zView.GetSettingFloat(connection, ZView.SettingKey.OverlayOffsetY); _zView.SetSetting(connection, ZView.SettingKey.OverlayOffsetY, overlayOffsetY - 1.0f); } } GUILayout.EndHorizontal(); // Handle resize. GUILayout.BeginHorizontal(); { GUILayout.Label("Resize Overlay: "); // Uniformly decrease scale by 0.1 factor: if (GUILayout.Button("Decrease")) { float overlayScaleX = _zView.GetSettingFloat(connection, ZView.SettingKey.OverlayScaleX); _zView.SetSetting(connection, ZView.SettingKey.OverlayScaleX, overlayScaleX - 0.1f); float overlayScaleY = _zView.GetSettingFloat(connection, ZView.SettingKey.OverlayScaleY); _zView.SetSetting(connection, ZView.SettingKey.OverlayScaleY, overlayScaleY - 0.1f); } // Uniformly increase scale by 0.1 factor: if (GUILayout.Button("Increase")) { float overlayScaleX = _zView.GetSettingFloat(connection, ZView.SettingKey.OverlayScaleX); _zView.SetSetting(connection, ZView.SettingKey.OverlayScaleX, overlayScaleX + 0.1f); float overlayScaleY = _zView.GetSettingFloat(connection, ZView.SettingKey.OverlayScaleY); _zView.SetSetting(connection, ZView.SettingKey.OverlayScaleY, overlayScaleY + 0.1f); } } GUILayout.EndHorizontal(); } GUI.enabled = true; }