zoukankan      html  css  js  c++  java
  • Unity3D动态天空之UniSky

    找工作时一家公司时给我出的题目,去uniSky官网看了看快速入门就做了出来,时间自动流逝,并且可以手动设置时间段以及相应的天气效果,直接上代码,要.package的留邮箱啊,我在博客园找不到上传的地方

     1 /// <summary>
     2 /// 天气状态
     3 /// </summary>
     4 public enum WeatherState
     5 {
     6     /// <summary>
     7     /// 晴天
     8     /// </summary>
     9     SUNNY_DAY,
    10 
    11     /// <summary>
    12     /// 雨天
    13     /// </summary>
    14     RAINY_DAY,
    15 
    16     /// <summary>
    17     /// 雪天
    18     /// </summary>
    19     SNOWY_DAY,
    20 
    21     /// <summary>
    22     /// 雾天
    23     /// </summary>
    24     FOGGY_DAY,
    25 
    26     /// <summary>
    27     /// 阴天
    28     /// </summary>
    29     CLOUD_DAY
    30 }
    天气状态
     1 /// <summary>
     2 /// 时间状态
     3 /// </summary>
     4 public enum TimeState
     5 {
     6     /// <summary>
     7     /// 早晨
     8     /// </summary>
     9     MORNING,
    10     
    11     /// <summary>
    12     /// 上午
    13     /// </summary>
    14     AM,
    15 
    16     /// <summary>
    17     /// 中午
    18     /// </summary>
    19     NOONING,
    20 
    21     /// <summary>
    22     /// 下午
    23     /// </summary>
    24     PM,
    25 
    26     /// <summary>
    27     /// 傍晚
    28     /// </summary>
    29     DUSK,
    30 
    31     /// <summary>
    32     /// 夜晚
    33     /// </summary>
    34     NIGHT
    35 }
    时间状态
      1 using UnityEngine;
      2 using System.Collections;
      3 
      4 public class SkyController : MonoBehaviour 
      5 {
      6     //导入UniSky插件
      7     private UniSkyAPI uniSky;
      8 
      9     //存储当前时间状态
     10     private TimeState nowTime; 
     11     //存储当前天气状态
     12     private WeatherState nowWeather;
     13 
     14     //时间状态是否更改
     15     private bool changeTime = false;
     16     //天气状态是否更改
     17     private bool changeWeather = false;
     18 
     19     //时间流逝速度
     20     public float timeSpeed = 0.0F;
     21 
     22     void Start () 
     23     {
     24         //初始化UniSky插件
     25         uniSky = GameObject.Find("UniSkyAPI").GetComponent("UniSkyAPI") as UniSkyAPI;
     26         uniSky.InstantiateUniSky();
     27         //初始化时间状态(上午)和天气状态(晴天)
     28         nowWeather = WeatherState.SUNNY_DAY;
     29         nowTime = TimeState.AM;
     30         //防止bug天空
     31         uniSky.SetStormCloudCover(-3.5F);
     32         uniSky.LerpStormCloudCover(-3.5F, -3.5F);
     33 
     34         //去掉鼠标
     35         Screen.showCursor = false;
     36     }
     37 
     38     void Update() 
     39     {
     40         //根据键盘输入改变时间状态和天气状态
     41         ChangeTimeAndWeather();
     42         //根据时间状态和天气状态绘制相关效果
     43         RealizeTimeAndWeather();
     44 
     45         //如果没有强行改变时间,则时间正常流逝,反之则强行改变时间的这一帧时间不流逝
     46         if (changeTime)
     47             changeTime = false;
     48         else
     49             ChanageTime();
     50 
     51         if (changeWeather)
     52         {
     53             ResetSky();
     54             changeWeather = false;
     55         }   
     56 
     57         //输出当前的时间和天气
     58         Debug.Log(nowTime + "," + nowWeather + "," + changeWeather);
     59     }
     60 
     61     void OnGUI()
     62     {
     63         GUI.Label(new Rect(0,   0, 100, 20), "操作说明:");
     64         
     65         GUI.Label(new Rect(0,  50, 500, 20), "F1-F6功能键切换时间:F1->早晨  F2->上午  F3->中午  F4->下午  F5->黄昏  F6->晚上");
     66         GUI.Label(new Rect(0,  80, 500, 20), "1-5数字键切换天气:    1->晴天  2 ->雨天   3->大风    4->雾天   5->阴天");
     67 
     68         GUI.Label(new Rect(0, 130, 200, 20), "W->人物向前");
     69         GUI.Label(new Rect(0, 160, 200, 20), "S->人物向后");
     70         GUI.Label(new Rect(0, 190, 200, 20), "A->人物向左");
     71         GUI.Label(new Rect(0, 220, 200, 20), "D->人物向右");
     72         GUI.Label(new Rect(0, 250, 200, 20), "空格->跳跃");
     73         GUI.Label(new Rect(0, 280, 200, 20), "鼠标->旋转");
     74     }
     75 
     76     /// <summary>
     77     /// 时间自动流逝
     78     /// </summary>
     79     void ChanageTime()
     80     {
     81         uniSky.SetTime(uniSky.GetTime() + Time.deltaTime * timeSpeed);
     82     }
     83 
     84     /// <summary>
     85     /// 重置天空
     86     /// </summary>
     87     void ResetSky()
     88     {
     89         //云少
     90         uniSky.SetCloudCover(-2);
     91         uniSky.LerpCloudCover(-2, -2);
     92         //云白
     93         uniSky.SetPrecipitationLevel(1);
     94         uniSky.LerpPrecipitationLevel(1, 1);
     95         //光多
     96         uniSky.SetSunIntensity(0.5F);
     97         uniSky.LerpSunIntensity(0.5F, 0.5F);
     98         
     99         //不打雷
    100         uniSky.SetLightningFrequency(0);
    101         //不下雨
    102         uniSky.SetRainLevel(0, 0);
    103         uniSky.LerpRainLevel(0, 0, 0);
    104         //雨不滴落下屏幕上
    105         uniSky.SetDropletLevel(1);
    106         uniSky.LerpDropletLevel(1, 1);
    107         //没烟雾
    108         uniSky.SetFogLevel(0);
    109         uniSky.LerpFogLevel(0, 0);
    110 
    111         //正常卷云
    112         uniSky.SetGlowVariance(10);
    113         uniSky.LerpGlowVariance(10, 10);
    114 
    115         //清除缓存
    116         uniSky.ClearDropletBuffer();
    117     }
    118 
    119     /// <summary>
    120     /// 实现时间天气效果
    121     /// </summary>
    122     void RealizeTimeAndWeather()
    123     {
    124         //--------------------------------------------时间 -----------------------------------------
    125 
    126         //早晨
    127         if(nowTime == TimeState.MORNING)
    128         {
    129             uniSky.SetTime(8);
    130         }
    131 
    132         //上午
    133         if (nowTime == TimeState.AM)
    134         {
    135             uniSky.SetTime(10);
    136         }
    137 
    138         //中午
    139         if (nowTime == TimeState.NOONING)
    140         {
    141             uniSky.SetTime(12);
    142         }
    143 
    144         //下午
    145         if (nowTime == TimeState.PM)
    146         {
    147             uniSky.SetTime(14);
    148         }
    149 
    150         //傍晚
    151         if (nowTime == TimeState.DUSK)
    152         {
    153             uniSky.SetTime(16);
    154         }
    155 
    156         //晚上
    157         if (nowTime == TimeState.NIGHT)
    158         {
    159             uniSky.SetTime(20);
    160         }
    161 
    162         //--------------------------------------------天气 -----------------------------------------
    163 
    164         //晴天
    165         if (nowWeather == WeatherState.SUNNY_DAY)
    166         {
    167             //云少
    168             uniSky.SetCloudCover(-2);
    169             uniSky.LerpCloudCover(-2, -2);
    170             //云白
    171             uniSky.SetPrecipitationLevel(1);
    172             uniSky.LerpPrecipitationLevel(1, 1);
    173             //少卷云
    174             uniSky.SetGlowVariance(15);
    175             uniSky.LerpGlowVariance(15, 15);
    176         }
    177 
    178         //雨天
    179         if (nowWeather == WeatherState.RAINY_DAY)
    180         {
    181             //云多
    182             uniSky.SetCloudCover(-1);
    183             uniSky.LerpCloudCover(-1, -1);
    184             //云黑
    185             uniSky.SetPrecipitationLevel(0.3F);
    186             uniSky.LerpPrecipitationLevel(0.3F, 0.3F);
    187             //光少
    188             uniSky.SetSunIntensity(0.2F);
    189             uniSky.LerpSunIntensity(0.2F, 0.2F);
    190             //打雷
    191             uniSky.SetLightningFrequency(200);
    192             //下雨
    193             uniSky.SetRainLevel(200, 200);
    194             uniSky.LerpRainLevel(200, 200, 200);
    195             //雨在屏幕图像上滴落(0到5)
    196             uniSky.SetDropletLevel(100);
    197             uniSky.LerpDropletLevel(100, 100);
    198             //多卷云
    199             uniSky.SetGlowVariance(5);
    200             uniSky.LerpGlowVariance(5, 5);
    201         }
    202 
    203         //雪天
    204         if (nowWeather == WeatherState.SNOWY_DAY)
    205         {
    206             //云多
    207             uniSky.SetCloudCover(-1.5F);
    208             uniSky.LerpCloudCover(-1.5F, -1.5F);
    209             //光少
    210             uniSky.SetSunIntensity(0.25F);
    211             uniSky.LerpSunIntensity(0.25F, 0.25F);
    212             //多卷云
    213             uniSky.SetGlowVariance(-4);
    214             uniSky.LerpGlowVariance(-4, -4);
    215         }
    216 
    217         //雾天
    218         if (nowWeather == WeatherState.FOGGY_DAY)
    219         {
    220             //云多
    221             uniSky.SetCloudCover(1);
    222             uniSky.LerpCloudCover(1, 1);
    223             //光少
    224             uniSky.SetSunIntensity(0.2F);
    225             uniSky.LerpSunIntensity(0.2F, 0.2F);
    226             //雾多
    227             uniSky.SetFogLevel(0.02F);
    228             uniSky.LerpFogLevel(0.02F, 0.02F);
    229         }
    230 
    231         //阴天
    232         if (nowWeather == WeatherState.CLOUD_DAY)
    233         {
    234             //云多
    235             uniSky.SetCloudCover(2);
    236             uniSky.LerpCloudCover(2, 2);
    237             //光少
    238             uniSky.SetSunIntensity(0.2F);
    239             uniSky.LerpSunIntensity(0.2F, 0.2F);
    240         }
    241     }
    242 
    243     /// <summary>
    244     /// 改变时间天气状态
    245     /// </summary>
    246     void ChangeTimeAndWeather()
    247     {
    248         //--------------------------------------------时间 -----------------------------------------
    249 
    250         //F1键为早晨
    251         if (Input.GetKeyDown(KeyCode.F1))
    252         {
    253             changeTime = true;
    254             nowTime = TimeState.MORNING;
    255         }
    256 
    257         //F2键为上午
    258         if (Input.GetKeyDown(KeyCode.F2))
    259         {
    260             changeTime = true;
    261             nowTime = TimeState.AM;
    262         }
    263 
    264         //F3键为中午
    265         if (Input.GetKeyDown(KeyCode.F3))
    266         {
    267             changeTime = true;
    268             nowTime = TimeState.NOONING;
    269         }
    270 
    271         //F4键为下午
    272         if (Input.GetKeyDown(KeyCode.F4))
    273         {
    274             changeTime = true;
    275             nowTime = TimeState.PM;
    276         }
    277 
    278         //F5键为傍晚
    279         if (Input.GetKeyDown(KeyCode.F5))
    280         {
    281             changeTime = true;
    282             nowTime = TimeState.DUSK;
    283         }
    284 
    285         //F6键为晚上
    286         if (Input.GetKeyDown(KeyCode.F6))
    287         {
    288             changeTime = true;
    289             nowTime = TimeState.NIGHT;
    290         }
    291 
    292         //--------------------------------------------天气 -------------------------------------------
    293 
    294         //数字键1为晴天
    295         if (Input.GetKeyDown(KeyCode.Alpha1))
    296         {
    297             changeWeather = true;
    298             nowWeather = WeatherState.SUNNY_DAY;
    299         }
    300 
    301         //数字键2为雨天
    302         if (Input.GetKeyDown(KeyCode.Alpha2))
    303         {
    304             changeWeather = true;
    305             nowWeather = WeatherState.RAINY_DAY;
    306         }
    307 
    308         //数字键3为雪天
    309         if (Input.GetKeyDown(KeyCode.Alpha3))
    310         {
    311             changeWeather = true;
    312             nowWeather = WeatherState.SNOWY_DAY;
    313         }
    314 
    315         //数字键4为雾天
    316         if (Input.GetKeyDown(KeyCode.Alpha4))
    317         {
    318             changeWeather = true;
    319             nowWeather = WeatherState.FOGGY_DAY;
    320         }
    321 
    322         //数字键5为阴天
    323         if (Input.GetKeyDown(KeyCode.Alpha5))
    324         {
    325             changeWeather = true;
    326             nowWeather = WeatherState.CLOUD_DAY;
    327         }
    328     }
    329 }
    核心控制类

    效果图

  • 相关阅读:
    Ugly Numbers
    Present
    Out of Hay
    Stars(树状数组或线段树)
    Humble Numbers
    Wireless Network
    Rank List
    Argus
    食物链
    Antenna Placement
  • 原文地址:https://www.cnblogs.com/coqn/p/3125380.html
Copyright © 2011-2022 走看看