[RELEASED] UniStorm 5.2 - AAA Volumetric Clouds, URP Support, Weather, Sky, Atmospheric Fog, & More!

What I tried was adding an empty object to my scene, which has a persistable object script from Plygame on it. Then I add this script which I wrote which in theory should save the information I want, but it is not working. I have tried about 25 different ways but I am not getting anywhere.

3337324–260431–UnistormSave.cs (2.25 KB)

Is Unistorm supports WAPI ?
http://www.procedural-worlds.com/blog/wapi/

That’s what I am planning on too. I am using ootii’s Third Person Motion Controller with his Camera controller. I still have to wire up the transition between 1st and 3rd as well though.

1 Like

Refer to UniStorm’s save and load example below. There is API that will help with setting the date, time, and weather.

//Black Horizon Studios
//UniStormSystem Save Example

using UnityEngine;
using System.Collections;

public class SavePlayerData_C : MonoBehaviour {

    Vector3 playerPosition;
    Vector3 playerRotation;
    UniStormWeatherSystem_C UniStormSystem;
    int currentHour;
    Vector3 rotationToSet;

    void Start ()
    {
        UniStormSystem = GameObject.Find("UniStormSystemEditor").GetComponent<UniStormWeatherSystem_C>();
    }
  

    void Update ()
    {
        if(Input.GetKeyDown(KeyCode.O))
        {
            PlayerPrefs.SetInt("Current Minute", UniStormSystem.minuteCounter);

            PlayerPrefs.SetInt("Current Hour", UniStormSystem.hourCounter);

            PlayerPrefs.SetInt("Current Weather", UniStormSystem.weatherForecaster);
            PlayerPrefs.SetInt("Current Day", UniStormSystem.dayCounter);
            PlayerPrefs.SetInt("Current Month", UniStormSystem.monthCounter);
            PlayerPrefs.SetInt("Current Year", UniStormSystem.yearCounter);
            PlayerPrefs.SetInt("Current Temperature", UniStormSystem.temperature);

            playerPosition = transform.position;
            playerRotation = transform.rotation.eulerAngles;

            PlayerPrefs.SetFloat("Player Position X", playerPosition.x);
            PlayerPrefs.SetFloat("Player Position Y", playerPosition.y);
            PlayerPrefs.SetFloat("Player Position Z", playerPosition.z);

            PlayerPrefs.SetFloat("Player Rotation X", playerRotation.x);
            PlayerPrefs.SetFloat("Player Rotation Y", playerRotation.y);
            PlayerPrefs.SetFloat("Player Rotation Z", playerRotation.z);

            Debug.Log("Game Saved" + "\n" + " In-Game Time " + UniStormSystem.hourCounter + ":" + UniStormSystem.minuteCounter + " | "  + " In-Game Date " + UniStormSystem.monthCounter + "/" + UniStormSystem.dayCounter + "/" + UniStormSystem.yearCounter + " |  Current Weather " + UniStormSystem.weatherString + " | Current Temperature " + UniStormSystem.temperature);
        }

        if(Input.GetKeyDown(KeyCode.L))
        {
            UniStormSystem.SetDateAndTime(PlayerPrefs.GetInt("Current Hour"), PlayerPrefs.GetInt("Current Minute"), PlayerPrefs.GetInt("Current Month"), PlayerPrefs.GetInt("Current Day"), PlayerPrefs.GetInt("Current Year"));
            UniStormSystem.ChangeWeather(PlayerPrefs.GetInt("Current Weather"));
            UniStormSystem.temperature = PlayerPrefs.GetInt ("Current Temperature");

            playerPosition.x = PlayerPrefs.GetFloat("Player Position X");
            playerPosition.y = PlayerPrefs.GetFloat("Player Position Y");
            playerPosition.z = PlayerPrefs.GetFloat("Player Position Z");

            playerRotation.x = PlayerPrefs.GetFloat("Player Rotation X");
            playerRotation.y = PlayerPrefs.GetFloat("Player Rotation Y");
            playerRotation.z = PlayerPrefs.GetFloat("Player Rotation Z");

            UniStormSystem.InstantWeather();

            transform.position = new Vector3 (playerPosition.x, playerPosition.y, playerPosition.z);

            rotationToSet = new Vector3 (playerRotation.x, playerRotation.y, playerRotation.z);
            transform.eulerAngles = rotationToSet;

            Debug.Log("Game Loaded");

        }
    }
}

Users can use WAPI to write custom scripts. However, it is not currently integrated with UniStorm. I have plans to do this with the next update as I have done with CTS.

When switching cameras, you will also need to update the position UniStorm’s particle effects. Feel free to use this script I wrote a little while back for another custom to accomplish this.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SwitchForms : MonoBehaviour {

    UniStormWeatherSystem_C UniStormSystem;

    //Get the UniStorm system
    void Start (){
        UniStormSystem = FindObjectOfType <UniStormWeatherSystem_C>();
    }

    ///When switching to the human form, move all particle effects over using the HumanFormObject.
    ///This can be set by sending the object as a parameter
    public void HumanForm (GameObject HumanFormObject){
        //Set the Rain to the human object
        UniStormSystem.rain.transform.SetParent (HumanFormObject.transform);
        UniStormSystem.rain.transform.position = new Vector3 (0,12,0);
        //Set Snow to the human object
        UniStormSystem.snow.transform.SetParent (HumanFormObject.transform);
        UniStormSystem.snow.transform.position = new Vector3 (0,12,0);
        //Set the Windy Leaves to the human object
        UniStormSystem.windyLeaves.transform.SetParent (HumanFormObject.transform);
        UniStormSystem.windyLeaves.transform.position = new Vector3 (0,12,0);
        //Set Lightning Bugs (aka Butterflies) to the human object
        UniStormSystem.butterflies.transform.SetParent (HumanFormObject.transform);
        UniStormSystem.butterflies.transform.position = new Vector3 (0,12,0);
        //Set Rain Mist to the human object
        UniStormSystem.rainMist.transform.SetParent (HumanFormObject.transform);
        UniStormSystem.rainMist.transform.position = new Vector3 (0,12,0);
        //Set Snow to the human object
        UniStormSystem.snowMistFog.transform.SetParent (HumanFormObject.transform);
        UniStormSystem.snowMistFog.transform.position = new Vector3 (0,12,0);
    }

    //When switching to the bird form, move all particle effects over using the BirdFormObject.
    //This can be set by sending the object as a parameter
    public void BirdForm (GameObject BirdFormObject){
        //Set the Rain to the bird object
        UniStormSystem.rain.transform.SetParent (BirdFormObject.transform);
        UniStormSystem.rain.transform.position = new Vector3 (0,12,0);
        //Set Snow to the bird object
        UniStormSystem.snow.transform.SetParent (BirdFormObject.transform);
        UniStormSystem.snow.transform.position = new Vector3 (0,12,0);
        //Set the Windy Leaves to the bird object
        UniStormSystem.windyLeaves.transform.SetParent (BirdFormObject.transform);
        UniStormSystem.windyLeaves.transform.position = new Vector3 (0,12,0);
        //Set Lightning Bugs (aka Butterflies) to the bird object
        UniStormSystem.butterflies.transform.SetParent (BirdFormObject.transform);
        UniStormSystem.butterflies.transform.position = new Vector3 (0,12,0);
        //Set Rain Mist to the bird object
        UniStormSystem.rainMist.transform.SetParent (BirdFormObject.transform);
        UniStormSystem.rainMist.transform.position = new Vector3 (0,12,0);
        //Set Snow to the bird object
        UniStormSystem.snowMistFog.transform.SetParent (BirdFormObject.transform);
        UniStormSystem.snowMistFog.transform.position = new Vector3 (0,12,0);
    }
}
1 Like

The script I wrote is based on your script. Plygame already saves the player position, so I took that out of the script. Like I said, in some attempts I tried I could get it to save the data, but if I had three saves, all of them would have the weather from the last save. I am not a good enough programmer to figure this out.

I see that the script you wrote is close to the save and load example that is included with UniStorm. However, you aren’t using some of the API that save and load example uses. I believe this is where your issue lies. You cannot set the date and time directly. You need to use UniStorm’s API.

Below, I have modified your save script. I don’t have the plyGame API, but I’m fairly certain this will work.

using UnityEngine;
using System.Collections;
using plyGame;

public class UnistormSave : MonoBehaviour, IPersistable
{
    uniStormWeatherSystem_C uniStormSystem;

    int currentHour;
    void Start ()
    {
        uniStormSystem = GameObject.Find("UniStormSystemEditor").GetComponent<UniStormWeatherSystem_C>();
    }

    public void Save(string key)
    {     
        key = key + ".unistorm";
        GameGlobal.SetIntKey(key + ".Current Minute", uniStormSystem.minuteCounter);
        GameGlobal.SetIntKey(key + ".Current Hour", uniStormSystem.hourCounter);
        GameGlobal.SetIntKey(key + ".Current Weather", uniStormSystem.weatherForecaster);
        GameGlobal.SetIntKey(key + ".Current Day", uniStormSystem.dayCounter);
        GameGlobal.SetIntKey(key + ".Current Month", uniStormSystem.monthCounter);
        GameGlobal.SetIntKey(key + ".Current Year", uniStormSystem.yearCounter);
        GameGlobal.SetIntKey(key + ".Current Temperature", uniStormSystem.temperature);
    }

    public void Load(string key)
    {             
        key = key + ".unistorm";
        //These are not needed because you cannot set the time and date directly.
        //uniStormSystem.minuteCounter = GameGlobal.GetIntKey(key + ".Current Minute", uniStormSystem.minuteCounter);
        //uniStormSystem.hourCounter = GameGlobal.GetIntKey(key + ".Current Hour", uniStormSystem.hourCounter);
        //uniStormSystem.dayCounter = GameGlobal.GetIntKey(key + ".Current Day", uniStormSystem.dayCounter);
        //uniStormSystem.monthCounter = GameGlobal.GetIntKey(key + ".Current Month", uniStormSystem.monthCounter);
        //uniStormSystem.yearCounter = GameGlobal.GetIntKey(key + ".Current Year", uniStormSystem.yearCounter);

        //Instead, set the time and date using the UniStorm SetTimeAndDate function. More is required to set the time and date than just setting the variables directly.
        //The SetTimeAndDate function does this automatically.
        uniStormSystem.SetDateAndTime(GameGlobal.GetIntKey(key + ".Current Hour", uniStormSystem.hourCounter), GameGlobal.GetIntKey(key + ".Current Minute", uniStormSystem.minuteCounter),
            GameGlobal.GetIntKey(key + ".Current Month", uniStormSystem.monthCounter), GameGlobal.GetIntKey(key + ".Current Day", uniStormSystem.dayCounter),
            GameGlobal.GetIntKey(key + ".Current Year", uniStormSystem.yearCounter));
 
        uniStormSystem.weatherForecaster = GameGlobal.GetIntKey(key + ".Current Weather", uniStormSystem.weatherForecaster);
     
        uniStormSystem.temperature = GameGlobal.GetIntKey(key + ".Current Temperature", uniStormSystem.temperature);

        //After the saved weather has been loaded, InstantWeather is needed to instantly fade it in.
        uniStormSystem.InstantWeather();
    }

    public void DeleteSaveData(string key)
    {
        key = key + ".unistorm";
        GameGlobal.DeleteKey(key + ".Current Minute");
        GameGlobal.DeleteKey(key + ".Current Hour");
        GameGlobal.DeleteKey(key + ".Current Weather");
        GameGlobal.DeleteKey(key + ".Current Day");
        GameGlobal.DeleteKey(key + ".Current Month");
        GameGlobal.DeleteKey(key + ".Current Year");
        GameGlobal.DeleteKey(key + ".Current Temperature");
    }

    public void DisablePersistence()
    {
        // Ignore
    }
}

I am getting this error.

And thank you for helping with this! It is much appreciated.

3340230--260745--30.png

@BHS Seems that the saving and loading isn’t really working as intended. We are saving by storing the current Hour (unistorm.Hour) as an int and the minute (unistorm.Minute). However, using SetTime() is not working, and UniStorm reverts to the default start time. I’ve have tried this in Awake(), Start() and after Start() and none of these are working. Could you either tell me what I’m doing wrong here or push a fix?

OK, all I had to do was change the “U” in UniStorm to a small letter. It is working perfectly. I will put up a guide in the plyGame forums so that if anyone else needs to integrate Unistorm with PlyGame they can use that.

Thanks again for the help.

Hey there!

Because UniStorm calculates everything on start, you may need to add a slight 0.1 second delay before you load your saved UniStorm time. It is most likely being rewritten by UniStorm’s initialization function.

You’re welcome.

Great to hear everything is working correctly. That would be great, thanks!

1 Like

I’m afraid your solution didn’t work - I waited 10 frames, 0.1 seconds and 1 second and it doesn’t appear to be working.

Strange. How exactly are you saving and loading? Have you tried the example saving and loading scenes to see if they are working correctly? There is one manual save example and an auto save example.

The saving example uses the old loading methods which are now depreciated.
Our saving code:

BinaryFormatter formatter = new BinaryFormatter();
            FileStream stream = new FileStream(ServerConfiguration.ServerPath + "/world.savedata", FileMode.OpenOrCreate);
            System.DateTime currentTime = uniStorm.GetDate();
            WorldSaveData saveData = new WorldSaveData()
            {
                currentMinute = currentTime.Minute,
                currentHour = currentTime.Hour,
                currentDay = currentTime.Day,
                currentMonth = currentTime.Month,
                currentYear = currentTime.Year,

                currentTemperature = uniStorm.temperature,
                currentWeather = uniStorm.weatherForecaster
            };
            formatter.Serialize(stream, saveData);
            stream.Close();

Our loading code (this is called via Start()):

if (File.Exists(ServerConfiguration.ServerPath + "/world.savedata"))
            {
                WorldSaveData data = new WorldSaveData();
                BinaryFormatter formatter = new BinaryFormatter();
                FileStream fileStream = new FileStream(ServerConfiguration.ServerPath + "/world.savedata", FileMode.Open);
                data = formatter.Deserialize(fileStream) as WorldSaveData;
                fileStream.Close();

                uniStorm.ChangeWeather(data.currentWeather);
                uniStorm.temperature = data.currentTemperature;


                uniStorm.SetDateAndTime(data.currentHour, data.currentMinute, data.currentMonth, data.currentDay, data.currentYear);
                Debug.Log("[Saving] Successfully Loaded World Settings");
            }

The temperature and weather load fine, just not the hours and minutes.

There used to be a tutorial for working with multiple cameras, but I can’t find it. Anyone have a link?

I’ll look into this to see what’s causing the issue. When using PlayerPrefs, everything works as it’s supposed to.

Hey there!

The process for using two cameras changed so the guide was removed. You basically have 1 camera render your scene and the other camera render UniStorm. This is done by using layers. A new example scene was added that demonstrates using two cameras.

1 Like

OK. My game is a third person game. What I am trying to do is when my player interacts with an NPC (when he talks to them) it must switch to a first person camera, and when the interaction stops, it must switch back to a third person camera.

What is happening is when the camera switches back to third person, it is playing a sound from my footsteps script through the Unistorm audio source.

I will have a look at the example scene and see if I can get this sorted out.

Hi,

First, the example scene for the two cameras is filled with errors, scripts that can’t be loaded, etc.

But that is not going to sort out my problem even it worked. The audio source is still on the player, and my footsteps script is conflicting with that. I need to find a way to make the footsteps script audio player and the Unistorm audio player not both be on the player.

Why switch cameras? Personally, I’d just move the camera, then move it back.

It is a third person camera. If I zoom in on the interaction, it passes through the players head, which looks a bit odd.

I also tried adjusting the zoom distance with a script, but that didn’t work properly either.

Volumetric Lighting ??