c# – Loading external file data into Scriptable Object in Unity

I’ve been at this for two long days, trying to figure out a way to handle saving and loading data for a mobile puzzle game I’m working on. The game has level packs and each level pack has multiple levels. Level packs can be purchased via IAP.

I need access to the fixed data and an easy way to add new data, so I used Scriptable Objects to store my Level Pack and Level data:

LevelPack

  • id
  • type (paid, free)
  • IAPproductId
  • levels (list of levels)

Level

  • id
  • totalTime (total time to solve puzzle)
  • warningTime (give a warning during level)
  • levels (list of levels)

I also need to store the following dynamic data, which can change during runtime:

  • completedTime for each level
  • isPurchased for each level pack

I tried adding these to the scriptable objects and it’s really easy to maintain and work with. But I can’t figure out a way to persist that data between sessions or game updates.

I created a save system that saves just the completed levels to an external file using binary formatter. So every time a level is completed, I change Level.completedTime to the new time on the scriptable object, then do GameState.Instance.UpdateLevelProgress(levelPack.id, levelId, time); to save the file that contains a dictionary with all the completed times.

 public void UpdateLevelProgress(int levelPackId, int levelId, float time)
     {
         if (!levelProgress.ContainsKey(levelPackId))
         {
             levelProgress.Add(levelPackId, new Dictionary<int, float>());
         }
 
         // set time
         levelProgress(levelPackId)(levelId) = time;
 
         // save to file
         SaveGame();
     }

Even though I figured out how to save, I don’t know how to load the data from the file into each Level scriptable object. There is an onEnable function for ScriptableObject, but that runs way before my GameState.LoadGame() function that runs inside a preload scene. So GameState.Instance.levelProgress is empty at that point.

Is there a better, cleaner way to do this?

PS:

Here’s my GameState file:

using UnityEngine;
using System.Collections.Generic;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;

(System.Serializable)
public class GameStateData
{
    public Dictionary<int, Dictionary<int, float>> levelProgress;

    public GameStateData(GameState gameState)
    {
        levelProgress = gameState.levelProgress;
    }
}

public class GameState : Singleton<GameState>
{
      

    // Prevent non-singleton constructor use
    protected GameState() {  }

    // declare variables
    public Dictionary<int, Dictionary<int, float>> levelProgress = new Dictionary<int, Dictionary<int, float>>();



    #region Load / Save Methods
    public void LoadGame()
    {

        string path = Path.Combine(Application.persistentDataPath, "game.save");

        if (File.Exists(path))
        {
            BinaryFormatter formatter = new BinaryFormatter();
            FileStream stream = new FileStream(path, FileMode.Open);

            GameStateData data = formatter.Deserialize(stream) as GameStateData;
            stream.Close();

            // overwrite current data with loaded data
            levelProgress = data.levelProgress;
        }
    }

    public void SaveGame()
    {
        BinaryFormatter formatter = new BinaryFormatter();

        string path = Path.Combine(Application.persistentDataPath, "game.save");
        FileStream stream = new FileStream(path, FileMode.Create);

        GameStateData data = new GameStateData(this);

        formatter.Serialize(stream, data);
        stream.Close();
    }
    #endregion

    public void UpdateLevelProgress(int levelPackId, int levelId, float time)
    {
        if (!levelProgress.ContainsKey(levelPackId))
        {
            levelProgress.Add(levelPackId, new Dictionary<int, float>());
        }

        // set time
        levelProgress(levelPackId)(levelId) = time;

        // save to file
        SaveGame();
    }

}

```

mail.app – Why is Apple Mail loading remote content in Spam Messages?

For a while now, likely including and pre-Big Sur, whenever I actually go through my Spam box message-by-message, when I click on one message is initially loads with the spam bar, the off yellow bar that includes “Load Remote Content” and “Move to Inbox”, but then the message pane “refreshes” and loads like normal.

I am then reminded of this bug and annoyed, because I inevitably leaked information due to remote content loading.

I have 3 IMAP accounts, two Gmail based and then one third party IMAP that gets no meaningful traffic. If any spam is going to it I’d be surprised, but the significant majority of them are no doubt those coming to the Spam addresses I’ve had and used for over a decade now. (Insert old man yelling at cloud here.)

Why does this refresh happen? Unless I explicitly remember to click outside of a message and then ⌘a to delete them, or right click them first and use that menu to delete them, is the only way I can manage spam messages, and this means messages I’m on the fence about, but ultimately have to delete, still leak information due to the afore-described behavior.

unity – Why the scene name is never change when loading another scene?

I have two scenes. Main Menu and Game.

When running the game it’s starting with the Main Menu scene loaded. Then when making a new game the Main Menu scene is unloaded and the Game scene is loaded but even if the Game scene is loaded it keep showing the Main Menu scene in the name :

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

public class AudioManager : MonoBehaviour
{
    public GameObject gameAudio;

    private AudioSource audioSource;
    private string sceneName;
    private bool currentScene = false;

    void Awake()
    {
        DontDestroyOnLoad(transform.gameObject);
    }

    // Start is called before the first frame update
    void Start()
    {
        // Create a temporary reference to the current scene.
        Scene currentScene = SceneManager.GetActiveScene();

        // Retrieve the name of this scene.
        sceneName = currentScene.name;

        audioSource = gameAudio.GetComponent<AudioSource>();

        var mainmenumusic = GameObject.Find("Main Menu Settings");
        audioSource.volume = mainmenumusic.GetComponent<AudioSource>().volume;
    }

    // Update is called once per frame
    void Update()
    {
        if (sceneName == "Game" && currentScene == false)
        {
            audioSource.Play();
            currentScene = true;
        }
        else
        {
            if (sceneName != "Game")
            {
                audioSource.Stop();
                currentScene = false;
            }
        }
    }

    //Called when Slider is moved
    public void changeVolume(float sliderValue)
    {
        audioSource = gameAudio.GetComponent<AudioSource>();
        audioSource.volume = sliderValue;
    }
}

In the Update even if the Game scene has loaded and only the Game scene is loaded it keep showing Main Menu in the sceneName :

if (sceneName == "Game" && currentScene == false)

sceneName is never “Game”

And a side question :

Why when I press the escape key back to the main menu it keep creating the Dont Destroy On Load object over and over again ? How can I avoid it from being creating the Dont Destroy On Load all the time ? This script is in my Game scene :

using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.Audio;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

public class BackToMainMenu : MonoBehaviour
{
    public GameObject() objsToDisable;

    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            if (Time.timeScale == 0)
            {
                DisableEnableUiTexts(true);
                SceneManager.UnloadSceneAsync(0);
                Cursor.visible = false;
                Time.timeScale = 1;
            }
            else
            {
                Time.timeScale = 0;
                MenuController.LoadSceneForSavedGame = false;
                SceneManager.LoadScene(0, LoadSceneMode.Additive);
                SceneManager.sceneLoaded += SceneManager_sceneLoaded;

                Cursor.visible = true;
            }
        }
    }

    private void SceneManager_sceneLoaded(Scene arg0, LoadSceneMode arg1)
    {
        DisableEnableUiTexts(false);
    }

    private void DisableEnableUiTexts(bool enabled)
    {
        foreach (GameObject go in objsToDisable)
        {
            if (go.name == "Cameras")
            {
                foreach(Transform child in go.transform)
                {
                    if(child.name == "Main Camera")
                    {
                        if (enabled == false)
                        {
                            child.GetComponent<Camera>().enabled = false;
                        }
                        else
                        {
                            child.GetComponent<Camera>().enabled = true;
                        }
                    }
                }
            }
            else
            {
                go.SetActive(enabled);
            }
        }
    }
}

Bitcoin Core 0.21.0 Loading PSBT from file gets error: “unable to decode psbt….”

The Bitcoin Core GitHub text says to ask my question here. I also asked on reddit but maybe this is a better place.

I created a PSBT file from my online Bitcoin Core wallet. I transferred it to my offline PC to sign on that Bitcoin Core wallet but when I try to load the PSBT file into the wallet through the “Load PSBT through file…” option I immediately get the following error:

“unable to decode psbt. global unsigned tx key is more than one byte type: iostream error”

Any help would be very greatly appreciated.

If you need to know the steps I completed to get to this stage, here it is:

  1. Got my scriptPubKey and pubkey for my bitcoin address that I own and have bitcoin on and want to test my PSBT with. I used command: getaddressinfo to get this on my offline Bitcoin Core

  2. Created a new wallet on my online Bitcoin Core with “Disable private keys & blank wallet” checked off

  3. Imported the scriptPubKey and pubkey from step 1] into my online Bitcoin Core wallet. It says successful. Command used was: importmulti ‘[{“scriptPubKey” : “XXXXXXXXXXXXXXX”,”pubkeys” : [“XXXXXXXXXXXXXXX”],”timestamp” : “now”,”label” : “PSBT-test”, “watchonly”: true}]’

  4. Inputed my transaction details on the Bitcoin Core online watch-only wallet and generated the PSBT file.

java – openjfx package is installed but I still get a NoClassDefFoundError when loading any javafx class

Hello I have been trying to export my javafx application as a runnable jar file and I get a NoClassDefFoundError when my application tries to load any javafx class:

Error: Unable to initialize main class striplight.host.Main
Caused by: java.lang.NoClassDefFoundError: javafx/embed/swing/JFXPanel

I am using debian, both the openjdk-11-jdk package and the openjfx package are installed on my system.

My application works from within eclipse using javafx through gradle, I only get this error once I export the project as a runnable jar file and run it in the command prompt using java -jar

Any suggestions on what could cause all javafx classes to be unavailable like this? Again, the openjfx package is installed

Google Chrome: Specific webpages are not loading properly

I am facing this strange issue with Google Chrome. When I use google chrome to open certain web pages, I see a blurry blue page that cannot be fixed (see the following screenshot). It sometimes exist for part of a page, or certain tabs of a website.

Other web browsers are working fine. I tried to restart and re-install chrome. It didn’t work. I am using mac, with intel chip. Would be glad to know what can be the potential cause.

enter image description here

javascript – Why is my CSS file only partially loading when using window.open()

I am having an issue where I created a new window, imported my CSS, passed over my div and then I import my scripts but the new window is missing part of my CSS rules from what I can tell.

I have it set up so that on hover a tooltip shows up for the button, but in the new window the tooltip CSS rules are not applying although others are.

I have included a codesandbox.io link where I isolated the issue I am having from the rest of my page. Any help is appreciated. Thank you.

javascript – Magento 2.4 admin keep on infinite loading

I updated my magento from 2.1 to 2.4 .

My admin panel keeps on loading since long.

Below is error i see in console.

Failed to load resource: the server responded with a status of 404 (Not Found)
require.js:166 Uncaught Error: Script error for: mageTranslationDictionary
http://requirejs.org/docs/errors.html#scripterror
    at makeError (require.js:166)
    at HTMLScriptElement.onScriptError (require.js:1681)

It is calling some js file : adminhtml/Magento/backend/en_US/mageTranslationDictionary.js

which gives 404 , i can not see any such js file .

Please help me with it