Ejemplo n.º 1
0
    public override void OnInspectorGUI()
    {
        serializedObject.Update();
        displayManagerLink.Update();

        EditorGUILayout.PropertyField(displays, true);

        EditorGUILayout.Space();

        //if there is only one display we want to give the user the opportunity to set fullscreen
        if (displays.arraySize == 1)
        {
//			allowResolutionDialog.boolValue = EditorGUILayout.Toggle(new GUIContent(  "Allow Resolution Dialog", "Enables the Resolution Dialog when your "
//			                                                                        + "standalone build starts if you have only one RUISDisplay. NOTE: In "
//			                                                                        + "all other cases the 'Display Resolution Dialog' setting in Unity's "
//			                                                                        + "Player Settings will be overriden with false. In those cases RUIS "
//			                                                                        + "will attempt to force the standalone game window to have the total "
//			                                                                        + "resolution that is the sum of your RUISDisplays arranged side-by-side."),
//			                                                         allowResolutionDialog.boolValue);
//            if (allowResolutionDialog.boolValue)
//            {
//                PlayerSettings.displayResolutionDialog = ResolutionDialogSetting.Enabled;
//            }
//            else
//            {
//                PlayerSettings.displayResolutionDialog = ResolutionDialogSetting.Disabled;
//            }
        }
        else
        {
            EditorStyles.textField.wordWrap = true;
            EditorGUILayout.TextArea("Below configuration has multiple RUISDisplays. 'Display Resolution Dialog' setting is automatically disabled "
                                     + "in Unity's Player Settings.", GUILayout.Height(60));

            PlayerSettings.displayResolutionDialog = ResolutionDialogSetting.Disabled;
//            allowResolutionDialog.boolValue = false;
        }

        if (GUILayout.Button("Add Display"))
        {
            displays.arraySize++;
            SerializedProperty newDisplayProperty = displays.GetArrayElementAtIndex(displays.arraySize - 1);
            GameObject         newDisplay         = Instantiate(displayPrefab) as GameObject;
            newDisplay.name = "NewDisplay";
            newDisplay.GetComponent <RUISDisplay>().xmlFilename = newDisplay.name + displays.arraySize + ".xml";
            newDisplay.transform.parent             = (target as RUISDisplayManager).transform;
            newDisplayProperty.objectReferenceValue = newDisplay;
        }

        EditorGUILayout.Space();

        int removeIndex = -1;

        for (int i = 0; i < displays.arraySize; i++)
        {
            //DisplayEditor(displays.GetArrayElementAtIndex(i));
            EditorGUILayout.BeginHorizontal();
            //EditorGUILayout.PropertyField(displays.GetArrayElementAtIndex(i));

            RUISDisplay display = displays.GetArrayElementAtIndex(i).objectReferenceValue as RUISDisplay;
            if (display == null)
            {
                continue;
            }
            EditorGUILayout.LabelField(string.Format("{0} ({1}x{2})", display.name, display.resolutionX, display.resolutionY));

            if (displays.arraySize > 1)
            {
                if (GUILayout.Button("Move Up", GUILayout.ExpandWidth(false)))
                {
                    MoveUp(i);
                }

                if (GUILayout.Button("Move Down", GUILayout.ExpandWidth(false)))
                {
                    MoveDown(i);
                }
            }

            if (GUILayout.Button("Delete", GUILayout.ExpandWidth(false)))
            {
                if (EditorUtility.DisplayDialog("Confirm deletion", "Are you sure you want to delete this display?", "Delete", "Cancel"))
                {
                    removeIndex = i;
                }
            }

            EditorGUILayout.EndHorizontal();
        }

        if (removeIndex != -1)
        {
            for (int i = removeIndex + 1; i < displays.arraySize; i++)
            {
                MoveUp(i);
            }
            displays.DeleteArrayElementAtIndex(displays.arraySize - 1);
            displays.arraySize--;
        }

        RUISDisplayManager displayManager = target as RUISDisplayManager;

        displayManager.CalculateTotalResolution();
        PlayerSettings.defaultScreenWidth  = displayManager.totalRawResolutionX;
        PlayerSettings.defaultScreenHeight = displayManager.totalRawResolutionY;

        //stuff for drawing the display boxes
        int optimalWidth  = Screen.width - displayManager.displays.Count;
        int optimalHeight = (int)((float)displayManager.totalResolutionY / displayManager.totalResolutionX * optimalWidth);

        EditorGUILayout.Space();
        EditorGUILayout.BeginHorizontal(GUILayout.Width(Screen.width), GUILayout.Height(optimalHeight));

        foreach (RUISDisplay display in displayManager.displays)
        {
            if (display.isStereo)
            {
                displayBoxStyle.normal.background = stereoDisplayTexture;
            }
            else
            {
                displayBoxStyle.normal.background = monoDisplayTexture;
            }
            GUILayout.Box(display.name, displayBoxStyle, GUILayout.Width(((float)display.resolutionX / displayManager.totalResolutionX) * optimalWidth), GUILayout.Height(optimalHeight * (float)display.resolutionY / displayManager.totalResolutionY));
        }

        EditorGUILayout.EndHorizontal();

        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.LabelField("Display With RUIS Menu:");
        guiDisplayChoices = new List <string>();
        for (int i = 0; i < displayManager.displays.Count; ++i)
        {
            guiDisplayChoices.Add(i + " " + displayManager.displays[i].name);
        }
        //MonoBehaviour.print(guiDisplayChoiceLink + ":" + guiDisplayChoices.Count);
        if (guiDisplayChoiceLink.intValue >= guiDisplayChoices.Count)
        {
            guiDisplayChoiceLink.intValue = 0;
        }
        guiDisplayChoiceLink.intValue = EditorGUILayout.Popup(guiDisplayChoiceLink.intValue, guiDisplayChoices.ToArray());
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.PropertyField(ruisMenuPrefab);



        EditorGUILayout.LabelField("RUIS Menu Local Coordinates:");
        EditorGUILayout.PropertyField(guiX, new GUIContent("X", "X-offset from camera"));
        EditorGUILayout.PropertyField(guiY, new GUIContent("Y", "Y-offset from camera"));
        EditorGUILayout.PropertyField(guiZ, new GUIContent("Z", "Z-offset from camera"));

        EditorGUILayout.Space();

        EditorGUILayout.LabelField("RUIS Menu Scale:");
        EditorGUILayout.PropertyField(guiScaleX, new GUIContent("X-scale", "Scales menu horizontally"));
        EditorGUILayout.PropertyField(guiScaleY, new GUIContent("Y-scale", "Scales menu vertically"));
        EditorGUILayout.Space();
        EditorGUILayout.PropertyField(hideMouseOnPlay, new GUIContent("Hide Mouse On Play", "Operating system mouse cursor will be hidden"));
        EditorGUILayout.Space();
        EditorGUILayout.PropertyField(menuCursorPrefab, new GUIContent("Menu Cursor Prefab", "The prefab that will be instantiated when RUIS Menu is "
                                                                       + "invoked (ESC key)"));
        menuLayer.intValue = EditorGUILayout.LayerField(new GUIContent("Menu Layer", "RUIS Menu mouse cursor ray is cast against objects on this layer only"), menuLayer.intValue);


        serializedObject.ApplyModifiedProperties();
        displayManagerLink.ApplyModifiedProperties();


        //remove all child displays that aren't in the list anymore
        RUISDisplay displayToDestroy = null;

        foreach (RUISDisplay display in displayManager.GetComponentsInChildren <RUISDisplay>())
        {
            if (!displayManager.displays.Contains(display))
            {
                displayToDestroy = display;
            }
        }
        if (displayToDestroy)
        {
            DestroyImmediate(displayToDestroy.gameObject);
        }
    }
Ejemplo n.º 2
0
    public override void OnInspectorGUI()
    {
        serializedObject.Update();

        EditorGUILayout.PropertyField(displays, true);

        EditorGUILayout.Space();

        //if there is only one display we want to give the user the opportunity to set fullscreen
        if (displays.arraySize == 1)
        {
            allowResolutionDialog.boolValue = EditorGUILayout.Toggle(new GUIContent("Allow resolution dialog", "Allow the usage of the resolution dialog"), allowResolutionDialog.boolValue);
            if (allowResolutionDialog.boolValue)
            {
                PlayerSettings.displayResolutionDialog = ResolutionDialogSetting.Enabled;
            }
            else
            {
                PlayerSettings.displayResolutionDialog = ResolutionDialogSetting.Disabled;
            }
        }
        else
        {
            PlayerSettings.displayResolutionDialog = ResolutionDialogSetting.Disabled;
            allowResolutionDialog.boolValue        = false;
        }

        if (GUILayout.Button("Add display"))
        {
            displays.arraySize++;
            SerializedProperty newDisplayProperty = displays.GetArrayElementAtIndex(displays.arraySize - 1);
            GameObject         newDisplay         = Instantiate(displayPrefab) as GameObject;
            newDisplay.name = "NewDisplay";
            newDisplay.GetComponent <RUISDisplay>().xmlFilename = newDisplay.name + displays.arraySize + ".xml";
            newDisplay.transform.parent             = (target as RUISDisplayManager).transform;
            newDisplayProperty.objectReferenceValue = newDisplay;
        }

        EditorGUILayout.Space();

        int removeIndex = -1;

        for (int i = 0; i < displays.arraySize; i++)
        {
            //DisplayEditor(displays.GetArrayElementAtIndex(i));
            EditorGUILayout.BeginHorizontal();
            //EditorGUILayout.PropertyField(displays.GetArrayElementAtIndex(i));

            RUISDisplay display = displays.GetArrayElementAtIndex(i).objectReferenceValue as RUISDisplay;
            if (display == null)
            {
                continue;
            }
            EditorGUILayout.LabelField(string.Format("{0} ({1}x{2})", display.name, display.resolutionX, display.resolutionY));

            if (displays.arraySize > 1)
            {
                if (GUILayout.Button("Move up", GUILayout.ExpandWidth(false)))
                {
                    MoveUp(i);
                }

                if (GUILayout.Button("Move down", GUILayout.ExpandWidth(false)))
                {
                    MoveDown(i);
                }
            }

            if (GUILayout.Button("Delete", GUILayout.ExpandWidth(false)))
            {
                if (EditorUtility.DisplayDialog("Confirm deletion", "Are you sure you want to delete this display?", "Delete", "Cancel"))
                {
                    removeIndex = i;
                }
            }

            EditorGUILayout.EndHorizontal();
        }

        if (removeIndex != -1)
        {
            for (int i = removeIndex + 1; i < displays.arraySize; i++)
            {
                MoveUp(i);
            }
            displays.DeleteArrayElementAtIndex(displays.arraySize - 1);
            displays.arraySize--;
        }

        RUISDisplayManager displayManager = target as RUISDisplayManager;

        displayManager.CalculateTotalResolution();
        PlayerSettings.defaultScreenWidth  = displayManager.totalRawResolutionX;
        PlayerSettings.defaultScreenHeight = displayManager.totalRawResolutionY;

        //stuff for drawing the display boxes
        int optimalWidth  = Screen.width - displayManager.displays.Count;
        int optimalHeight = (int)((float)displayManager.totalResolutionY / displayManager.totalResolutionX * optimalWidth);

        EditorGUILayout.Space();
        EditorGUILayout.BeginHorizontal(GUILayout.Width(Screen.width), GUILayout.Height(optimalHeight));

        foreach (RUISDisplay display in displayManager.displays)
        {
            if (display.isStereo)
            {
                displayBoxStyle.normal.background = stereoDisplayTexture;
            }
            else
            {
                displayBoxStyle.normal.background = monoDisplayTexture;
            }
            GUILayout.Box(display.name, displayBoxStyle, GUILayout.Width(((float)display.resolutionX / displayManager.totalResolutionX) * optimalWidth), GUILayout.Height(optimalHeight * (float)display.resolutionY / displayManager.totalResolutionY));
        }

        EditorGUILayout.EndHorizontal();

        serializedObject.ApplyModifiedProperties();

        //remove all child displays that aren't in the list anymore
        RUISDisplay displayToDestroy = null;

        foreach (RUISDisplay display in displayManager.GetComponentsInChildren <RUISDisplay>())
        {
            if (!displayManager.displays.Contains(display))
            {
                displayToDestroy = display;
            }
        }
        if (displayToDestroy)
        {
            DestroyImmediate(displayToDestroy.gameObject);
        }
    }