private void DrawSceneInfo(Rect dynamicrect, bool darkBackground, SceneInfo sceneInfo, SceneSelectMenu sceneSelect) { string background = darkBackground ? "dynamicentry_even" : "dynamicentry_odd"; Event e = Event.current; if (e.isMouse && e.type == EventType.MouseDown) { if (e.mousePosition.x < dynamicrect.x || e.mousePosition.x > dynamicrect.x + dynamicrect.width - 100 || e.mousePosition.y < dynamicrect.y || e.mousePosition.y > dynamicrect.y + dynamicrect.height) { } else { Selection.activeObject = sceneSelect; selectedSceneInfoPath = sceneInfo.ScenePath; } } GUI.Label(dynamicrect, sceneInfo.DisplayName, background); if (string.IsNullOrEmpty(sceneInfo.ScenePath)) { Rect warningRect = dynamicrect; warningRect.x = 30; warningRect.width = 30; GUI.Label(warningRect, new GUIContent(CognitiveVR.EditorCore.Alert, "Missing Scene Path"), "image_centered"); } if (e.mousePosition.x < dynamicrect.x || e.mousePosition.x > dynamicrect.x + dynamicrect.width || e.mousePosition.y < dynamicrect.y || e.mousePosition.y > dynamicrect.y + dynamicrect.height) { } else { //draw up/down arrows float height = dynamicrect.height / 2; float offset = dynamicrect.height / 2; Rect up = new Rect(435, dynamicrect.y, 18, height - 1); Rect down = new Rect(435, dynamicrect.y + offset + 1, 18, height - 1); if (GUI.Button(up, "^")) { selectedSceneInfoPath = sceneInfo.ScenePath; var all = sceneSelect.SceneInfos; int index = all.IndexOf(sceneInfo); if (index > 0) { all.Remove(sceneInfo); all.Insert(index - 1, sceneInfo); } } if (GUI.Button(down, "v")) { selectedSceneInfoPath = sceneInfo.ScenePath; var all = sceneSelect.SceneInfos; int index = all.IndexOf(sceneInfo); if (index < all.Count - 1) { all.Remove(sceneInfo); all.Insert(index + 1, sceneInfo); } } } if (selectedSceneInfoPath == sceneInfo.ScenePath) { GUI.Box(dynamicrect, "", "box_sharp_alpha"); } }
void DrawAssessment(AssessmentBase assessment, Rect rect, bool darkbackground) { Event e = Event.current; if (e.isMouse && e.type == EventType.MouseDown) { if (e.mousePosition.x < rect.x || e.mousePosition.x > rect.x + rect.width - 100 || e.mousePosition.y < rect.y || e.mousePosition.y > rect.y + rect.height) { } else { if (e.shift) //add to selection { GameObject[] gos = new GameObject[Selection.transforms.Length + 1]; Selection.gameObjects.CopyTo(gos, 0); gos[gos.Length - 1] = assessment.gameObject; Selection.objects = gos; } else { Selection.activeTransform = assessment.transform; } } } if (darkbackground) GUI.Box(rect, "", "dynamicentry_even"); else GUI.Box(rect, "", "dynamicentry_odd"); bool forceWarning = false; if (assessment.GetType() == typeof(SceneSelectMenu)) { var all = GetAllAssessments(); //warning if scene select assessment exists and is not last if (SceneSelectAssessment == null) { var sceneMenu = all.Find(delegate (AssessmentBase obj) { return obj.GetType() == typeof(SceneSelectMenu); }); if (sceneMenu != null) SceneSelectAssessment = (SceneSelectMenu)sceneMenu; } if (SceneSelectAssessment != null) { if (SceneSelectAssessment.Order != all.Count - 1) { forceWarning = true; } } } if (Selection.activeTransform == assessment.transform) { GUI.Box(rect, "", "box_sharp_alpha"); } float height = rect.height / 2; float offset = rect.height / 2; Rect up = new Rect(rect.x + 407, rect.y, 18, height - 1); Rect down = new Rect(rect.x + 407, rect.y + offset + 1, 18, height - 1); bool needsRefresh = false; if (e.mousePosition.x < rect.x || e.mousePosition.x > rect.x + rect.width || e.mousePosition.y < rect.y || e.mousePosition.y > rect.y + rect.height) { } else { if (GUI.Button(up, "^")) { var all = GetAllAssessments(); int index = all.IndexOf(assessment); if (index > 0) { all.Remove(assessment); all.Insert(index - 1, assessment); needsRefresh = true; } } if (GUI.Button(down, "v")) { var all = GetAllAssessments(); int index = all.IndexOf(assessment); if (index < all.Count - 1) { all.Remove(assessment); all.Insert(index + 1, assessment); needsRefresh = true; } } } Rect isActiveRect = new Rect(rect.x + 10, rect.y, 24, rect.height); Rect gameObjectRect = new Rect(rect.x + 60, rect.y, 420, rect.height); if (assessment.Active && !forceWarning) { GUI.Label(isActiveRect, CognitiveVR.EditorCore.Checkmark, "image_centered"); } else { GUI.Label(isActiveRect, CognitiveVR.EditorCore.Alert, "image_centered"); } if (needsRefresh) { var all = GetAllAssessments(); for (int i = 0; i < all.Count; i++) { all[i].Order = i; } ReorderAssessmentsInScene(); } string tooltip = "No Text Display"; var textComponent = assessment.GetComponentInChildren<UnityEngine.UI.Text>(); if (textComponent != null) { tooltip = textComponent.text; } if (forceWarning) { //scene assessment not in last position tooltip = "Scene Select Menu should be last"; } GUI.Label(gameObjectRect, new GUIContent(assessment.gameObject.name, tooltip), "dynamiclabel"); }
void SceneMenuUpdate() { GUI.Label(steptitlerect, "STEP " + (currentPage + 1) + " - SCENE MENU", "steptitle"); GUI.Label(boldlabelrect, "<b>Step 8:</b> Display scenes when the Ready Room is complete", "normallabel_actionable"); if (!hasDisplayedBuildPopup) { hasDisplayedBuildPopup = true; //popup to add scene to build settings var editorSceneList = new List<EditorBuildSettingsScene>(EditorBuildSettings.scenes); var foundScene = editorSceneList.Find(delegate (EditorBuildSettingsScene obj) { return obj.path.Contains("ReadyRoom"); }); //ready room isn't in build settings or not first in build settings if (foundScene == null || editorSceneList[0] != foundScene) { bool result = EditorUtility.DisplayDialog("Ready Room not in Build Settings", "Ready Room scene should be first scene loaded in build settings. Do you want to change this now?", "Yes", "No"); if (result) { //if it exists, remove ready room scene from list if (foundScene != null) editorSceneList.Remove(foundScene); //get scene asset var foundSceneAssets = AssetDatabase.FindAssets("t:scene ReadyRoom"); if (foundSceneAssets.Length > 0) { string readyRoomPath = AssetDatabase.GUIDToAssetPath(foundSceneAssets[0]); EditorBuildSettingsScene ebss = new EditorBuildSettingsScene(readyRoomPath, true); editorSceneList.Insert(0, ebss); EditorBuildSettings.scenes = editorSceneList.ToArray(); Debug.Log("Added " + readyRoomPath + " to Editor Build Settings"); } } } } if (sceneSelect == null) sceneSelect = FindObjectOfType<SceneSelectMenu>(); if (sceneSelect == null) { //display warning GUI.Label(new Rect(0, 200, 475, 130), CognitiveVR.EditorCore.Alert, "image_centered"); GUI.Label(new Rect(30, 300, 440, 440), "There is no Scene Select Menu in this scene. Make sure the participant can correctly exit Ready Room when completed", "normallabel"); } else { Rect dropArea = new Rect(30, 150, 440, 100); GUI.color = new Color(0, .8f, 0); GUI.Box(dropArea, "", "box_sharp_alpha"); GUI.color = Color.white; if (dropArea.Contains(Event.current.mousePosition)) { DragAndDrop.visualMode = DragAndDropVisualMode.Link; if (Event.current.type == EventType.DragPerform) { foreach (var v in DragAndDrop.objectReferences) { SceneAsset sceneAsset = v as SceneAsset; if (sceneAsset == null) { continue; } string path = AssetDatabase.GetAssetPath(v); var foundSceneByPath = sceneSelect.SceneInfos.Find(delegate (SceneInfo obj) { return obj.ScenePath == path; }); if (string.IsNullOrEmpty(foundSceneByPath.ScenePath)) { string filename = System.IO.Path.GetFileNameWithoutExtension(path); string displayname = ObjectNames.NicifyVariableName(filename.Replace('_', ' ')); sceneSelect.SceneInfos.Add(new SceneInfo() { ScenePath = path, DisplayName = displayname }); //popup to add scene to build settings var editorSceneList = new List<EditorBuildSettingsScene>(EditorBuildSettings.scenes); var foundScene = editorSceneList.Find(delegate (EditorBuildSettingsScene obj) { return obj.path == path; }); if (foundScene == null) { bool result = EditorUtility.DisplayDialog("Scene not in Build Settings", "The selected scene is not currently in the build settings. Do you want to add this now?", "Yes", "No"); if (result) { EditorBuildSettingsScene ebss = new EditorBuildSettingsScene(path, true); editorSceneList.Add(ebss); EditorBuildSettings.scenes = editorSceneList.ToArray(); Debug.Log("Added " + path + " to Editor Build Settings"); } } } } } } else { //DragAndDrop.visualMode = DragAndDropVisualMode.Rejected; } GUI.Label(dropArea, "Drag and Drop Scene Assets here\nto add to the Scene Select Menu", "ghostlabel_actionable"); Rect innerScrollSize = new Rect(30, 0, 420, sceneSelect.SceneInfos.Count * 30); dynamicScrollPosition = GUI.BeginScrollView(new Rect(30, 280, 440, 150), dynamicScrollPosition, innerScrollSize, false, true); Rect dynamicrect; for (int i = 0; i < sceneSelect.SceneInfos.Count; i++) { dynamicrect = new Rect(30, i * 30, 425, 30); bool darkBackground = (i % 2 == 0); DrawSceneInfo(dynamicrect, darkBackground, sceneSelect.SceneInfos[i], sceneSelect); } GUI.EndScrollView(); Repaint(); GUI.Box(new Rect(30, 280, 425, 150), "", "box_sharp_alpha"); if (GUI.Button(new Rect(30, 450, 440, 30), "Start Session when participant selects a scene?", sceneSelect.StartSessionOnSceneChange ? "button_blueoutlineleft" : "button_disabledoutline")) { sceneSelect.StartSessionOnSceneChange = !sceneSelect.StartSessionOnSceneChange; UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty(UnityEditor.SceneManagement.EditorSceneManager.GetActiveScene()); } GUI.Label(new Rect(425, 455, 24, 24), sceneSelect.StartSessionOnSceneChange ? EditorCore.Checkmark : EditorCore.EmptyCheckmark, "image_centered"); } }