public override void OnInspectorGUI() { base.OnInspectorGUI(); if (FindObjectOfType <NuitrackManager>(true) == null) { NuitrackSDKGUI.NuitrackNotExistMessage(); } SensorSpace sensorSpace = serializedObject.targetObject as SensorSpace; Canvas canvas = viewCanvasProperty.objectReferenceValue as Canvas; if (canvas != null) { if (canvas.renderMode == RenderMode.WorldSpace || canvas.renderMode == RenderMode.ScreenSpaceOverlay) { string message = string.Format("The canvas rendering mode is specified: {0}.\nIt is recommended to use: {1}", canvas.renderMode, RenderMode.ScreenSpaceCamera); string buttonLabel = string.Format("Switch to {0}", RenderMode.ScreenSpaceCamera); UnityAction fixAction = delegate { FixCanvasRenderMode(canvas, sensorSpace); }; NuitrackSDKGUI.DrawMessage(message, LogType.Warning, fixAction, buttonLabel); } } else { string message = "View Canvas is not set. The screen size will be used to align the camera's fov."; NuitrackSDKGUI.DrawMessage(message, LogType.Log); } }
public override void OnInspectorGUI() { serializedObject.Update(); EditorGUILayout.PropertyField(m_FrameMode); serializedObject.ApplyModifiedProperties(); EditorGUILayout.Space(); base.OnInspectorGUI(); if (FindObjectOfType <NuitrackManager>(true) == null) { NuitrackSDKGUI.NuitrackNotExistMessage(); } if (nuitrackAspectRatioFitter.aspectMode != AspectRatioFitter.AspectMode.FitInParent) { UnityAction fixAspectMode = delegate { FixAspectMode(m_AspectMode); }; string message = string.Format("Aspect Mode is set to {0}." + "The frame from the sensor may not be displayed correctly." + "\nRecommended: Fit In Parent.", nuitrackAspectRatioFitter.aspectMode); NuitrackSDKGUI.DrawMessage(message, LogType.Warning, fixAspectMode, "Fix"); } serializedObject.ApplyModifiedProperties(); }
void DrawRuntimePosesMatching() { ShowRuntimePoseMatching = EditorGUILayout.BeginFoldoutHeaderGroup(ShowRuntimePoseMatching, "Runtime matches of poses"); if (ShowRuntimePoseMatching) { if (EditorApplication.isPlaying) { if (PoseDetector.CountPoses > 0) { using (new VerticalGroup(EditorStyles.helpBox)) { foreach (NuitrackPose pose in PoseDetector) { using (new VerticalGroup()) { EditorGUILayout.LabelField(pose.name, EditorStyles.boldLabel); using (new VerticalGroup(EditorStyles.helpBox)) { if (PoseDetector.Matches[pose].Count > 0) { foreach (KeyValuePair <int, float> poseMatch in PoseDetector.Matches[pose]) { DrawUserPoseMatch(string.Format("User id: {0}", poseMatch.Key), poseMatch.Value); } } else { DrawUserPoseMatch("User not found", 0); } } } } } } else { NuitrackSDKGUI.DrawMessage("Not a single pose is set", LogType.Log); } Repaint(); } else { NuitrackSDKGUI.DrawMessage("Play the scene to see the matching poses for the users", LogType.Log); } } EditorGUILayout.EndFoldoutHeaderGroup(); }
void DrawPoseGUI() { GUIStyle contentStyle = new GUIStyle(GUIStyle.none) { margin = new RectOffset(20, 0, 2, 2) }; GUIStyle foldoutStyle = new GUIStyle(EditorStyles.foldout) { fontStyle = FontStyle.Bold }; List <nuitrack.JointType> jointsMask = NuitrackPoseWrapper.JointsMask; using (new VerticalGroup(contentStyle)) { GUIContent relativeButtonContent = new GUIContent("Relative mode", "In relative mode, the rotation of the trunk will not affect the correspondence of the pose"); poseWrapper.RelativeMode = EditorGUILayout.Toggle(relativeButtonContent, poseWrapper.RelativeMode); List <nuitrack.JointType> activeJoints = jointsMask.Where(k => poseWrapper[k].IsActive).ToList(); skeletonMapper.Draw(activeJoints); if (skeletonPoseView != null) { skeletonPoseView.DrawGUIInspector(); } if (SelectedJoint != nuitrack.JointType.None) { NuitrackSDKGUI.DrawMessage("You can disable the selected joint by clicking on it.", LogType.Log); } EditorGUILayout.Space(); openAdvanced = GUILayout.Toggle(openAdvanced, "Advanced settings", foldoutStyle); if (openAdvanced) { using (new VerticalGroup(contentStyle)) DrawPoseAdvanced(); } EditorGUILayout.Space(); } }
/// <summary> /// Draw a GUI in the inspector. /// Use this in method OnInspectorGUI of your custom editors. /// </summary> public void DrawInspectorGUI() { EditorGUILayout.LabelField("Skeleton display mode", EditorStyles.boldLabel); switch (CurrentViewMode) { case ViewMode.ModelBones: string modelBonesMessage = SelectedJoint == nuitrack.JointType.None ? "Select the joint on the avatar, and then specify the joint on the model in order to set the match." : "Specify the joint on the model in order to set the match. \nClick \"Deselect\" for cancels selection."; NuitrackSDKGUI.DrawMessage(modelBonesMessage, LogType.Log); break; case ViewMode.AssignedBones: string assignedBonesMessage = "The mode displays the specified joints of the skeleton. You can blow out the joints on the model."; NuitrackSDKGUI.DrawMessage(assignedBonesMessage, LogType.Log); break; } CurrentViewMode = (ViewMode)GUILayout.Toolbar((int)CurrentViewMode, skeletonModeGuiContent); }
void DrawFramePreview() { float pointScale = 0.025f; float lineScale = 0.01f; ShowPreview = EditorGUILayout.BeginFoldoutHeaderGroup(ShowPreview, "Frame viewer"); if (ShowPreview) { if (!EditorApplication.isPlaying) { NuitrackSDKGUI.DrawMessage("RGB and depth frames will be displayed run time.", LogType.Log); } else { if (rgbCache == null) { rgbCache = new TextureCache(); } if (depthCache == null) { depthCache = new TextureCache(); } List <Vector2> pointCoord = new List <Vector2>(); rgbTexture = NuitrackManager.ColorFrame.ToRenderTexture(rgbCache); depthTexture = NuitrackManager.DepthFrame.ToRenderTexture(textureCache: depthCache); Rect rgbRect = NuitrackSDKGUI.DrawFrame(rgbTexture, "RGB frame"); Texture pointTexture = EditorGUIUtility.IconContent("sv_icon_dot0_pix16_gizmo").image; float lineSize = rgbRect.size.magnitude * lineScale; foreach (UserData user in NuitrackManager.Users) { if (user.Skeleton != null) { Color userColor = FrameUtils.SegmentToTexture.GetColorByID(user.ID); foreach (nuitrack.JointType jointType in System.Enum.GetValues(typeof(nuitrack.JointType))) { nuitrack.JointType parentJointType = jointType.GetParent(); UserData.SkeletonData.Joint joint = user.Skeleton.GetJoint(jointType); if (joint.Confidence > 0.1f) { Vector2 startPoint = new Vector2(rgbRect.x + rgbRect.width * joint.Proj.x, rgbRect.y + rgbRect.height * (1 - joint.Proj.y)); pointCoord.Add(startPoint); if (jointType.GetParent() != nuitrack.JointType.None) { UserData.SkeletonData.Joint parentJoint = user.Skeleton.GetJoint(parentJointType); if (parentJoint.Confidence > 0.1f) { Vector2 endPoint = new Vector2(rgbRect.x + rgbRect.width * parentJoint.Proj.x, rgbRect.y + rgbRect.height * (1 - parentJoint.Proj.y)); Handles.DrawBezier(startPoint, endPoint, startPoint, endPoint, userColor, null, lineSize); } } } } float pointSize = rgbRect.size.magnitude * pointScale; foreach (Vector3 point in pointCoord) { Rect rect = new Rect(point.x - pointSize / 2, point.y - pointSize / 2, pointSize, pointSize); GUI.DrawTexture(rect, pointTexture, ScaleMode.ScaleToFit); } } } NuitrackSDKGUI.DrawFrame(depthTexture, "Depth frame"); Repaint(); } } EditorGUILayout.EndFoldoutHeaderGroup(); }
void DrawRuntimeWizard() { GUIContent wizardLabel = new GUIContent("Save runtime pose wizard", EditorGUIUtility.IconContent("AvatarSelector").image); ShowRuntimePoseWizard = EditorGUILayout.BeginFoldoutHeaderGroup(ShowRuntimePoseWizard, wizardLabel); if (ShowRuntimePoseWizard) { if (NuitrackManager == null) { UnityAction fixNuitrack = delegate { NuitrackMenu.AddNuitrackToScene(); }; NuitrackSDKGUI.DrawMessage("The wizard requires NuitrackScripts on the scene.", LogType.Error, fixNuitrack, "Fix"); Selection.activeObject = target; } else { if (!EditorApplication.isPlaying) { using (new VerticalGroup(EditorStyles.helpBox)) EditorGUILayout.LabelField("1) Play \n2) Stand in a pose \n3) Save pose", EditorStyles.wordWrappedLabel); EditorGUILayout.Space(); SaveFolder = NuitrackSDKGUI.OpenFolderField(SaveFolder, "Save pose folder", true, DefaultPath); GUIContent playScene = new GUIContent("Play", EditorGUIUtility.IconContent("PlayButton").image); EditorGUILayout.Space(); if (GUILayout.Button(playScene)) { EditorApplication.isPlaying = true; } } else { UserData user = NuitrackManager.Users.Current; bool disable = user == null || user.Skeleton == null; Texture icon = disable ? NuitrackSDKGUI.GetMessageIcon(LogType.Warning) : null; Color backgroundColor = disable ? Color.yellow : Color.green; string message = "After saving a pose, playback will stop and the saved pose will open"; if (disable) { message = string.Format("{0}\n{1}", "The user was not found. Stand in front of the sensor to save a pose.", message); } GUIContent messageGUI = new GUIContent(message, icon); UnityAction savePose = delegate { SaveRuntimePose(user.Skeleton); }; GUIContent iconAvatar = new GUIContent("Save runtime pose", EditorGUIUtility.IconContent("SaveAs").image); EditorGUI.BeginDisabledGroup(disable); NuitrackSDKGUI.DrawMessage(messageGUI, backgroundColor, savePose, iconAvatar); EditorGUI.EndDisabledGroup(); Repaint(); if (rgbCache == null) { rgbCache = new TextureCache(); } rgbTexture = NuitrackManager.ColorFrame.ToRenderTexture(rgbCache); NuitrackSDKGUI.DrawFrame(rgbTexture, "RGB Preview"); } } } EditorGUILayout.EndFoldoutHeaderGroup(); }