[Unity3D]呼风唤雨:天气插件UniSky的使用教程与案例

UniSky是Unity3D的一款模拟环境天气的插件,使用它可以简单的实现呼风唤雨的各种功能。

下载地址:请点击我

使用起来也非常的方便。

引入Package后(注意路径必须是英文否则会出错)Project中会多一个文件夹:

下面我们来简单的创建一个下雨的场景。

首先从UniSky中拖动UniSkyAPI到Hierachy面板:

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

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


这个脚本的源码如下:

using UnityEngine;
using System.Collections;

public class ExampleScript : MonoBehaviour {

	// instance of the API
	private UniSkyAPI uniSky;
	
	void Awake() {
		
		// Define instance
		uniSky = GameObject.Find("UniSkyAPI").GetComponent("UniSkyAPI") as UniSkyAPI;
		
		// Initiate and create default UniSky 
		uniSky.InstantiateUniSky();
		// Set some initial states 
		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);
		
		// Functions to interpolate parameters over time
		/*
		uniSky.LerpCloudCover(0.5f, 5000.0f);
		uniSky.LerpPrecipitationLevel(0.6f, 5000.0f);
		uniSky.LerpStormCloudCover(-1.0f, 10000.0f);
		uniSky.LerpRainLevel(100, 0.2f, 10000.0f);
		uniSky.LerpStormLevel(150, 0.4f, 20000.0f);
		uniSky.LerpSunIntensity(0.2f, 10000.0f);
		uniSky.LerpFogLevel(0.02f, 20000.0f);
		uniSky.LerpAmbientLighting(new Color(0.0f, 0.0f, 0.0f, 0.0f), 5000);
		uniSky.ClearDropletBuffer();
		uniSky.LerpDropletLevel(10, 20000.0f);
		*/
	}

	void Update() {

	}
}

以下是对于插件API函数的简要解释:

API函数/参数
下面是对UniSky参数的介绍,并且都对其进行了效果解释。下面的列表可以再UniSkyAPI.js/cs中找到。
//一天的时间(0到24小时循环)
SetTime(float time);
LerpTime(float time, float milliseconds);
GetTime();



//返回太阳的颜色
GetSunColor();
//启用或禁用太阳和月亮的阴影。类型: "LightShadows.None" 、"LightShadows.Hard"和 "LightShadows.Soft"
public void SetSunShadows(LightShadows sunShadows)
public void SetMoonShadows(LightShadows moonShadows)

 
//设置暴风雨云层中心的坐标
SetStormCenter(Vector3 stormCenter);

 
//散射半径,他影响着天空的颜色(默认是45000,通常情况下是一个真实的天空)
SetScatteringRadius(float scatteringRadius);
LerpScatteringRadius(float scatteringRadius, float milliseconds);

 
//主大气层的覆盖是(-5到5)
void SetCloudCover(float cloudCover);
LerpCloudCover(float cloudCover, float milliseconds);

 
//黑暗的云层,不是暴风雨的大气层。(2-0,越低,云层颜色越深)
SetPrecipitationLevel(float precipitationLevel);
LerpPrecipitationLevel(float precipitationLevel, float milliseconds);

 
//暴风雨的覆盖层级是(建议是-3.5到-1.0)
SetStormCloudCover(float cloudCover);
LerpStormCloudCover(float cloudCover, float milliseconds);

 
//雨的数量。没有大暴雨的,但是都是小雨。(任何地方都是从0-1000)
SetRainLevel(float rainLevel, float sfxLevel);
LerpRainLevel(float rainLevel, float sfxLevel, float milliseconds);
 
//特大暴雨。一片都有雨。(任何地方都是从0-200)
SetStormLevel(float stormLevel, float sfxLevel);
LerpStormLevel(float stormLevel, float sfxLevel, float milliseconds);
 
//太阳的亮度或浓度。由于黑暗中阴天或暴风雨天(0到0.5)淡入淡出
SetSunIntensity(float intensity);
LerpSunIntensity(float intensity, float milliseconds);
 
//设置内置雾(0到0.03)
SetFogLevel(float fogLevel);
LerpFogLevel(float fogLevel, float milliseconds);

 
//设置屏幕图像上滴落的速率(0到5)
SetDropletLevel(float dropletLevel);
LerpDropletLevel(float dropletLevel, float milliseconds);



//设置云的方向,加速度和演化的速度。X=x方向和加速度,Y=y方向和加速度,Z=演化速度(0到1)
SetCloudSpeedDirection(Vector3 speedDirection);
LerpCloudSpeedDirection(Vector3 speedDirection, float milliseconds);
//光晕差异。设置云边缘的照明强度(0到10)。提示:设置为0左右,会有一个很好的卷云效果。
SetGlowVariance(float glowVariance);
LerpGlowVariance(float glowVariance, float milliseconds);
 
//设置云褪色到大气中的距离(0到20)
SetViewDistance(float viewDistance);
LerpViewDistance(float viewDistance, float milliseconds);
 
//调节默认颜色。建议RGB的默认值(1.5,1.5,1.5)。如果你想要粉红色或绿色的云:D
SetColorVariance(Vector3 colorVariance);
LerpColorVariance(Vector3 colorVariance, milliseconds);

//如果你想时间自动循环,这个是时间流逝的速度。(0到0.1)
SetSpeedOfTime(float speedOfTime);



//改变光散射到云中,只影响云的颜色。最好是保持他的默认值,40.(-20到100)
SetRayleighLevel(float rayleighLevel);
//如果启用该选项,一天中时间的播放器与系统时钟同步。
SetUseSystemTime(bool enabled);

 
//改变环境光的颜色。我建议在一天的时间内进行插值或混浊。
SetAmbientLighting(Color ambientLevel);
LerpAmbientLighting(Color ambientLevel, float milliseconds);

 
//设置月亮的大小
SetMoonSize(float moonSize);
 
//清除雾滴缓存
ClearDropletBuffer();
 
//设置打雷闪电的频率。越高越频繁(0到100)。
SetLightningFrequency(float
frequency);

此时点击运行,便会发现UniSky已经基本成型了:



当然想过不是很理想,因为没有地面。。

如果需要下雨的效果,只需要加上这么一行代码:

uniSky.SetStormLevel(1000,1000);
或者是:

uniSky.SetRainLevel(1000,1000);

就可以实现了:

完整的学习案例还是参照插件中自带的案例UniSky Example Scene,效果非常好:

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

评论 12
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值