ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

unity使用UniStorm插件根据当前城市动态修改天气效果

2022-01-23 17:00:49  阅读:582  来源: 互联网

标签:插件 UniStorm WeatherDataConfig weatherData 天气 System unity public


一、效果图

二、Unity接入天气

 Unity接入心知天气   https://blog.csdn.net/qq_42345116/article/details/121932488

三、UniStorm天气插件使用

1.插件下载

链接:https://pan.baidu.com/s/1QTbidZcgKEqnSsP3_mG5wA 
提取码:syq1

下载完直接导入Unity就好

2.下面的连接,可以简单了解面板的各参数使用

https://www.cnblogs.com/forever-Ys/p/13492008.html

https://blog.csdn.net/qq_55117297/article/details/121355376

不了解也没关系,下面简单教大家如何实现上面的效果

四、效果实现 

1.创建一个UniStorm System

 

2.修改UniStorm System 属性

 3.UniStorm System自带的天气 对照表

/*      插件天气对照表
    0   Clear				 		//清除 万里无云        
    1   Mostly Clear		 		//晴时多云              
    2   Mostly Cloudy	    		//大部多云              
    3   Partly Cloudy				//局部多云;少云         
    4   Cloudy						//阴天的		
    5   Lightning Bugs			    //萤火虫
    6   Blowing Pollen			    //吹花粉
    7   Blowing Leaves			    //吹树叶
    8   Blowing Pine Needles 	    //吹松针
    9   Blowing Snow				//高吹雪,飞雪
    10  Foggy						//有雾的
    11  Overcast					//阴天的
    12  Hail						//下冰雹
    13  Heavy Rain					//大暴雨
    14  Rain						//雨
    15  Light Rain					//小雨
    16  Drizzle					    //下毛毛雨
    17  Heavy Snow					//大雪
    18  Snow						//雪
    19  Light Snow					//小雪
    20  Thunderstorm				//雷雨
    21  Thunder Snow				//雷阵雨
    22  Dust Storm					//尘暴
    23  Fire Rain					//火雨
    24  Fire Storm					//(原子爆炸等引起的)风暴性大火
 */

调用 UniStormSystem.Instance.AllWeatherTypes[下标] (天气List)可以获取对应天气

然后使用 UniStormManager.Instance.ChangeWeatherInstantly(WeatherType) 切换天气

public void SetWeather() 
{

   WeatherType weather = UniStormSystem.Instance.AllWeatherTypes[0]; 
   Debug.Log(weather.WeatherTypeName); //打印天气的名称

   //两种切换效果
   //UniStormManager.Instance.ChangeWeatherWithTransition(weather); //过渡切换 
   UniStormManager.Instance.ChangeWeatherInstantly(weather); //直接切换
}

4.现当地天气和插件的天气切换都搞定了,现在我们要根据当地天气配置对应的插件天气了,怎么做呢?

新建一个WeatherData.cs数据类,这里存放当地天气和对应的插件天气下标

using System;

[Serializable]
public class WeatherData
{
    public string weatherName; //当地天气 
    public int uniStormWeatherIndex; //插件天气下标
}

我们创建WeatherDataConfig继承ScriptableObject(继承这个的子类,可以当成基础数据使用)

using System.Collections.Generic;
using UnityEngine;

//这个表示 我们右键文件夹 Create/DataConfig/WeatherDataConfig 可以生成一个文件为WeatherDataConfig数据文件,我们的数据配置就是在这个文件下
[CreateAssetMenu(menuName = "DataConfig/WeatherDataConfig", fileName = "WeatherDataConfig")]
public class WeatherDataConfig : ScriptableObject
{
    public List<WeatherData> weatherData;
}

这两个脚本创建完后,右键创建一个WeatherDataConfig数据文件,如下图

 

数据配置 

根据心知天气返回的所有天气和UniStorm System自带的天气 对照表进行配置

5.数据配置完毕 ,我们写一个 切换天气的脚本

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

//天气切换
public class ChangeWeather : MonoBehaviour
{

    [SerializeField] WeatherDataConfig weatherData; //天气数据 我们配置的文件拖入即可


    //单例
    static ChangeWeather instance;
    public static ChangeWeather GetInstacne() 
    {
        return instance;
    }

    void Awake() 
    {
        instance = this;
    }

    void Start()
    {
    }

    public void SetWeather(string weatherName) 
    {
        //根据传过来的天气名称找到对应的插件天气下标
        int index = 0;
        for (int i = 0; i < weatherData.weatherData.Count; i++)
        {
            //名称相同 获取天气下标
            if (weatherData.weatherData[i].weatherName.Equals(weatherName))
            {
                index = weatherData.weatherData[i].uniStormWeatherIndex;
                break;
            }
        }
        
        //根据插件天气下标,获取天气
        WeatherType weather = UniStormSystem.Instance.AllWeatherTypes[index];
        Debug.Log(weather.WeatherTypeName);

        //UniStormManager.Instance.ChangeWeatherWithTransition(weather); //过度切换
        UniStormManager.Instance.ChangeWeatherInstantly(weather); //直接切换
    }
}

6.回到第二步接入天气所创建的脚本,CityWeather.cs

 7.新建空物体CityWeather,布局如下

ok,效果完成。 

标签:插件,UniStorm,WeatherDataConfig,weatherData,天气,System,unity,public
来源: https://blog.csdn.net/qq_42345116/article/details/122652578

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有