using System; using System.Collections; using System.Collections.Generic; using System.IO; using UnityEditor; using UnityEngine; using Newtonsoft.Json; /// /// /// public class EquipmentAttrubeConfig : EditorWindow { [MenuItem("Tools/设备属性配置")] static void EquipmentConfigWindow() { var window = (EquipmentAttrubeConfig)EditorWindow.GetWindow(typeof(EquipmentAttrubeConfig), true, "属性配置"); window.Show(); } private void OnGUI() { if (GUILayout.Button("Set")) { OnSet(); } if (GUILayout.Button("Power")) { OnPowerSet(); } } private void OnPowerSet() { var list = new List(); foreach (var go in Selection.gameObjects) { var data = new PowerAttributeConfig(); data.id = go.name; if (go.GetComponent()) { data.isBoxcollider = true; data.boxColliderCenter = go.GetComponent().center; data.boxColliderSize = go.GetComponent().size; } if (go.GetComponent()) data.isMeshCollider = true; data.createMode = go.GetComponent().PowerMode; data.taskType = go.GetComponent().taskType; if (go.GetComponent()) data.isFiremanController = true; if (go.GetComponent()) data.isShuiGuanCheController = true; if (go.GetComponent()) data.isGaoPenCheController = true; if (go.GetComponent()) data.isDenGaoCheController = true; if (go.GetComponent()) data.isYunTiCheController = true; if (go.GetComponent()) data.isAreaController = true; if (go.GetComponent()) data.isLT6Controller = true; if (go.GetComponent()) data.isLT15Controller = true; if (go.GetComponent()) data.isWaterMonitorController = true; if (go.GetComponent()) data.isZhaoMingCheController = true; if (go.transform.Find("Info")) data.isInfo = true; list.Add(data); } Debug.Log(list.Count); var json = JsonConvert.SerializeObject(list, Formatting.Indented); var path = $"{Application.streamingAssetsPath}/Config/PowerAttributeConfig.json"; Debug.Log(json); File.WriteAllText(path, json); } private void OnSet() { var list = new List(); foreach(var go in Selection.gameObjects) { var data = new EquipmentAttributeConfig(); data.Id = go.name; if (go.GetComponent()) { data.IsBoxCollider = true; data.BoxColliderCenter = go.GetComponent().center; data.BoxColliderSize = go.GetComponent().size; } else { data.IsBoxCollider = false; } if (go.GetComponent()) data.IsMeshCollider = true; else { data.IsMeshCollider = false; } data.Type = go.GetComponent().equipmentType; if (go.GetComponent()) data.IsEquipmentDataListening = true; data.ufIconName = go.GetComponent().IconName; data.ufDistanceY = go.GetComponent().DistanceY; data.ufChangeFloor = go.GetComponent().ChangeFloor; data.ufFloorNumber = go.GetComponent().FloorNumber; list.Add(data); } Debug.Log(list.Count); var json = JsonConvert.SerializeObject(list, Formatting.Indented); var path = $"{Application.streamingAssetsPath}/Config/EquipmentAttributeConfig.json"; Debug.Log(json); File.WriteAllText(path,json); } }