这里用的UniStorm版本是2.1
因为在unity中可以很方便的调节时间和天气,所以在一些不大的项目当中经常用到
开始一般使用可以用window菜单UniStorm里面创建对应的
一般会创建这个(我这里用的是c#版本),
当然创建了也可以手动进行修正,比如你要换个摄像机
可以把里面的player禁用掉,还有记得一定要把摄像机的远切平面调大,貌似要30000以上,不然远处的云和星空将被切掉,然后不可见
然后把上面的滤镜都搬到自己的摄像机上,这样差不多就完成了手动迁移
另外如果需要下雨之类的效果,还需要自己扩大区域,默认是在player周围的
还有要注意的就是运行才能看到效果,为了防止效果影响在window-lighting里面最好把skybox去掉,然后把上面截图里的Sun_Moon拖到Sun里面就好了
UniStorm的总控调节参数可以看UniStormSystemEditor这个物体,上面有很多参数调节
包括了昼夜分别的长度和起始时间,云的密度等等很多东西
但是没有提供代码控制,所以还是有不方便的地方
所以自己找来显示时间和控制时间的方式
下面是查到的显示时间的方式(需要自己建立一个canvas并有4个text组件拖上去)
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class myUniStormControlTime : MonoBehaviour {
UniStormWeatherSystem_C uniStormSystem;
GameObject uniStormObject;
public bool use12hourclock = false;
public Text ClockText;
public Text DateText;
public Text WeatherText;
public Text TempText;
// Use this for initialization
void Start()
{
uniStormObject = GameObject.Find("UniStormSystemEditor");
uniStormSystem = uniStormObject.GetComponent<UniStormWeatherSystem_C>();
}
void Update()
{
if (!use12hourclock)
{
ClockText.text = "Current Time:" + "\n" + uniStormSystem.hourCounter.ToString() + ":" + uniStormSystem.minuteCounter.ToString("00");
}
if (use12hourclock)
{
if (uniStormSystem.hourCounter <= 12)
{
ClockText.text = "Current Time:" + "\n" + uniStormSystem.hourCounter.ToString() + ":" + uniStormSystem.minuteCounter.ToString("00") + " AM";
}
if (uniStormSystem.hourCounter >= 13)
{
ClockText.text = "Current Time:" + "\n" + ((int)uniStormSystem.hourCounter - 12) + ":" + uniStormSystem.minuteCounter.ToString("00") + " PM";
}
}
DateText.text = "Date:" + "\n" + uniStormSystem.monthCounter.ToString() + "/" + uniStormSystem.dayCounter.ToString() + "/" + uniStormSystem.yearCounter.ToString();
WeatherText.text = "Current Weather:" + "\n" + uniStormSystem.weatherString.ToString();
TempText.text = "Current Temperature:" + "\n" + uniStormSystem.temperature.ToString() + "°";
}
}
显示效果如下
下面还有就是控制时间
using UnityEngine;
using System.Collections;
public class StartingHour : MonoBehaviour
{
public GameObject uniStormSystem;
public int startingHour = 8;
public float getDayLength;
public bool startingHourReached = false;
void Awake()
{
//uniStormSystem = GameObject.Find("UniStormPrefab_C/UniStormSystemEditor"); //Get our UniStorm Weather System gameObject
getDayLength = uniStormSystem.GetComponent<UniStormWeatherSystem_C>().dayLength;
}
void Start()
{
uniStormSystem.GetComponent<UniStormWeatherSystem_C>().dayLength = 0.2f; //Sets our dayLength fast to calculate the proper time on start
//Sets our time variables
uniStormSystem.GetComponent<UniStormWeatherSystem_C>().dayCounter = 1;
uniStormSystem.GetComponent<UniStormWeatherSystem_C>().monthCounter = 1;
uniStormSystem.GetComponent<UniStormWeatherSystem_C>().yearCounter = 2015;
//uniStormSystem.GetComponent<UniStormWeatherSystem_C>().weatherForecaster = 1; //Changes the weather to foggy
uniStormSystem.GetComponent<UniStormWeatherSystem_C>().fader = 1; //Fades in clouds instantly
}
void Update()
{
if (Input.GetKeyDown(KeyCode.W))
{//这里是控制时间的
uniStormSystem.GetComponent<UniStormWeatherSystem_C>().startTime +=0.1f;
}
if (startingHourReached == false)
{
//niStormSystem.GetComponent<UniStormWeatherSystem_C>().lightFlareObject.light.intensity = 0; //Fades out our sun glare instantly
uniStormSystem.GetComponent<UniStormWeatherSystem_C>().lightningShadowIntensity = 0; //Fades out our sun glare instantly
}
//After everything is set disable by setting startingHourReachedTo true
if (uniStormSystem.GetComponent<UniStormWeatherSystem_C>().hourCounter == startingHour && startingHourReached == false)
{
startingHourReached = true;
uniStormSystem.GetComponent<UniStormWeatherSystem_C>().dayLength = getDayLength;
uniStormSystem.GetComponent<UniStormWeatherSystem_C>().startTime = 0.2333f;
}
}
}
按w可以跳转时间,这里一天长度是1,可以根据24小时自己算
然后就能调节时间了
当然里面还能调节天气之类的
参考地址
http://unistorm-weather-system.wikia.com/wiki/Code_References
https://forum.unity3d.com/threads/unistorm-dynamic-day-night-weather-system-released-now-includes-unistorm-mobile-free.121021/page-48
http://unistorm-weather-system.wikia.com/wiki/Documentation
http://unistorm-weather-system.wikia.com/wiki/Tutorials