using System.Collections.Generic; using System.Linq; using TyphoonFormatCSharp; using TyphoonGUIStyle; using UnityEditor; using UnityEngine; namespace TyphoonUI { [CustomEditor(typeof(UIObject))] [CanEditMultipleObjects] public class UIObjectEditor : Editor { private UIObject Target => target as UIObject; public override void OnInspectorGUI() { GUILayout.Space(5); GUILayout.BeginHorizontal(); if (GUILayout.Button("导出代码", Styles.BtnGreen, GUILayout.Height(32))) { ExportCode(); } GUILayout.Space(3); if (GUILayout.Button("应用&更新", Styles.BtnGreen, GUILayout.Height(32))) { Apply(); } GUILayout.EndHorizontal(); GUILayout.Space(5); UIObjectGUIDrawer.DrawGUI(Target); Repaint(); } private void ExportCode() { var objects = Selection.gameObjects; var matches = new HashSet(); foreach (var o in objects) { var view = o.GetComponent(); if (view != null) { matches.Add(view); } } var paths = new List(); foreach (var match in matches) { paths.Add(match.ExportCode(false)); } FormatCSharp.Format(Paths.ExportCodeFolder, () => { AssetDatabase.Refresh(); TyphoonUIEditor.PingObject(paths.Last()); Debug.Log("导出成功!"); }); } private void Apply() { var objects = Selection.gameObjects; var matches = new HashSet(); foreach (var o in objects) { var view = o.GetComponent(); if (view != null) { matches.Add(view); } } foreach (var match in matches) { match.Apply(); } } } }