YiHe_AllVersion/YHWeb/Assets/YHElectric/Scripts/Manager/SkyUIController.cs

130 lines
3.6 KiB
C#

using UnityEngine;
using UnityEngine.UI;
using UnityEngine.AzureSky;
using YHElectric;
using System;
using LitJson;
public class SkyUIController : MonoBehaviour
{
[HideInInspector]
public AzureSkyController skyController;
//public Slider slider;
//public Image transitionBar;
private Vector3 m_scale;
private float timeValue = 11.96f;
private static float timeValueFlag = 11.96f;
private void Start()
{
skyController = GameObject.Find("Azure[Sky]Controller").GetComponent<AzureSkyController>();
for (int i = 0; i < transform.GetComponentsInChildren<Button>().Length; i++)
{
int index = i;
transform.GetComponentsInChildren<Button>()[i].onClick.AddListener(() => BtnClick(index));
}
// GameManager.funcDict.Add("SetWeather",SetWeather);//+++++++++++++
// GameManager.funcDict.Add("timeSlider", SetTime);//+++++++++++++++++++
RealWeather.setWeather+=SetRealWeather;
}
void Update()
{
//RealWeather.setWeather += SetRealWeather;
if (timeValue != timeValueFlag)
{
timeValue = timeValueFlag;
if (timeValue < 6 || timeValue > 18)//黑夜
{
if(!ModelLocation.instance.lightState)
{
ModelLocation.instance.lightState = true;
StartCoroutine(ModelLocation.instance.SetLightState(true));
}
}
else//白天
{
if (ModelLocation.instance.lightState)
{
ModelLocation.instance.lightState = false;
StartCoroutine(ModelLocation.instance.SetLightState(false));
}
}
}
skyController.timeOfDay.hour = timeValue;
if (flag != weatherFlag)
{
weatherFlag = flag;
skyController.SetNewWeatherProfile(flag);
ShowSkyImage(flag);
}
}
void BtnClick(int index)
{
print(index);
skyController.SetNewWeatherProfile(index);
}
int weatherFlag = -1, flag = -1;
public void SetWeather(string str)
{
flag = int.Parse(str);
}
public static void SetTime(string str)
{
timeValueFlag = float.Parse(str);
}
void ShowSkyImage(int value)
{
for(int i = 0; i < transform.childCount; i++)
{
transform.GetChild(i).gameObject.SetActive(false);
}
transform.GetChild(value).gameObject.SetActive(true);
}
/// <summary>
/// 设置真实天气
/// </summary>
/// <param name="weather"></param>
public void SetRealWeather(string weather)
{
string JsonData = weather;
JsonData jd = JsonMapper.ToObject(JsonData);
IndexPanel.tempTxt.text = jd["tem"].ToString();
int flag=0;
switch (jd["wea"].ToString())
{
case "多云":
flag = 0;
break;
case "多云转晴":
flag = 0;
break;
case "晴":
flag = 1;
break;
case "阴":
flag = 2;
break;
case "小雨":
flag = 3;
break;
case "小雨转多云":
flag = 3;
break;
case "中雨":
flag = 4;
break;
case "大雨":
flag = 5;
break;
}
skyController.SetNewWeatherProfile(flag);
ShowSkyImage(flag);
print(flag);
}
}