using AX.ImageViewer; using System; using System.Collections.Generic; using UniRx; using UnityEngine; using UnityEngine.UI; public class NodeController : MonoBehaviour { public Toggle LoadToggle; public Button SaveButton; public Button ImageButton; public Button DeleteButton; public OpenImage OpenImageFile; public string ImageUrl; public Sprite defaultSprite; //public PlanController planController; // Start is called before the first frame update void Start() { //保存节点 SaveButton.OnClickAsObservable() .Subscribe(_ => { SaveNode(); MessageBox.Show($"{PowerManager.Instance.PlanName}-{name} 保存成功!",Color.white,3f); }).AddTo(gameObject); //加载节点 LoadToggle.onValueChanged.AddListener((bool value) => { LoadValueChanged(value); ImageButton.interactable = value; SaveButton.interactable = value; ImageButton.GetComponent().raycastTarget = value; }); //删除节点 DeleteButton.OnClickAsObservable() .Subscribe(_ => MessageBox.Show($"确认删除 {PowerManager.Instance.PlanName}-{name}?", Color.white, DeleteNode)).AddTo(gameObject); //插入图片 OpenImageFile.OnLoadTextureFinished = texture => { UploadImage(texture); }; } private void UploadImage(Texture2D texture) { HttpManager.Instance.PostImage($"{Uri.EscapeDataString(PowerManager.Instance.PlanName)}{Uri.EscapeDataString(name)}.jpg", texture, a => { ImageUrl = a?.ObjectName; }); } private void LoadValueChanged(bool value) { if (value) { PowerManager.Instance.ClearAll(); LoadNode(); } else { PowerManager.Instance.ClearAll(); ImageViewer.Instance.Hide(); } } private void LoadNode() { var planName = PowerManager.Instance.planController.name; var nodeName = name; var plan =UIManager.Instance.GetView().Plans.Find(a => a.Name == planName); var node = plan.Nodes.Find(n => n.Name == nodeName); HttpManager.Instance.GetFile(node.Id, actionResult => { Debug.Log(actionResult); //摄影机 AssetManager.Instance.MainCamera.GetComponent().target.localPosition = actionResult.PivotPos; AssetManager.Instance.MainCamera.transform.localPosition = actionResult.MainCamera.Position; AssetManager.Instance.MainCamera.transform.localEulerAngles = actionResult.MainCamera.Rotation; AssetManager.Instance.MainCamera.GetComponent().distance = actionResult.MainCamera.Distance; AssetManager.Instance.MainCamera.GetComponent().x = actionResult.MainCamera.XY.x; AssetManager.Instance.MainCamera.GetComponent().y = actionResult.MainCamera.XY.y; //按钮名称 ImageButton.gameObject.name = actionResult.ImageButtonName; //楼层 int i = 0; foreach (var item in actionResult.Floors) { if (AssetManager.Instance.Floors[i].gameObject.name == item.Id) { AssetManager.Instance.Floors[i].GetComponent().isOn = item.IsOn; } i++; } if (!string.IsNullOrEmpty(actionResult.ImageUrl)) { HttpManager.Instance.GetImage(actionResult.ImageUrl, texture => { ImageViewer.Load(texture); }); } //powers SpawnPowers(actionResult.Powers); }); } private async void SpawnPowers(List Powers) { foreach(var item in Powers) { //yield return new WaitForSeconds(0.01f); //GameObject power = Instantiate(AssetManager.Instance.Powers.Find(p => p.name == item.Id)) as GameObject; GameObject power; if (item.Name.Contains("Fire") || item.Name.Contains("Smoke")) { var prefab = AssetManager.Instance.powerEffacts.Find(go => go.name == item.Id); power = Instantiate(prefab) as GameObject; } else power = await PowerPool.Instance.GetPower(item.Id, Vector3.zero, Quaternion.identity, null); power.name = item.Name; if (item.Parent.Contains("|")) { GameObject PowerGroup = GameObject.Find(item.Parent); string[] m_parents = item.Parent.Split('|'); if (PowerGroup == null) { PowerGroup = new GameObject(); PowerGroup.transform.parent = PowerManager.Instance.transform.Find(m_parents[0]); PowerGroup.name = item.Parent; } power.transform.parent = PowerGroup.transform; } else { power.transform.parent = PowerManager.Instance.transform.Find(item.Parent); } power.transform.localPosition = item.Position; power.transform.localRotation = Quaternion.Euler(item.Rotation); power.transform.localScale = item.Scale; power.SetActive(item.isActive); SelectionManager.Instance.Sets.Add(power); if (power.transform.Find("Info/Task")) power.transform.Find("Info/Task").GetComponent().text = item.Attribute.Task; if (power.transform.Find("Info/Name")) power.transform.Find("Info/Name").GetComponent().text = item.Attribute.Name; if (item.Attribute != null) power.GetComponent().Remarks = item.Attribute.Remarks; //消防员 if (power.GetComponent()) { power.GetComponent().speed = item.Hose.HoseValue; power.GetComponent().waterGun.transform.localRotation = Quaternion.Euler(item.Hose.HoseRotation); } #region 车辆控制 //水罐车、泡沫车、超高层供水车 if (power.GetComponent()) { power.GetComponent().speed = item.Hose.HoseValue; power.GetComponent().waterGun.transform.localRotation = Quaternion.Euler(item.Hose.HoseRotation); } //照明车 if (power.GetComponent()) { power.GetComponent().Arm.transform.localRotation = Quaternion.Euler(item.ZhaoMingChe.ArmRotation); power.GetComponent().Light.transform.localRotation = Quaternion.Euler(item.ZhaoMingChe.LightRotation); } //高喷车 if (power.GetComponent()) { power.GetComponent().isInit = false; var animator = power.GetComponent(); power.GetComponent().speed = item.Truck.HoseValue; power.GetComponent().part1.transform.localPosition = item.Truck.Part1Pos; power.GetComponent().part1.transform.localRotation = Quaternion.Euler(item.Truck.Part1Rot); power.GetComponent().part2.transform.localPosition = item.Truck.Part2Pos; power.GetComponent().part2.transform.localRotation = Quaternion.Euler(item.Truck.Part2Rot); power.GetComponent().part3.transform.localPosition = item.Truck.Part3Pos; power.GetComponent().part3.transform.localRotation = Quaternion.Euler(item.Truck.Part3Rot); power.GetComponent().part4.transform.localPosition = item.Truck.Part4Pos; power.GetComponent().part4.transform.localRotation = Quaternion.Euler(item.Truck.Part4Rot); power.GetComponent().part5.transform.localPosition = item.Truck.Part5Pos; power.GetComponent().part5.transform.localRotation = Quaternion.Euler(item.Truck.Part5Rot); power.GetComponent().part6.transform.localPosition = item.Truck.Part6Pos; power.GetComponent().part6.transform.localRotation = Quaternion.Euler(item.Truck.Part6Rot); power.GetComponent().part7.transform.localPosition = item.Truck.Part7Pos; power.GetComponent().part7.transform.localRotation = Quaternion.Euler(item.Truck.Part7Rot); power.GetComponent().waterGun.transform.localPosition = item.Truck.Part8Pos; power.GetComponent().waterGun.transform.localRotation = Quaternion.Euler(item.Truck.Part8Rot); } //登高平台车 if (power.GetComponent()) { power.GetComponent().isInit = false; power.GetComponent().speed = item.Truck.HoseValue; power.GetComponent().part1.transform.localPosition = item.Truck.Part1Pos; power.GetComponent().part1.transform.localRotation = Quaternion.Euler(item.Truck.Part1Rot); power.GetComponent().part2.transform.localPosition = item.Truck.Part2Pos; power.GetComponent().part2.transform.localRotation = Quaternion.Euler(item.Truck.Part2Rot); power.GetComponent().part3.transform.localPosition = item.Truck.Part3Pos; power.GetComponent().part3.transform.localRotation = Quaternion.Euler(item.Truck.Part3Rot); power.GetComponent().part4.transform.localPosition = item.Truck.Part4Pos; power.GetComponent().part4.transform.localRotation = Quaternion.Euler(item.Truck.Part4Rot); power.GetComponent().part5.transform.localPosition = item.Truck.Part5Pos; power.GetComponent().part5.transform.localRotation = Quaternion.Euler(item.Truck.Part5Rot); power.GetComponent().part6.transform.localPosition = item.Truck.Part6Pos; power.GetComponent().part6.transform.localRotation = Quaternion.Euler(item.Truck.Part6Rot); power.GetComponent().part7.transform.localPosition = item.Truck.Part7Pos; power.GetComponent().part7.transform.localRotation = Quaternion.Euler(item.Truck.Part7Rot); power.GetComponent().waterGun.transform.localPosition = item.Truck.Part8Pos; power.GetComponent().waterGun.transform.localRotation = Quaternion.Euler(item.Truck.Part8Rot); } //云梯车 if (power.GetComponent()) { power.GetComponent().isInit = false; var animator = power.GetComponent(); power.GetComponent().speed = item.Truck.HoseValue; power.GetComponent().part1.transform.localPosition = item.Truck.Part1Pos; power.GetComponent().part1.transform.localRotation = Quaternion.Euler(item.Truck.Part1Rot); power.GetComponent().part2.transform.localPosition = item.Truck.Part2Pos; power.GetComponent().part2.transform.localRotation = Quaternion.Euler(item.Truck.Part2Rot); power.GetComponent().part3.transform.localPosition = item.Truck.Part3Pos; power.GetComponent().part3.transform.localRotation = Quaternion.Euler(item.Truck.Part3Rot); power.GetComponent().part4.transform.localPosition = item.Truck.Part4Pos; power.GetComponent().part4.transform.localRotation = Quaternion.Euler(item.Truck.Part4Rot); power.GetComponent().part5.transform.localPosition = item.Truck.Part5Pos; power.GetComponent().part5.transform.localRotation = Quaternion.Euler(item.Truck.Part5Rot); power.GetComponent().part6.transform.localPosition = item.Truck.Part6Pos; power.GetComponent().part6.transform.localRotation = Quaternion.Euler(item.Truck.Part6Rot); power.GetComponent().part7.transform.localPosition = item.Truck.Part7Pos; power.GetComponent().part7.transform.localRotation = Quaternion.Euler(item.Truck.Part7Rot); power.GetComponent().part8.transform.localPosition = item.Truck.Part8Pos; power.GetComponent().part8.transform.localRotation = Quaternion.Euler(item.Truck.Part8Rot); power.GetComponent().waterGun.transform.localPosition = item.Truck.Part9Pos; power.GetComponent().waterGun.transform.localRotation = Quaternion.Euler(item.Truck.Part9Rot); } #endregion //区域设定 if (item.Id == "QuYuSheDing"|| item.Id == "JiJieQu") { power.GetComponent().mesh.vertices = item.Vertices.MeshVertices.ToArray(); power.GetComponent().mesh.RecalculateNormals(); power.GetComponent().sharedMesh = power.GetComponent().mesh; } //6米拉梯 if (power.GetComponent()) { power.GetComponent().ladder_6Up.transform.localPosition = item.Ladder.Position1; } //15米拉梯 if (power.GetComponent()) { power.GetComponent().ladder_15Up1.transform.localPosition = item.Ladder.Position1; power.GetComponent().ladder_15Up2.transform.localPosition = item.Ladder.Position2; } //水炮 if (power.GetComponent()) { power.GetComponent().speed = item.Hose.HoseValue; power.GetComponent().waterGun.transform.localRotation = Quaternion.Euler(item.Hose.HoseRotation); } } } public void SaveNode() { NodeFile nodeFile = new NodeFile { PivotPos = AssetManager.Instance.MainCamera.GetComponent().target.transform.localPosition, MainCamera = new CameraData { Position = AssetManager.Instance.MainCamera.transform.localPosition, Rotation = AssetManager.Instance.MainCamera.transform.localRotation.eulerAngles, Distance = AssetManager.Instance.MainCamera.GetComponent().distance, XY = new Vector2(AssetManager.Instance.MainCamera.GetComponent().x, AssetManager.Instance.MainCamera.GetComponent().y), }, ImageUrl = ImageUrl, ImageButtonName = ImageButton.gameObject.name, //楼层开关 Floors = new List() }; foreach (var floor in AssetManager.Instance.Floors) { var temp = new FloorNode() { Id = floor.gameObject.name, IsOn = floor.GetComponent().isOn }; nodeFile.Floors.Add(temp); } //power nodeFile.Powers = new List(); foreach (GameObject Power in SelectionManager.Instance.Sets) { PowerNode powerNode = new PowerNode { Name = Power.name, Id = Power.GetComponent().PrefabName, Parent = Power.transform.parent.name, Position = Power.transform.localPosition, Rotation = Power.transform.localRotation.eulerAngles, Scale = Power.transform.localScale, isActive = Power.activeSelf }; nodeFile.Powers.Add(powerNode); if (Power.GetComponent().taskType != TaskType.none) { powerNode.Attribute = new AttributeNode(); if (Power.transform.Find("Info/Name")) powerNode.Attribute.Name = Power.transform.Find("Info/Name").GetComponent().text; if (Power.transform.Find("Info/Task")) powerNode.Attribute.Task = Power.transform.Find("Info/Task").GetComponent().text; powerNode.Attribute.Remarks = Power.GetComponent().Remarks; } //六种消防员 if (Power.GetComponent()) { powerNode.Hose = new HoseNode { HoseValue = Power.GetComponent().speed, HoseRotation = Power.GetComponent().waterGun.transform.localRotation.eulerAngles }; } #region 车辆控制 //水罐车、泡沫车、超高层供水车 if (Power.GetComponent()) { powerNode.Hose = new HoseNode { HoseValue = Power.GetComponent().speed, HoseRotation = Power.GetComponent().waterGun.transform.localRotation.eulerAngles }; } //照明车 if (Power.GetComponent()) { powerNode.ZhaoMingChe = new ZhaoMingCheNode { ArmRotation = Power.GetComponent().Arm.transform.localRotation.eulerAngles, LightRotation = Power.GetComponent().Light.transform.localRotation.eulerAngles }; } //高喷车 if (Power.GetComponent()) { powerNode.Truck = new TruckNode { HoseValue = Power.GetComponent().speed, Part1Pos = Power.GetComponent().part1.transform.localPosition, Part2Pos = Power.GetComponent().part2.transform.localPosition, Part3Pos = Power.GetComponent().part3.transform.localPosition, Part4Pos = Power.GetComponent().part4.transform.localPosition, Part5Pos = Power.GetComponent().part5.transform.localPosition, Part6Pos = Power.GetComponent().part6.transform.localPosition, Part7Pos = Power.GetComponent().part7.transform.localPosition, Part8Pos = Power.GetComponent().waterGun.transform.localPosition, Part1Rot = Power.GetComponent().part1.transform.localRotation.eulerAngles, Part2Rot = Power.GetComponent().part2.transform.localRotation.eulerAngles, Part3Rot = Power.GetComponent().part3.transform.localRotation.eulerAngles, Part4Rot = Power.GetComponent().part4.transform.localRotation.eulerAngles, Part5Rot = Power.GetComponent().part5.transform.localRotation.eulerAngles, Part6Rot = Power.GetComponent().part6.transform.localRotation.eulerAngles, Part7Rot = Power.GetComponent().part7.transform.localRotation.eulerAngles, Part8Rot = Power.GetComponent().waterGun.transform.localRotation.eulerAngles }; } //登高平台车 if (Power.GetComponent()) { powerNode.Truck = new TruckNode { HoseValue = Power.GetComponent().speed, Part1Pos = Power.GetComponent().part1.transform.localPosition, Part2Pos = Power.GetComponent().part2.transform.localPosition, Part3Pos = Power.GetComponent().part3.transform.localPosition, Part4Pos = Power.GetComponent().part4.transform.localPosition, Part5Pos = Power.GetComponent().part5.transform.localPosition, Part6Pos = Power.GetComponent().part6.transform.localPosition, Part7Pos = Power.GetComponent().part7.transform.localPosition, Part8Pos = Power.GetComponent().waterGun.transform.localPosition, Part1Rot = Power.GetComponent().part1.transform.localRotation.eulerAngles, Part2Rot = Power.GetComponent().part2.transform.localRotation.eulerAngles, Part3Rot = Power.GetComponent().part3.transform.localRotation.eulerAngles, Part4Rot = Power.GetComponent().part4.transform.localRotation.eulerAngles, Part5Rot = Power.GetComponent().part5.transform.localRotation.eulerAngles, Part6Rot = Power.GetComponent().part6.transform.localRotation.eulerAngles, Part7Rot = Power.GetComponent().part7.transform.localRotation.eulerAngles, Part8Rot = Power.GetComponent().waterGun.transform.localRotation.eulerAngles }; } //云梯车 if (Power.GetComponent()) { powerNode.Truck = new TruckNode { HoseValue = Power.GetComponent().speed, Part1Pos = Power.GetComponent().part1.transform.localPosition, Part2Pos = Power.GetComponent().part2.transform.localPosition, Part3Pos = Power.GetComponent().part3.transform.localPosition, Part4Pos = Power.GetComponent().part4.transform.localPosition, Part5Pos = Power.GetComponent().part5.transform.localPosition, Part6Pos = Power.GetComponent().part6.transform.localPosition, Part7Pos = Power.GetComponent().part7.transform.localPosition, Part8Pos = Power.GetComponent().part8.transform.localPosition, Part9Pos = Power.GetComponent().waterGun.transform.localPosition, Part1Rot = Power.GetComponent().part1.transform.localRotation.eulerAngles, Part2Rot = Power.GetComponent().part2.transform.localRotation.eulerAngles, Part3Rot = Power.GetComponent().part3.transform.localRotation.eulerAngles, Part4Rot = Power.GetComponent().part4.transform.localRotation.eulerAngles, Part5Rot = Power.GetComponent().part5.transform.localRotation.eulerAngles, Part6Rot = Power.GetComponent().part6.transform.localRotation.eulerAngles, Part7Rot = Power.GetComponent().part7.transform.localRotation.eulerAngles, Part8Rot = Power.GetComponent().part8.transform.localRotation.eulerAngles, Part9Rot = Power.GetComponent().waterGun.transform.localRotation.eulerAngles }; } #endregion //区域设定 if (Power.GetComponent().PrefabName == "QuYuSheDing"|| Power.GetComponent().PrefabName == "JiJieQu") { powerNode.Vertices = new VerticesNode { MeshVertices = new List() }; foreach (Vector3 point in Power.GetComponent().mesh.vertices) { powerNode.Vertices.MeshVertices.Add(point); } } //水炮 if (Power.GetComponent().PrefabName == "ShuiPao") { powerNode.Hose = new HoseNode() { HoseValue = Power.GetComponent().speed, HoseRotation = Power.GetComponent().waterGun.transform.localRotation.eulerAngles }; } //6米拉梯 if (Power.GetComponent()) { powerNode.Ladder = new LadderNode() { Position1 = Power.GetComponent().ladder_6Up.transform.localPosition }; } //15米拉梯 if (Power.GetComponent()) { powerNode.Ladder = new LadderNode() { Position1 = Power.GetComponent().ladder_15Up1.transform.localPosition, Position2 = Power.GetComponent().ladder_15Up2.transform.localPosition }; } } var planName = PowerManager.Instance.planController.name; var nodeName = name; var fileName = $"{planName}-{nodeName}.nodeFile"; HttpManager.Instance.PostFile(fileName, nodeFile, actionResult => { var plan = UIManager.Instance.GetView().Plans.Find(a => a.Name == planName); var node = plan.Nodes.Find(n => n.Name == nodeName); node.Id = actionResult.ObjectName; UIManager.Instance.GetView().SavePlanList(); }); } private void DeleteNode() { var temp = UIManager.Instance.GetView().Plans.Find(a => a.Name == PowerManager.Instance.PlanName); var tempNode = temp.Nodes.Find(b => b.Name == name); temp.Nodes.Remove(tempNode); UIManager.Instance.GetView().SavePlanList(); Destroy(this.gameObject); } public void ClearImage() { OpenImageFile.GetComponent