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.
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.
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);
}
}
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
}
}
@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.
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!
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.
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.
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.
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.