| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472 |
- using Mirror;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using FLOW;
- using GFMain;
- using UnityCommon;
- using UnityEngine.UI;
- namespace DTYJ
- {
- public class ControllerPanel : NetworkBehaviour
- {
- public static ControllerPanel instance;
- private void Awake()
- {
- instance = this;
- ShowPanel(false);
- InitDeng();
- InitShuiZhai();
- }
- public GameObject goPanelRoot;
- private void Update()
- {
- if (Input.GetKeyUp(KeyCode.P))
- {
- if (!isServer) return;
- SwitchShowPanel();
- }
- if (!OnlineCtrl.Instance.xietongServerIsConnected)
- UpdateTrain();
- }
- private void SwitchShowPanel()
- {
- ShowPanel(!goPanelRoot.activeSelf);
- }
- public void ShowPanel(bool show)
- {
- goPanelRoot.SetActive(show);
- }
- #region 水灾
- Dictionary<string, GameObject> dicGos = new Dictionary<string, GameObject>();
- public void InitShuiZhai()
- {
- dicGos.Clear();
- var tfRoot = GameObject.Find("快速定位").transform;
- int count = tfRoot.childCount;
- for (int i = 0; i < count; i++)
- {
- var child = tfRoot.GetChild(i);
- dicGos[child.name] = child.GetChild(0).gameObject;
- }
- }
- GameObject goShuiZai;
- ShuiZaiCtrl shuizaiCtrl;
- public void OnToggleShuiZai(bool v)
- {
- CmdSetShuiZai(v, 0);
- }
- public void OnSliderShuiZai(float v)
- {
- CmdSetShuiZai(true, v);
- }
- public Dictionary<string, float> dicSW = new Dictionary<string, float>();
- [Command(requiresAuthority = false)]
- public void CmdOnLevel(string name, float level)
- {
- dicSW[name] = level;
- foreach (var kvp in dicSW)
- {
- Debug.Log($"{kvp.Key} 水位 {kvp.Value}");
- }
- var cmdObj = new ShuiWei_opt();
- cmdObj.kvp = new ShuiWei_opt.Info[dicSW.Count];
- int index = 0;
- foreach (var kvp in dicSW)
- {
- cmdObj.kvp[index++] = new ShuiWei_opt.Info() { postion = kvp.Key, value = kvp.Value };
- }
- NetworkAnimPlayer.instance.SendCmdToServer(20601, cmdObj);
- }
- int nTaskSetShuiWei = -1;
- [Command(requiresAuthority = false)]
- public void CmdSetShuiZai(bool isOpen, float value)
- {
- Debug.Log($"CmdSetShuiZai isOpen-{isOpen} value-{value}");
- RpcSetShuiZai(isOpen, value);
- if (isOpen)
- {
- nTaskSetShuiWei = Utility.Update(5, () =>
- {
- foreach (var kvp in dicSW)
- {
- RpcSetShuiWei(kvp.Key, kvp.Value);
- }
- });
- }
- else
- {
- Utility.StopCoroutineExe(nTaskSetShuiWei);
- }
- }
- [ClientRpc]
- public void RpcSetShuiWei(string shuiweiname, float shuiwei)
- {
- dicGos[shuiweiname].GetComponentInChildren<TextMesh>().text = $"{shuiweiname}水位:{shuiwei.ToString("#0.000")} 米";
- }
- private void ShowLevelTag(bool show)
- {
- foreach (var kvp in dicGos)
- {
- kvp.Value.SetActive(show);
- }
- }
- [ClientRpc]
- public void RpcSetShuiZai(bool isOpen, float value)
- {
- ShowLevelTag(isOpen);
- if (isOpen)
- {
- if (goShuiZai == null)
- {
- MainEntry.Resource.LoadAsset("Assets/_DTYJ/Prefabs/水灾/水灾Flow.prefab", new GameFramework.Resource.LoadAssetCallbacks((assetName, asset, duration, userData) =>
- {
- goShuiZai = Instantiate((GameObject)asset);
- shuizaiCtrl = goShuiZai.GetComponent<ShuiZaiCtrl>();
- shuizaiCtrl?.SetFlowValue_up(value);
- }));
- }
- else
- {
- shuizaiCtrl?.SetFlowValue_up(value);
- }
- }
- else
- {
- if (goShuiZai != null)
- {
- DestroyImmediate(goShuiZai);
- goShuiZai = null;
- shuizaiCtrl = null;
- }
- }
- }
- [Command(requiresAuthority = false)]
- public void CmdSetShuiZai_down(float value)
- {
- var conn = OnlineCtrl.Instance.GetConnByRoleName(RoleName.站务员_站台);
- if (conn != null)
- RpcSetShuiZai_down(conn, value);
- }
- [TargetRpc]
- public void RpcSetShuiZai_down(NetworkConnectionToClient target, float value)
- {
- shuizaiCtrl.SetFlowValue_down(Mathf.Abs(value));
- }
- private GameObject goShaDai;
- [Command(requiresAuthority = false)]
- public void CmdPlaceShaDai()
- {
- if (goShaDai == null)
- goShaDai = OnlineCtrl.Instance.GenerateNetworkObj(13);
- }
- [Command(requiresAuthority = false)]
- public void CmdRemoveShaDai()
- {
- if (goShaDai != null)
- NetworkServer.Destroy(goShaDai);
- }
- private GameObject goTishiPai;
- [Command(requiresAuthority = false)]
- public void CmdPlaceTishiPai()
- {
- if (goTishiPai == null)
- goTishiPai = OnlineCtrl.Instance.GenerateNetworkObj(17);
- }
- [Command(requiresAuthority = false)]
- public void CmdRemoveTishiPai()
- {
- if (goTishiPai != null)
- NetworkServer.Destroy(goTishiPai);
- }
- private GameObject goGaoShi;
- [Command(requiresAuthority = false)]
- public void CmdPlaceGaoShi()
- {
- if (goGaoShi == null)
- goGaoShi = OnlineCtrl.Instance.GenerateNetworkObj(18);
- }
- [Command(requiresAuthority = false)]
- public void CmdRemoveGaoShi()
- {
- if (goGaoShi != null)
- NetworkServer.Destroy(goGaoShi);
- }
- private GameObject goZhiHuiBu;
- [Command(requiresAuthority = false)]
- public void CmdPlaceZhiHuiBu()
- {
- if (goZhiHuiBu == null)
- goZhiHuiBu = OnlineCtrl.Instance.GenerateNetworkObj(19);
- }
- [Command(requiresAuthority = false)]
- public void CmdRemoveZhiHuiBu()
- {
- if (goZhiHuiBu != null)
- NetworkServer.Destroy(goZhiHuiBu);
- }
- private GameObject goTZFW_Pai;
- [Command(requiresAuthority = false)]
- public void CmdPlaceTZFW()
- {
- if (goTZFW_Pai == null)
- goTZFW_Pai = OnlineCtrl.Instance.GenerateNetworkObj(20);
- }
- [Command(requiresAuthority = false)]
- public void CmdRemoveTZFW()
- {
- if (goTZFW_Pai != null)
- NetworkServer.Destroy(goTZFW_Pai);
- }
- private GameObject goShuiBeng_1, goShuiBeng_2;
- [Command(requiresAuthority = false)]
- public void CmdPlaceShuiBeng(string id)
- {
- if (id == "1")
- {
- if (goShuiBeng_1 == null)
- goShuiBeng_1 = OnlineCtrl.Instance.GenerateNetworkObj(14);
- }
- else if (id == "2")
- {
- if (goShuiBeng_2 == null)
- goShuiBeng_2 = OnlineCtrl.Instance.GenerateNetworkObj(16);
- }
- }
- [Command(requiresAuthority = false)]
- public void CmdRemoveShuiBeng(string id)
- {
- if (id == "1")
- {
- if (goShuiBeng_1 != null)
- NetworkServer.Destroy(goShuiBeng_1);
- }
- else if (id == "2")
- {
- if (goShuiBeng_2 != null)
- NetworkServer.Destroy(goShuiBeng_2);
- }
- }
- #endregion
- #region Train
- public InputField input_trainNo, input_blockNo;
- private float trainSpeed = 0;
- public void OnSlider_TrainSpeed(float value)
- {
- trainSpeed = value;
- }
- public void OnClickSetTrain()
- {
- RunTrain(input_trainNo.text, input_blockNo.text);
- }
- Dictionary<string, TrainInfo> dicTrain = new Dictionary<string, TrainInfo>();
- public void RunTrain(string trainNo, string block)
- {
- TrainInfo trainInfo;
- if (dicTrain.ContainsKey(trainNo))
- {
- trainInfo = dicTrain[trainNo];
- }
- else
- {
- trainInfo = new TrainInfo();
- dicTrain.Add(trainNo, trainInfo);
- }
- trainInfo.trainNo = trainNo;
- if (trainInfo.blockNo != block)
- {
- trainInfo.blockNo = block;
- trainInfo.offset = 0;
- }
- trainInfo.speed = trainSpeed;
- }
- CMDData cmdData10101_train = new CMDData() { cmd = 10101 };
- readonly List<string> listTrainStop = new List<string>();
- private void UpdateTrain()
- {
- foreach (var kvp in dicTrain)
- {
- kvp.Value.offset += kvp.Value.speed * Time.deltaTime;
- var trainInfo = kvp.Value;
- if (kvp.Value.blockNo == "T0202")
- {
- if (kvp.Value.offset > 140.6f && kvp.Value.offset < 140.73f)
- {
- if (!listTrainStop.Contains(kvp.Key))
- {
- listTrainStop.Add(kvp.Key);
- trainInfo.speed = 0;
- }
- }
- else
- {
- if (listTrainStop.Contains(kvp.Key))
- {
- listTrainStop.Remove(kvp.Key);
- }
- }
- }
- else
- {
- if (listTrainStop.Contains(kvp.Key))
- listTrainStop.Remove(kvp.Key);
- }
- cmdData10101_train.data = trainInfo;
- ControllerPanel.instance.CmdSendMessageMoNI(Newtonsoft.Json.JsonConvert.SerializeObject(cmdData10101_train));
- }
- }
- public void SetTrainDoor(string trainNo, int state)
- {
- TrainDoorState doorState = new TrainDoorState();
- doorState.trainNo = trainNo;
- doorState.state = state;
- var dataCmd = new { cmd = 10105, data = doorState };
- ControllerPanel.instance.CmdSendMessageMoNI(Newtonsoft.Json.JsonConvert.SerializeObject(dataCmd));
- }
- public InputField input_trainNo_door;
- int trainDoorState = 0;
- public void OnDropdownTrainDoor(int v)
- {
- trainDoorState = v;
- }
- public void OnClickSetTrainDoor()
- {
- SetTrainDoor(input_trainNo_door.text, trainDoorState);
- }
- #endregion
- #region CK
- public void OnSliderJinZhanSpeed(float value)
- {
- CmdSetJinZhanSpeed((int)value);
- }
- int countGenerate = 50;
- public Text addCKCount;
- public void OnSliderCKCount(float value)
- {
- countGenerate = (int)value;
- addCKCount.text = $"进站速度({countGenerate}人/分钟)";
- }
- [Command(requiresAuthority = false)]
- public void CmdSetJinZhanSpeed(int speed)
- {
- OnlineCtrl.Instance.chengKeCtrl.SetInSpeed(speed);
- }
- public void OnClickClearAll()
- {
- CmdClearAllCK();
- }
- [Command(requiresAuthority = false)]
- public void CmdClearAllCK()
- {
- OnlineCtrl.Instance.chengKeCtrl.RemoveAllChengKe();
- }
- public void OnClickGenerateCK_Immidiately()
- {
- CmdGenerateCK_Immidiately(countGenerate);
- }
- [Command(requiresAuthority = false)]
- public void CmdGenerateCK_Immidiately(int count)
- {
- OnlineCtrl.Instance.chengKeCtrl.GenerateImmidiately(count);
- }
- public void OntoggleChuZhan(bool v)
- {
- CmdChuZhanIsOn(v);
- }
- [Command(requiresAuthority = false)]
- public void CmdChuZhanIsOn(bool value)
- {
- OnlineCtrl.Instance.chengKeCtrl.CountPerMin_ChuZhan = value ? 10 : 0;
- }
- private GameObject goWeilan;
- [Command(requiresAuthority = false)]
- public void CmdPlaceWeilan()
- {
- if (goWeilan == null)
- goWeilan = OnlineCtrl.Instance.GenerateNetworkObj(15);
- }
- [Command(requiresAuthority = false)]
- public void CmdRemoveWeilan()
- {
- if (goWeilan != null)
- NetworkServer.Destroy(goWeilan);
- }
- #endregion
- #region 设备控制
- [Command(requiresAuthority = false)]
- public void CmdSendMessageMoNI(string cMDDataJson)
- {//模拟来协同服务器的消息
- OnlineCtrl.Instance.OnWebSocketMsgReceiveMoNi(cMDDataJson);
- }
- #endregion
- #region 灯
- List<MeshRenderer> meshRenderers;
- Color oldEmissionColor;
- Dictionary<string, GameObject> dicDeng;
- private void InitDeng()
- {
- meshRenderers = new List<MeshRenderer>();
- meshRenderers.Add(GameObject.Find("SceneStatic/Chezhan_fangti_static/Chezhan_fangti_static/polySurface4884").GetComponent<MeshRenderer>());
- var root = GameObject.Find("SceneStatic/Chezhan_light_static/Chezhan_light_static/zhantai");
- int count = root.transform.childCount;
- for (int i = 0; i < count; i++)
- {
- MeshRenderer renderer = root.transform.GetChild(i).GetComponent<MeshRenderer>();
- meshRenderers.Add(renderer);
- }
- oldEmissionColor = meshRenderers[0].material.GetColor("_EmissionColor");
- dicDeng = new Dictionary<string, GameObject>();
- var rootDeng = GameObject.Find($"灯控制");
- for (int i = 0; i < rootDeng.transform.childCount; i++)
- {
- var child = rootDeng.transform.GetChild(i);
- dicDeng[child.name] = child.gameObject;
- child.gameObject.SetActive(false);
- }
- }
- [Command(requiresAuthority = false)]
- public void CmdDeng(string position, bool v)
- {
- RpcDeng(position, v);
- }
- [ClientRpc]
- public void RpcDeng(string position, bool v)
- {
- dicDeng[position].SetActive(!v);
- for (int i = 0; i < meshRenderers.Count; i++)
- {
- meshRenderers[0].material.SetColor("_EmissionColor", v ? oldEmissionColor : Color.black);
- }
- }
- #endregion
- }
- }
|