Esempio n. 1
0
        /* --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- */

        public static void Init(UnityEngine.Camera cameraScript)
        {
            if (IsInit || cameraScript == null)
            {
                return;
            }

            Sky.cameraScript = cameraScript;
            skyObject        = new GameObject("Sky");

            sunObject = new GameObject("Sun");
            sunObject.transform.parent           = skyObject.transform;
            sunObject.transform.localPosition    = new Vector3(0f, 5000f, 0f);
            sunObject.transform.localEulerAngles = new Vector3(0f, 180f, 0f);

            moonObject = new GameObject("Moon");
            moonObject.transform.parent           = skyObject.transform;
            moonObject.transform.localPosition    = new Vector3(0f, -5000f, 0f);
            moonObject.transform.localEulerAngles = new Vector3(0f, 0f, 0f);

            rotation.y = 90f;
            GameObject.DontDestroyOnLoad(skyObject);

            sunLight         = sunObject.AddComponent <Light>();
            sunLight.type    = LightType.Directional;
            sunLight.shadows = LightShadows.Soft;

            moonLight         = moonObject.AddComponent <Light>();
            moonLight.type    = LightType.Directional;
            moonLight.shadows = LightShadows.Soft;

            Mode   = SkyMode.Night;
            IsInit = true;
        }
Esempio n. 2
0
 public static void Update()
 {
     if (!IsInit || !isEnable)
     {
         return;
     }
     curMinute = Calendar.Minute;
     if (curMinute == lastMinute)
     {
         return;
     }
     lastMinute = curMinute;
     rotation.x = (Calendar.Hour * -15f + curMinute * -0.25f) + 90f;
     skyObject.transform.localEulerAngles = rotation;
     if (mode != SkyMode.Day && Calendar.Hour > 5 && 18 > Calendar.Hour)
     {
         Mode = SkyMode.Day;
     }
     else if (mode != SkyMode.Night && (6 > Calendar.Hour || Calendar.Hour > 17))
     {
         Mode = SkyMode.Night;
     }
 }
Esempio n. 3
0
    IEnumerator ChangeSkybox(int type,float time)
    {
        //type: 1=Sunny 2=Rain
        float moveTime = 0.0f;
        if(type==1 && skymode!=SkyMode.Sunny){//sunny
            while(moveTime < time){
                moveTime += Time.deltaTime;
                if(blend>0){
                    blend = 1-moveTime/time;
                }
        //				if(DirectionalLight.light.intensity < 1f){
        //					DirectionalLight.light.intensity = 0.01f+0.99f*(moveTime/time);
        //				}
                if(DirectionalLight.light.intensity < 1f){
                    DirectionalLight.light.intensity = 0.3f+0.7f*(moveTime/time);
                }
                RenderSettings.skybox.SetFloat("_Blend",blend);
                yield return null;
            }
            skymode = SkyMode.Sunny;
        }
        else if(type==2 && skymode!=SkyMode.Rain){//rain
            PS_Rain.particleEmitter.emit = true;
            while(moveTime < time){
                moveTime += Time.deltaTime;
                if(blend<1){
                    blend = moveTime/time;
                }
        //				if(DirectionalLight.light.intensity > 0.01f){
        //					DirectionalLight.light.intensity = 1f-0.99f*(moveTime/time);
        //				}
                if(DirectionalLight.light.intensity > 0.3f){
                    DirectionalLight.light.intensity = 1f-0.7f*(moveTime/time);
                }
                RenderSettings.skybox.SetFloat("_Blend",blend);
                RenderSettings.fogColor = new Color(origin_color.r-(moveTime/time)*(origin_color.r-new_color.r),origin_color.g-(moveTime/time)*(origin_color.g-new_color.g),origin_color.b-(moveTime/time)*(origin_color.b-new_color.b),1);
                RenderSettings.ambientLight = new Color(origin_ambient.r-(moveTime/time)*(origin_ambient.r-new_ambient.r),origin_ambient.g-(moveTime/time)*(origin_ambient.g-new_ambient.g),origin_ambient.b-(moveTime/time)*(origin_ambient.b-new_ambient.b),1);
                PS_Rain.particleEmitter.maxSize = (moveTime/time);
                PS_Rain.particleEmitter.minSize = (moveTime/time);
                yield return null;
            }

            skymode = SkyMode.Rain;
        }
    }