0
\$\begingroup\$

I have 3 script which is OptionPopup.cs,MC_StreamingOption.cs,MC_OptionPopUp.cs. Now here is a screenshot of my UI so that you can fully understand my question.

enter image description here The Option below on the left side the Horse Racing Scene must be the same value as on the Game Option Board which is on the right side.

For ex: I choose Rendering then on the GameOption the Rendering also will be checked the same as when i choose on the GameOption the Rendering then on the Horse Racing Scene below on the left side the Rendering will be checked.

So here is my script for the Game Option(On the right side option). Note: They are on different scenes so basically i could not use static field on my UI's

OptionPopUp.cs

 public void LiveStreaming()
{
    
    if (livestream.normalSprite == RADIO_OFF_SPRITE_NAME && MC_StreamingOption.isLiveStreamingOutside)
    {
        livestream.normalSprite = RADIO_ON_SPRITE_NAME;
        isCheckedLivestream = true;
        PlayerPrefs.SetInt(LiveStreaming_, 1);

        if (isCheckedLivestream)
        {
            render.normalSprite = RADIO_OFF_SPRITE_NAME;
            PlayerPrefs.SetInt(Rendering_, 0);
        }
    } else
    {
        livestream.normalSprite = RADIO_OFF_SPRITE_NAME;
        isCheckedLivestream = false;
        PlayerPrefs.SetInt(LiveStreaming_, 0);

        if (!isCheckedLivestream && render.normalSprite == RADIO_OFF_SPRITE_NAME)
        {
            render.normalSprite = RADIO_ON_SPRITE_NAME;
            PlayerPrefs.SetInt(Rendering_, 1);
        }
    } 
}

public void Rendering()
{

    if (render.normalSprite == RADIO_OFF_SPRITE_NAME && MC_StreamingOption.isRenderingOutside)
    {
        render.normalSprite = RADIO_ON_SPRITE_NAME;
        isCheckedRendering = true;
        PlayerPrefs.SetInt(Rendering_, 1);

        if (isCheckedRendering)
        {
            livestream.normalSprite = RADIO_OFF_SPRITE_NAME;
            PlayerPrefs.SetInt(LiveStreaming_, 0);
        }
    } else
    {
        render.normalSprite = RADIO_OFF_SPRITE_NAME;
        isCheckedRendering = false;
        PlayerPrefs.SetInt(Rendering_, 0);

        if (!isCheckedRendering && livestream.normalSprite == RADIO_OFF_SPRITE_NAME)
        {
            livestream.normalSprite = RADIO_ON_SPRITE_NAME;
            PlayerPrefs.SetInt(LiveStreaming_, 1);
        }
    }
}

Here's what i'm doing in the Horce Racing Scene(on the left side below)

MC_StreamingOption

//[PK Debug 2/6/2018]
public string RADIO_ON_SPRITE_NAME = "popup_radiobtn01_on";

public string RADIO_OFF_SPRITE_NAME = "popup_radiobtn01_off";

[SerializeField] UIButton livestream = null;

[SerializeField] UIButton render = null;

public static bool isLiveStreamingOutside = false;
public static bool isRenderingOutside = false;

public void LiveStreaming()
{
    if (livestream.normalSprite == RADIO_OFF_SPRITE_NAME)
    {
        livestream.normalSprite = RADIO_ON_SPRITE_NAME;
        //render.normalSprite = RADIO_OFF_SPRITE_NAME;

        if (livestream.normalSprite == RADIO_ON_SPRITE_NAME)
        {
            PlayerPrefs.GetInt(OptionPopup.LiveStreaming_, 1);
            isLiveStreamingOutside = true;
            render.normalSprite = RADIO_OFF_SPRITE_NAME;
        }
    }
    else
    {
        livestream.normalSprite = RADIO_OFF_SPRITE_NAME;
        render.normalSprite = RADIO_ON_SPRITE_NAME;

        if (livestream.normalSprite == RADIO_OFF_SPRITE_NAME)
        {
            PlayerPrefs.GetInt(OptionPopup.LiveStreaming_, 0);
            isLiveStreamingOutside = false;
            render.normalSprite = RADIO_ON_SPRITE_NAME;
        }
    }
}

public void Rendering()
{
    if (render.normalSprite == RADIO_OFF_SPRITE_NAME)
    {
        render.normalSprite = RADIO_ON_SPRITE_NAME;
        livestream.normalSprite = RADIO_OFF_SPRITE_NAME;

        if (render.normalSprite == RADIO_ON_SPRITE_NAME)
        {
            PlayerPrefs.GetInt(OptionPopup.Rendering_,1);
            isRenderingOutside = true;
            livestream.normalSprite = RADIO_OFF_SPRITE_NAME;
        }
    } else
    {
        render.normalSprite = RADIO_OFF_SPRITE_NAME;
        livestream.normalSprite = RADIO_ON_SPRITE_NAME;

        if (render.normalSprite == RADIO_OFF_SPRITE_NAME)
        {
            PlayerPrefs.GetInt(OptionPopup.Rendering_, 0);
            isRenderingOutside = false;
            livestream.normalSprite = RADIO_ON_SPRITE_NAME;
        }
    }
}

So I'm calling the Game Option(On the right side) by this code:

MC_OptionPopUp.cs

if (tzGlobal.Instance.UserConsoleType == tzGlobal.eGameRH_ConsoleType.LOBBY)
    {
        if (PlayerPrefs.GetInt(OptionPopup.LiveStreaming_) == 1)
        {
            livestream.normalSprite = RADIO_ON_SPRITE_NAME;
        }
        else
        {
            livestream.normalSprite = RADIO_OFF_SPRITE_NAME;
        }

        if (PlayerPrefs.GetInt(OptionPopup.Rendering_) == 1)
        {
            render.normalSprite = RADIO_ON_SPRITE_NAME;
        }
        else
        {
            render.normalSprite = RADIO_OFF_SPRITE_NAME;
        }
    }

Just like that so that you will know that i'm doing it like that. I would really appreciate if someone can help me out with my problem.

\$\endgroup\$
0
\$\begingroup\$

Not sure I completely understand the question but static fields of a class should stay the same regardless of whether or not you changed scenes.

For example if your class name is Foo and your static field is named bar, you should be able to access it via Foo.bar regardless of the scene you are currently in.

I would recommend making whatever variable you are using to store the option a static field (if it isn't already) and when a scene is loaded you can check whether the value of option has changed during Start() and then set your checkbox to the appropriate state.

\$\endgroup\$
0
\$\begingroup\$

What i did here is this

if (livestream.normalSprite == RADIO_OFF_SPRITE_NAME)
    {
        isLiveStreamingOutside = true;
        PlayerPrefs.SetInt(OptionPopup.LiveStreaming_, 1);

        if (isLiveStreamingOutside)
        {
            render.normalSprite = RADIO_OFF_SPRITE_NAME;
            livestream.normalSprite = RADIO_ON_SPRITE_NAME;
            PlayerPrefs.SetInt(OptionPopup.Rendering_, 0);
        }
    }
    else
    {

        isLiveStreamingOutside = false;
        PlayerPrefs.SetInt(OptionPopup.LiveStreaming_, 0);

        if (!isLiveStreamingOutside)
        {
            render.normalSprite = RADIO_ON_SPRITE_NAME;
            livestream.normalSprite = RADIO_OFF_SPRITE_NAME;
            PlayerPrefs.SetInt(OptionPopup.Rendering_, 1);
        }
    }

So from MC_StreamingOption.cs I have no choice but to get the playerprefs again. And it works.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.