Forum rules - please read before posting.

Fullscreen Toggle - Anyone Done It?

Hey everybody,

I undertook the great tutorial Chris put up about how to set a resolution setting into your options menu, but he also mentioned that the 'same method' could be used to create a full screen toggle.

I'm guessing that he means you have to use a script that does something along the lines of this:


But I'm not sure exactly what. Has anyone made an Action that does this? I know how to set it up in the Menu and all that, just unsure of the script.

Thanks!
«1

Comments

  • I could never end up figuring this out, but I came up with another solution in case anyone was curious...

    Instead of having a separate toggle for fullscreen, I simply put 'Fullscreen' or 'Windowed' in with my resolution settings... So players can pick '800 x 600 (Fullscreen)' or '800 x 600 (Windowed)'

    It's actually a little bit more elegant than having a separate fullscreen toggle, I think.

    Also, I can't say I recommend 800 x 600 fullscreen. :P
  • Good suggestion!  I've personally found Unity's resolution / fullscreen functions to be a little suspect, so I'm glad to hear this is working for you.
  • edited December 2021

    Where do I find the tutorial mentioned above? EDIT: Found it

  • Trying to follow the tutorial but getting tripped up on script, i have this so far:

    using UnityEngine;

    if UNITY_EDITOR

    using UnityEditor;

    endif

    namespace AC
    {

    [System.Serializable]
    public class ActionApplyResolution : Action
    {


    public override ActionCategory Category { get { return ActionCategory.Engine; }}
    public override string Title { get { return "Apply resolution"; }}



    override public float Run ()
    {
    int chosenIndex = GlobalVariables.GetIntegerValue (0); // Replace '0' with your own variable's ID number
    if (chosenIndex >= 0)
    {
    Resolution chosenResolution = Screen.resolutions [chosenIndex];

      Screen.SetResolution (chosenResolution.width, chosenResolution.height, Screen.fullScreen);
      KickStarter.playerMenus.RecalculateAll ();
    

    }
    return 0f;
    }


    }

    Getting this error:

    Assets/TMOWM/Scripts/CustomActions/ActionApplyResolution.cs(45,2): error CS1513: } expected

  • Add a "}" character to the end.

  • added an extra one and now get this error:

    Assets/AdventureCreator/Scripts/Actions/ActionApplyResolution.cs(25,26): error CS0115: 'ActionApplyResolution.Title': no suitable method found to override

  • What is your AC version?

  • so i get no error now but it is not showing up in my custom actions

  • What did you change to remove the error?

    Share the script - properly formatted - as well as its filename and location.

  •     using UnityEngine;
        #if UNITY_EDITOR
        using UnityEditor;
        #endif
    
        namespace AC
        {
    
            [System.Serializable]
            public class ActionApplyResolution : Action
            {
    
                public override ActionCategory Category { get { return ActionCategory.Engine; }}
                public override string Title { get { return "Apply resolution"; }}
    
    
    
                override public float Run ()
                {
                    int chosenIndex = GlobalVariables.GetIntegerValue (24); // Replace '0' with your own variable's ID number
                    if (chosenIndex >= 0)
            {
                Resolution chosenResolution = Screen.resolutions [chosenIndex];
    
                Screen.SetResolution (chosenResolution.width, chosenResolution.height, Screen.fullScreen);
                KickStarter.playerMenus.RecalculateAll ();
            }
            return 0f;
        }
    
                }
            }
    

    The path is here, with my other custom action scripts that do show up in actions menu:

    Assets/Sleepytime Village/Scripts/CustomActions

    I am using v1.74

  • Does it appear in the Actions Manager?

    It should be listed in the "Engine" category - not "Custom".

  • edited December 2021

    ah yes it does... my bad!

  • So, it seems to be almost working now, however, should there be choices available when clicking on the screen resolution element in play? there is no resolutions to cycle through? See screenshots:

    https://www.dropbox.com/sh/6hwh6w4ipju5ezl/AAALQVKPqPsKoDCfnuomSpA8a?dl=0

  • The resolutions are set by the tutorial's SetupOptionsMenu script - not by the Action. You can place Debug.Log statements inside the GenerateResolutionCycleOptions function to check what's running.

    Though, the behaviour will vary between builds and Editor. If logs show in the Editor, what is the behaviour in a build?

  • ok thanks!

    In regards to this code:

    MenuCycle resolutionCycle = PlayerMenus.GetElementWithName ("Options1", "ScreenResolution") as AC.MenuCycle;

    How would I modify this code if I wanted the script to affect 2 Options menu one called Options and one called Options1

    Thanks!

  • Though, the behaviour will vary between builds and Editor. If logs show in the Editor, what is the behaviour in a build?

    Plus, I am still only presented with one option in build, see screenshot:

    https://www.dropbox.com/s/bhuw7kf6wnhxp81/screenResOptionsInBuild.png?dl=0

  • How would I modify this code if I wanted the script to affect 2 Options menu one called Options and one called Options1

    void GenerateResolutionCycleOptions ()
    {
        MenuCycle resolutionCycle1 = PlayerMenus.GetElementWithName ("Options1", "ScreenResolution") as AC.MenuCycle;
        MenuCycle resolutionCycle2 = PlayerMenus.GetElementWithName ("Options1", "ScreenResolution") as AC.MenuCycle;
    
        resolutionCycle1.optionsArray.Clear ();
        resolutionCycle2.optionsArray.Clear ();
        foreach (Resolution resolution in Screen.resolutions)
        {
            string optionLabel = resolution.width.ToString () + " x " + resolution.height.ToString () + " (" + resolution.refreshRate.ToString () + ")";
            resolutionCycle1.optionsArray.Add (optionLabel);
            resolutionCycle2.optionsArray.Add (optionLabel);
        }
    }
    

    Plus, I am still only presented with one option in build, see screenshot

    The cycle element populates itself from Unity's Screen.resolutions array. What options are presented will be based on your platform, hardware, and project settings - AC is not involved in what exact options are presented.

  • ok thanks, any reason why it has the (0) at the end of the screen resolution in play?

  • That ought to represent the refresh rate. You can remove it by replacing:

    string optionLabel = resolution.width.ToString () + " x " + resolution.height.ToString () + " (" + resolution.refreshRate.ToString () + ")";
    

    with:

    string optionLabel = resolution.width.ToString () + " x " + resolution.height.ToString ();
    
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.