网演高层钦州
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.
 
 
 

228 lines
8.8 KiB

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using AX.NetworkSystem;
using System.IO;
using AX.Serialization;
public class DisasterItem : MonoBehaviour {
private Button LoadDisasterBtn;
private Toggle toggle;
private Text disasterItro;
private Text victoryCondition;
private Text timeSpeed;
private Text XiaQZDName;
private Text personCount;
private InputField roomName;
private InputField roomPassword;
public MapType mapType;
private int maxPersons;
public string fullName;
private Slider Progress;
public string myPath;
private DisasterLibraryFile disaster = new DisasterLibraryFile();
public long disasterMetaDataId;
// Use this for initialization
void Start () {
if (!transform.name.Contains("Custom"))
{
LoadDisasterBtn = transform.Find("Button").GetComponent<Button>();
LoadDisasterBtn.onClick.AddListener(LoadDisaster);
Progress = transform.Find("NotLoad/Slider").GetComponent<Slider>();
}
toggle = transform.Find("Toggle").GetComponent<Toggle>();
toggle.onValueChanged.AddListener(RefreshDisasterInfo);
disasterItro = GameObject.Find("DisasterInfo/DisasterIntro/Scroll View/Viewport/Content/Text").GetComponent<Text>();
victoryCondition = GameObject.Find("DisasterInfo/VictoryConditions/Scroll View/Viewport/Content/Text").GetComponent<Text>();
if (GameSettings.othersSettings.mode != Mode.DisasterManagement)
{//演习模式或者练习模式下:创建房间;等于DisasterManagement是创建灾情库
timeSpeed = GameObject.Find("DisasterInfo/Time/Speed").GetComponent<Text>();
XiaQZDName = GameObject.Find("DisasterInfo/XiaQuZhongDui/Name").GetComponent<Text>();
personCount = GameObject.Find("DisasterInfo/MaxPerson/PersonCount").GetComponent<Text>();
roomName = GameObject.Find("DisasterInfo/RoomName/InputField").GetComponent<InputField>();
roomPassword = GameObject.Find("DisasterInfo/RoomPassword/InputField").GetComponent<InputField>();
}
}
private void OnDestroy()
{
if (!transform.name.Contains("Custom"))
{
LoadDisasterBtn.onClick.RemoveListener(LoadDisaster);
}
toggle.onValueChanged.RemoveListener(RefreshDisasterInfo);
}
private void LoadDisaster()
{
Progress.gameObject.SetActive(true);
NetworkManager.Default.DownloadFileAsync(fullName, ProgressHandle, Completed);
}
private void ProgressHandle(string fullname, float progress)
{
Progress.value = progress / 100;
}
private void Completed(string fullname)
{
var str = fullname.Split('/');
myPath = Application.streamingAssetsPath + "/DisasterLibrary/" + str[str.Length - 1];
File.Move(fullname, myPath);
Progress.gameObject.SetActive(false);
Progress.value = 0;
Progress.transform.parent.gameObject.SetActive(false);
LoadDisasterBtn.gameObject.SetActive(false);
}
private void RefreshDisasterInfo(bool flag)
{
if (flag)
{
if (transform.name.Contains("Custom"))
{
disasterItro.text = "XXXX";
victoryCondition.text = "XXXX";
timeSpeed.text = "XXX";
XiaQZDName.text = mapType.areaSquadron;
maxPersons = GameObject.Find("Canvas/Background/CreateRoom").GetComponent<GET_MAX_PERSONS_REPLY>().maxPersons;
personCount.text = maxPersons.ToString();
}
else
{
//练习模式,演习模式,创建灾情库都需要
//需从灾情库下载的灾情,从灾情元数据里读取出来赋值
ReadDisaster(myPath, disaster);
disasterItro.text = disaster.DisasterIntro;
string vc = "";
if (disaster.VictoryCondition.Count != 0)
{
vc = "出现以下任意 " + "<color=red>" + disaster.VictoryCondition.Count + "</color>" + ", 则宣告演练失败:";
if (disaster.VictoryCondition.BurnedArea > 0 )
{
vc = vc + "\n" + "1. 火灾面积超过 " + "<color=red>" + disaster.VictoryCondition.BurnedArea + "</color>" + " 平米";
}
if (disaster.VictoryCondition.FireManDied > 0)
{
vc = vc + "\n" + "2. 消防员牺牲 " + "<color=red>" + disaster.VictoryCondition.FireManDied + "</color>" + " 名";
}
if (disaster.VictoryCondition.UnRescued > 0)
{
vc = vc + "\n" + "3. 伤员/被困人员有 " + "<color=red>" + disaster.VictoryCondition.UnRescued + "</color>" + " 名未救出";
}
if (disaster.VictoryCondition.BurnedTime > 0)
{
vc = vc + "\n" + "4. 火灾超过 " + "<color=red>" + disaster.VictoryCondition.BurnedTime + "</color>" + " 个小时未扑灭";
}
}
else
{
vc = "此灾情没有设置胜利条件!";
}
victoryCondition.text = vc;
if (GameSettings.othersSettings.mode != Mode.None && GameSettings.othersSettings.mode != Mode.DisasterManagement)
{
timeSpeed.text = "XXX";
XiaQZDName.text = mapType.areaSquadron;
maxPersons = GameObject.Find("Canvas/Background/CreateRoom").GetComponent<GET_MAX_PERSONS_REPLY>().maxPersons;
personCount.text = maxPersons.ToString();
}
}
if (GameSettings.othersSettings.mode != Mode.None )
{
if (GameSettings.othersSettings.mode != Mode.DisasterManagement)
{
GameObject.Find("Canvas/Background/CreateRoom/CreateRoomBtn").GetComponent<CreateRoom>().mapType = mapType;
if (transform.name.Contains("Custom"))
{
GameSettings.othersSettings.isSelectedDisaster = false;
}
else
{
GameSettings.othersSettings.isSelectedDisaster = true;
GameSettings.othersSettings.disaster = disaster;
}
}
else
{
GameObject.Find("ViewButton").GetComponent<DisasterView>().mapType = mapType;
GameObject.Find("EditButton").GetComponent<DisasterEdit>().mapType = mapType;
GameObject.Find("DeleteButton").GetComponent<DisasterDelete>().mapType = mapType;
GameObject.Find("DeleteButton").GetComponent<DisasterDelete>().disasterMetaDataId = disasterMetaDataId;
GameSettings.othersSettings.disaster = disaster;
}
}
}
else
{
disasterItro.text = "";
victoryCondition.text = "";
if (GameSettings.othersSettings.mode != Mode.None && GameSettings.othersSettings.mode != Mode.DisasterManagement)
{
timeSpeed.text = "";
XiaQZDName.text = "";
maxPersons = 0;
personCount.text = maxPersons.ToString();
}
if (GameSettings.othersSettings.mode != Mode.None)
{
if (GameSettings.othersSettings.mode != Mode.DisasterManagement)
{
GameObject.Find("Canvas/Background/CreateRoom/CreateRoomBtn").GetComponent<CreateRoom>().mapType = null;
}
else
{
GameObject.Find("ViewButton").GetComponent<DisasterView>().mapType = null;
GameObject.Find("EditButton").GetComponent<DisasterEdit>().mapType = null;
GameObject.Find("DeleteButton").GetComponent<DisasterDelete>().mapType = null;
}
}
}
}
/// <summary>
/// 读取下载的灾情文件,并反序列化成灾情
/// </summary>
/// <param name="path">文件路径</param>
/// <param name="disaster"></param>
private void ReadDisaster(string path, DisasterLibraryFile dst)
{
if (File.Exists(path))
{
var fileAllBytes = File.ReadAllBytes(path);
dst = fileAllBytes.CompressedTypelessDeserialize() as DisasterLibraryFile;
disaster = dst;
}
}
// Update is called once per frame
void Update () {
}
}