You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
437 lines
15 KiB
437 lines
15 KiB
using AX.MessageSystem; |
|
using System; |
|
using System.Collections; |
|
using System.Collections.Generic; |
|
using System.IO; |
|
using System.Xml; |
|
using UnityEngine; |
|
using UnityEngine.UI; |
|
|
|
public enum TianQi |
|
{ |
|
晴 = 0, 阴, 雨, 雪 |
|
} |
|
public enum FengLi |
|
{ |
|
无风 = 0, 一级, 二级, 三级, 四级, 五级, 六级, 七级, 八级, 九级, 十级, 十一级, 十二级 |
|
} |
|
public enum FengXiang |
|
{ |
|
北风 = 0, 东北风, 东风, 东南风, 南风, 西南风, 西风, 西北风 |
|
} |
|
public enum HasNeight |
|
{ |
|
关 = 0, 开 |
|
} |
|
[Serializable] |
|
public class TianQiSetting |
|
{ |
|
public TianQi tianqi; |
|
public int wendu; |
|
public FengLi fengli; |
|
public FengXiang fengxiang; |
|
public int datetime; |
|
public int neightLast; |
|
public HasNeight Hasneight; |
|
} |
|
public class WeatherSettingManager : MonoBehaviour |
|
{ |
|
|
|
//参数设置 |
|
[Header("昼夜交替多少秒代替一小时")] |
|
public float interval;//时间间隔 |
|
//引用对象 |
|
public WindZone windZone; |
|
public GameObject rain; |
|
public GameObject snow; |
|
public AzureSky_Controller skyController; |
|
public Toggle SetToggle; |
|
//天气设置相关 |
|
public Dropdown TianQiDrop; |
|
public Slider WenDunSlider; |
|
public InputField WenDunInput; |
|
public Dropdown FengLiDrop; |
|
public Dropdown FengXiangDrop; |
|
public Slider DateTimeSlider; |
|
public Dropdown NeightDrop; |
|
public InputField NeightTimeInput; |
|
public Button TianQiSureBtn; |
|
public Button TianQiCancelBtn; |
|
private GameObject rainObj; |
|
private GameObject sonwObj; |
|
private Transform mainCamera; |
|
public float timeAllMM; |
|
public bool HasNeightChange; |
|
public TianQiSetting TianQiSettingData; |
|
private XmlDocument XmlDoc; |
|
private string TianQiDataPath; |
|
private int timeAll; |
|
private bool HasInit = false; |
|
void Start() |
|
{ |
|
|
|
} |
|
public void AddRecordEventWeather(TianQiSetting data) |
|
{ |
|
if (ReplaySetting.PlayStatus == PlayStatus.isEditor && RecordManager.Instance.recordStatus == RecordStatus.normal) |
|
{ |
|
var eventData = new EventData(); |
|
eventData.time = RecordManager.Instance.RecordTimer; |
|
eventData.cloneObjType = CloneObjType.None; |
|
eventData.eventType = RecordEventType.WeatherSetting; |
|
eventData.json = JsonUtility.ToJson(data); |
|
|
|
RecordManager.Instance.jsonData.eventDataList.Add(eventData); |
|
} |
|
} |
|
public TianQiSetting GetNowSettingData() |
|
{ |
|
return TianQiSettingData; |
|
} |
|
|
|
public void Init(Toggle setToggle) |
|
{ |
|
SetToggle = setToggle; |
|
if (!HasInit) |
|
InitMethord(); |
|
//CreateXml(); |
|
//TianQiSettingData = LoadXmlTianQi(); |
|
if (TianQiSettingData == null) |
|
{ |
|
TianQiSettingData = new TianQiSetting |
|
{ |
|
tianqi = TianQi.晴, |
|
wendu = 20, |
|
fengli = FengLi.无风, |
|
fengxiang = FengXiang.北风, |
|
datetime = 10, |
|
Hasneight = HasNeight.关, |
|
neightLast = 1 |
|
}; |
|
//SetXml(TianQiSettingData); |
|
} |
|
InitTianQi(); |
|
} |
|
|
|
private void InitMethord() |
|
{ |
|
if (windZone == null) |
|
windZone = GameObject.Find("WindZone").GetComponent<WindZone>(); |
|
if (skyController == null) |
|
skyController = GameObject.Find("SkyControl").GetComponent<AzureSky_Controller>(); |
|
mainCamera = GameObject.Find("Main Camera").GetComponent<Camera>().transform; |
|
//天气设置相关 |
|
TianQiDrop.onValueChanged.AddListener(TianQiDropOnValueChanged); |
|
WenDunSlider.onValueChanged.AddListener(WenDuSliderValueChanged); |
|
WenDunInput.onValueChanged.AddListener(WenDuInputValueChanged); |
|
FengXiangDrop.onValueChanged.AddListener(FengXiangDropValueChanged); |
|
FengLiDrop.onValueChanged.AddListener(FengLiDropValueChanged); |
|
DateTimeSlider.onValueChanged.AddListener(DateTimeSliderValueChanged); |
|
NeightDrop.onValueChanged.AddListener(NeightDropOnValueChanged); |
|
NeightTimeInput.onValueChanged.AddListener(NeightTimeInputValueChanged); |
|
TianQiSureBtn.onClick.AddListener(TianQiSureBtnClick); |
|
TianQiCancelBtn.onClick.AddListener(TianQiCancelBtnClick); |
|
HasInit = true; |
|
} |
|
|
|
/// <summary> |
|
/// 天气设置 |
|
/// </summary> |
|
/// <param name="value"></param> |
|
private void TianQiDropOnValueChanged(int value) |
|
{ |
|
switch (TianQiDrop.captionText.text) |
|
{ |
|
case "晴": |
|
if (rainObj != null) |
|
{ |
|
Destroy(rainObj); |
|
} |
|
if (sonwObj != null) |
|
{ |
|
Destroy(sonwObj); |
|
} |
|
skyController.Lightincrement = 0f; |
|
skyController.SunIntensityCurve[0] = AnimationCurve.Linear(0, 100.0f, 24, 100.0f); |
|
skyController.LambdaCurveR[0] = AnimationCurve.Linear(0, 650.0f, 24, 650.0f); |
|
skyController.LambdaCurveG[0] = AnimationCurve.Linear(0, 570.0f, 24, 570.0f); |
|
skyController.LambdaCurveB[0] = AnimationCurve.Linear(0, 475.0f, 24, 475.0f); |
|
break; |
|
case "阴": |
|
if (rainObj != null) |
|
{ |
|
Destroy(rainObj); |
|
} |
|
if (sonwObj != null) |
|
{ |
|
Destroy(sonwObj); |
|
} |
|
skyController.Lightincrement = -0.6f; |
|
skyController.SunDirLightIntensity = 0.5f; |
|
skyController.SunIntensityCurve[0] = AnimationCurve.Linear(0, 0, 0, 0); |
|
skyController.LambdaCurveR[0] = AnimationCurve.Linear(0, 300.0f, 24, 300.0f); |
|
skyController.LambdaCurveG[0] = AnimationCurve.Linear(0, 300.0f, 24, 300.0f); |
|
skyController.LambdaCurveB[0] = AnimationCurve.Linear(0, 300.0f, 24, 300.0f); |
|
break; |
|
case "雨": |
|
skyController.Lightincrement = -0.6f; |
|
skyController.SunDirLightIntensity = 0.5f; |
|
skyController.SunIntensityCurve[0] = AnimationCurve.Linear(0, 0, 0, 0); |
|
skyController.LambdaCurveR[0] = AnimationCurve.Linear(0, 300.0f, 24, 300.0f); |
|
skyController.LambdaCurveG[0] = AnimationCurve.Linear(0, 300.0f, 24, 300.0f); |
|
skyController.LambdaCurveB[0] = AnimationCurve.Linear(0, 300.0f, 24, 300.0f); |
|
if (sonwObj != null) |
|
{ |
|
Destroy(sonwObj); |
|
} |
|
if (rainObj == null) |
|
{ |
|
rainObj = Instantiate(rain, mainCamera); |
|
rainObj.name = "Rain"; |
|
rainObj.transform.localPosition = new Vector3(20, 45, 45); |
|
rainObj.transform.localEulerAngles = new Vector3(-100, 25, 120); |
|
} |
|
break; |
|
case "雪": |
|
skyController.Lightincrement = -0.6f; |
|
skyController.SunDirLightIntensity = 0.5f; |
|
skyController.SunIntensityCurve[0] = AnimationCurve.Linear(0, 0, 0, 0); |
|
skyController.LambdaCurveR[0] = AnimationCurve.Linear(0, 300.0f, 24, 300.0f); |
|
skyController.LambdaCurveG[0] = AnimationCurve.Linear(0, 300.0f, 24, 300.0f); |
|
skyController.LambdaCurveB[0] = AnimationCurve.Linear(0, 300.0f, 24, 300.0f); |
|
if (rainObj != null) |
|
{ |
|
Destroy(rainObj); |
|
} |
|
if (sonwObj == null) |
|
{ |
|
sonwObj = Instantiate(snow, mainCamera); |
|
sonwObj.name = "Snow"; |
|
sonwObj.transform.localPosition = new Vector3(9, 45, 90); |
|
sonwObj.transform.localEulerAngles = new Vector3(-75, 180, -155); |
|
} |
|
break; |
|
} |
|
TianQiSettingData.tianqi = (TianQi)TianQiDrop.value; |
|
AddRecordEventWeather(TianQiSettingData); |
|
} |
|
/// <summary> |
|
/// 温度设置 |
|
/// </summary> |
|
/// <param name="value"></param> |
|
private void WenDuInputValueChanged(string value) |
|
{ |
|
float _value = 0; |
|
try |
|
{ |
|
_value = float.Parse(value); |
|
} |
|
catch |
|
{ |
|
return; |
|
} |
|
if (_value > 40) |
|
{ |
|
WenDunInput.text = 40 + ""; |
|
return; |
|
} |
|
if (_value < -40) |
|
{ |
|
WenDunInput.text = -40 + ""; |
|
return; |
|
} |
|
WenDunSlider.value = _value + 40; |
|
} |
|
/// <summary> |
|
/// 温度设置 |
|
/// </summary> |
|
/// <param name="value"></param> |
|
private void WenDuSliderValueChanged(float value) |
|
{ |
|
float _value = value - 40; |
|
WenDunInput.text = _value.ToString(); |
|
} |
|
/// <summary> |
|
/// 风向设置 |
|
/// </summary> |
|
/// <param name="value"></param> |
|
private void FengXiangDropValueChanged(int value) |
|
{ |
|
//float _BaseY = _compass.InitialRotationAngle; |
|
float _BaseY = 0; |
|
switch (value) |
|
{ |
|
case 0: |
|
windZone.transform.localEulerAngles = new Vector3(0, 0 - _BaseY, 0); |
|
break; |
|
case 1: |
|
windZone.transform.localEulerAngles = new Vector3(0, 0 - _BaseY + 45, 0); |
|
break; |
|
case 2: |
|
windZone.transform.localEulerAngles = new Vector3(0, 0 - _BaseY + 90, 0); |
|
break; |
|
case 3: |
|
windZone.transform.localEulerAngles = new Vector3(0, 0 - _BaseY + 135, 0); |
|
break; |
|
case 4: |
|
windZone.transform.localEulerAngles = new Vector3(0, 0 - _BaseY + 180, 0); |
|
break; |
|
case 5: |
|
windZone.transform.localEulerAngles = new Vector3(0, 0 - _BaseY + 225, 0); |
|
break; |
|
case 6: |
|
windZone.transform.localEulerAngles = new Vector3(0, 0 - _BaseY + 270, 0); |
|
break; |
|
case 7: |
|
windZone.transform.localEulerAngles = new Vector3(0, 0 - _BaseY + 315, 0); |
|
break; |
|
} |
|
} |
|
/// <summary> |
|
/// 风力设置 |
|
/// </summary> |
|
/// <param name="value"></param> |
|
private void FengLiDropValueChanged(int value) |
|
{ |
|
windZone.windMain = value; |
|
windZone.windTurbulence = value; |
|
} |
|
/// <summary> |
|
/// 当前时间设置 |
|
/// </summary> |
|
/// <param name="value"></param> |
|
private void DateTimeSliderValueChanged(float value) |
|
{ |
|
if (!HasNeightChange) |
|
{ |
|
skyController.TIME_of_DAY = value * 24; |
|
} |
|
} |
|
/// <summary> |
|
/// 昼夜交替开关 |
|
/// </summary> |
|
/// <param name="value"></param> |
|
private void NeightDropOnValueChanged(int value) |
|
{ |
|
HasNeightChange = value != 0; |
|
switch (value) |
|
{ |
|
case 0: |
|
skyController.SetTime(0, 0); |
|
DateTimeSlider.interactable = false; |
|
DateTimeSlider.value = TianQiSettingData.datetime / 24.0f; |
|
skyController.TIME_of_DAY = TianQiSettingData.datetime; |
|
DateTimeSlider.interactable = true; |
|
skyController.WispyCloudSpeedCurve[0] = AnimationCurve.Linear(0, 1f, 24, 1f); |
|
break; |
|
case 1: |
|
skyController.SetTime(0, int.Parse(NeightTimeInput.text)); |
|
skyController.TIME_of_DAY = DateTimeSlider.value * 24f; |
|
float a = float.Parse(NeightTimeInput.text); |
|
skyController.WispyCloudSpeed = 10f; |
|
skyController.WispyCloudSpeedCurve[0] = AnimationCurve.Linear(0, (0.1f - a / 1440 + 1) * 10, 24, (0.1f - a / 1440 + 1) * 10); |
|
if (skyController.WispyCloudSpeed <= 1) |
|
{ |
|
skyController.WispyCloudSpeedCurve[0] = AnimationCurve.Linear(0, 1f, 24, 1f); |
|
} |
|
break; |
|
} |
|
} |
|
/// <summary> |
|
/// 持续时间设置 |
|
/// </summary> |
|
/// <param name="value"></param> |
|
private void NeightTimeInputValueChanged(string value) |
|
{ |
|
try |
|
{ |
|
timeAll = int.Parse(value); |
|
if (timeAll < 1) |
|
{ |
|
NeightTimeInput.text = 1 + ""; |
|
} |
|
} |
|
catch |
|
{ |
|
NeightTimeInput.text = 1 + ""; |
|
} |
|
} |
|
/// <summary> |
|
/// 天气确定点击跟新XML数据保存更改 |
|
/// </summary> |
|
private void TianQiSureBtnClick() |
|
{ |
|
TianQiSettingData.tianqi = (TianQi)TianQiDrop.value; |
|
TianQiSettingData.wendu = int.Parse(WenDunInput.text); |
|
TianQiSettingData.fengli = (FengLi)FengLiDrop.value; |
|
TianQiSettingData.fengxiang = (FengXiang)FengXiangDrop.value; |
|
TianQiSettingData.datetime = (int)(DateTimeSlider.value * 24); |
|
TianQiSettingData.Hasneight = (HasNeight)NeightDrop.value; |
|
TianQiSettingData.neightLast = int.Parse(NeightTimeInput.text); |
|
|
|
AddRecordEventWeather(TianQiSettingData); |
|
//SetXml(TianQiSettingData); |
|
if (SetToggle.isOn) |
|
SetToggle.isOn = false; |
|
} |
|
/// <summary> |
|
/// 天气取消按钮点击 |
|
/// </summary> |
|
public void TianQiCancelBtnClick() |
|
{ |
|
InitTianQi(); |
|
if (SetToggle.isOn) |
|
SetToggle.isOn = false; |
|
} |
|
/// <summary> |
|
/// 初始化天气设置 |
|
/// </summary> |
|
public void InitTianQi() |
|
{ |
|
TianQiDrop.value = (int)TianQiSettingData.tianqi; |
|
WenDunSlider.value = TianQiSettingData.wendu + 40; |
|
FengLiDrop.value = (int)TianQiSettingData.fengli; |
|
windZone.windMain = (int)TianQiSettingData.fengli; |
|
windZone.windTurbulence = (int)TianQiSettingData.fengli; |
|
FengXiangDrop.value = (int)TianQiSettingData.fengxiang; |
|
DateTimeSlider.value = (float)(TianQiSettingData.datetime / 24.0); |
|
NeightTimeInput.text = TianQiSettingData.neightLast.ToString(); |
|
NeightDrop.value = (int)TianQiSettingData.Hasneight; |
|
HasNeightChange = NeightDrop.value != 0; |
|
} |
|
private void CreateXml() |
|
{ |
|
if (string.IsNullOrEmpty(TianQiDataPath)) |
|
TianQiDataPath = Application.dataPath + @"/StreamingAssets/TianQiSettingData.xml"; |
|
if (!File.Exists(TianQiDataPath)) |
|
{ |
|
XmlDoc = new XmlDocument(); |
|
XmlElement root = XmlDoc.CreateElement("Root"); |
|
XmlDoc.AppendChild(root); |
|
|
|
XmlDoc.Save(TianQiDataPath); |
|
} |
|
} |
|
private TianQiSetting LoadXmlTianQi() |
|
{ |
|
XmlDoc = new XmlDocument(); |
|
|
|
XmlDoc.Load(TianQiDataPath); |
|
XmlNode Node = XmlDoc.SelectSingleNode("Root"); |
|
if (!string.IsNullOrEmpty(Node.InnerText)) |
|
{ |
|
TianQiSetting data = JsonUtility.FromJson<TianQiSetting>(Node.InnerText); |
|
return data; |
|
} |
|
else |
|
return null; |
|
} |
|
private void SetXml(TianQiSetting data) |
|
{ |
|
XmlDoc = new XmlDocument(); |
|
XmlDoc.Load(TianQiDataPath); |
|
XmlNode root = XmlDoc.SelectSingleNode("Root"); |
|
root.InnerText = JsonUtility.ToJson(data); |
|
XmlDoc.Save(TianQiDataPath); |
|
} |
|
}
|
|
|