一些游戏场景需要用到天气变化,这就要借助UniSky这款插件,UniSky是Unity3D的一款模拟环境天气的插件,使用它可以简单的实现呼风唤雨的各种功能。
使用起来也非常的方便。
引入Package后(注意路径必须是英文否则会出错)Project中会多一个文件夹:

下面我们来简单的创建一个下雨的场景。
首先从UniSky中拖动UniSkyAPI到Hierachy面板:

然后再把Camara与API建立连接:

接下来创建一个空的GameObject用来控制UniSkyAPI,并将脚本ExampleScript拖到它身上:

这个脚本的源码如下:
- using UnityEngine;
- using System.Collections;
-
- public class ExampleScript : MonoBehaviour {
-
-
- private UniSkyAPI uniSky;
-
- void Awake() {
-
-
- uniSky = GameObject.Find("UniSkyAPI").GetComponent("UniSkyAPI") as UniSkyAPI;
-
-
- uniSky.InstantiateUniSky();
-
- uniSky.SetTime(12.0f);
- uniSky.SetAmbientLighting(new Color(0.1f, 0.1f, 0.1f, 0.1f));
- uniSky.SetStormCenter(new Vector3(0,0,0));
- uniSky.SetSunShadows(LightShadows.Soft);
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- }
-
- void Update() {
-
- }
- }
以下是对于插件API函数的简要解释:- API函数/参数
- 下面是对UniSky参数的介绍,并且都对其进行了效果解释。下面的列表可以再UniSkyAPI.js/cs中找到。
-
- SetTime(float time);
- LerpTime(float time, float milliseconds);
- GetTime();
-
-
-
-
- GetSunColor();
-
- public void SetSunShadows(LightShadows sunShadows)
- public void SetMoonShadows(LightShadows moonShadows)
-
-
-
- SetStormCenter(Vector3 stormCenter);
-
-
-
- SetScatteringRadius(float scatteringRadius);
- LerpScatteringRadius(float scatteringRadius, float milliseconds);
-
-
-
- void SetCloudCover(float cloudCover);
- LerpCloudCover(float cloudCover, float milliseconds);
-
-
-
- SetPrecipitationLevel(float precipitationLevel);
- LerpPrecipitationLevel(float precipitationLevel, float milliseconds);
-
-
-
- SetStormCloudCover(float cloudCover);
- LerpStormCloudCover(float cloudCover, float milliseconds);
-
-
-
- SetRainLevel(float rainLevel, float sfxLevel);
- LerpRainLevel(float rainLevel, float sfxLevel, float milliseconds);
-
-
- SetStormLevel(float stormLevel, float sfxLevel);
- LerpStormLevel(float stormLevel, float sfxLevel, float milliseconds);
-
-
- SetSunIntensity(float intensity);
- LerpSunIntensity(float intensity, float milliseconds);
-
-
- SetFogLevel(float fogLevel);
- LerpFogLevel(float fogLevel, float milliseconds);
-
-
-
- SetDropletLevel(float dropletLevel);
- LerpDropletLevel(float dropletLevel, float milliseconds);
-
-
-
-
- SetCloudSpeedDirection(Vector3 speedDirection);
- LerpCloudSpeedDirection(Vector3 speedDirection, float milliseconds);
-
- SetGlowVariance(float glowVariance);
- LerpGlowVariance(float glowVariance, float milliseconds);
-
-
- SetViewDistance(float viewDistance);
- LerpViewDistance(float viewDistance, float milliseconds);
-
-
- SetColorVariance(Vector3 colorVariance);
- LerpColorVariance(Vector3 colorVariance, milliseconds);
-
-
- SetSpeedOfTime(float speedOfTime);
-
-
-
-
- SetRayleighLevel(float rayleighLevel);
-
- SetUseSystemTime(bool enabled);
-
-
-
- SetAmbientLighting(Color ambientLevel);
- LerpAmbientLighting(Color ambientLevel, float milliseconds);
-
-
-
- SetMoonSize(float moonSize);
-
-
- ClearDropletBuffer();
-
-
- SetLightningFrequency(float
- frequency);
此时点击运行,便会发现UniSky已经基本成型了:
当然想过不是很理想,因为没有地面。。
如果需要下雨的效果,只需要加上这么一行代码:
- uniSky.SetStormLevel(1000,1000);
或者是:- uniSky.SetRainLevel(1000,1000);
就可以实现了:
完整的学习案例还是参照插件中自带的案例UniSky Example Scene,效果非常好:

当然啦,如果只是要简单的下雨特效,推荐这款插件:Rain.package