void Update() { if (!m_waitingForCompilation) { return; } if (!EditorApplication.isCompiling) { var gameObject = (GameObject)EditorUtility.InstanceIDToObject(m_xmlLayoutInstanceId); var type = XmlLayoutUtilities.GetXmlLayoutControllerType(m_xmlLayoutControllerName); gameObject.AddComponent(type); m_waitingForCompilation = false; this.Close(); } }
void OnGUI() { float spaceRemaining = 74; var style = new GUIStyle(); style.margin = new RectOffset(10, 10, 10, 10); GUILayout.BeginVertical(style); // a) Choose whether or not to use an Xml file // i) Create a new one // ii) Use an existing one GUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Xml File", GUILayout.Width(200)); int xmlIndex = EditorGUILayout.Popup(xmlFileNames.IndexOf(xmlFileName), xmlFileNames.ToArray()); xmlFileName = xmlFileNames[xmlIndex]; GUILayout.EndHorizontal(); GUILayout.Space(4); if (xmlFileName == "Create New") { GUILayout.BeginHorizontal(); EditorGUILayout.LabelField("New Xml File Name", GUILayout.Width(200)); newXmlFileName = EditorGUILayout.TextField(newXmlFileName); GUILayout.EndHorizontal(); GUILayout.Space(4); spaceRemaining -= 20; } // b) Choose whether to use an XmlLayoutController // i) Create a new one // ii) Use an existing one GUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Xml Layout Controller", GUILayout.Width(200)); int index = EditorGUILayout.Popup(controllerNames.IndexOf(controllerName), controllerNames.ToArray()); controllerName = controllerNames[index]; GUILayout.EndHorizontal(); GUILayout.Space(4); if (controllerName == "Create New") { GUILayout.BeginHorizontal(); EditorGUILayout.LabelField("New Xml Layout Controller Name", GUILayout.Width(200)); newControllerName = EditorGUILayout.TextField(newControllerName); GUILayout.EndHorizontal(); GUILayout.Space(4); spaceRemaining -= 20; } EditorGUILayout.HelpBox("Both the 'Xml File' and 'Xml Layout Controller' fields are optional.", MessageType.Info); if (xmlFileName == "Create New" || controllerName == "Create New") { EditorGUILayout.HelpBox("Please be advised that the file(s) will be created in the Assets/ folder and will need to be manually moved to the folder(s) of your choice.", MessageType.Info); spaceRemaining -= 32; } // Buttons GUILayout.Space(spaceRemaining); if (GUILayout.Button("Add Xml Layout")) { if (xmlFileName == "Create New") { // Create the new xml file xmlFileName = XmlLayoutMenuItems.NewXmlLayoutXmlFile(newXmlFileName, false).Substring("Assets/".Length); AssetDatabase.Refresh(); } bool newController = false; if (controllerName == "Create New") { // Create the new controller file XmlLayoutMenuItems.NewXmlLayoutController(newControllerName, false).Substring("Assets/".Length); newController = true; } var xmlLayout = InstantiatePrefab("XmlLayout Prefabs/XmlLayout").GetComponent <XmlLayout>(); if (xmlFileName == "None") { // expand the xml editor by default xmlLayout.editor_showXml = true; } xmlLayout.name = "XmlLayout"; Selection.activeGameObject = xmlLayout.gameObject; if (xmlFileName != "None") { var xmlFile = AssetDatabase.LoadAssetAtPath <TextAsset>("Assets/" + xmlFileName); xmlLayout.XmlFile = xmlFile; xmlLayout.ReloadXmlFile(); } if (controllerName != "None") { if (!newController) { var controllerType = XmlLayoutUtilities.GetXmlLayoutControllerType(controllerName); if (controllerType != null) { xmlLayout.gameObject.AddComponent(controllerType); } } else { AssetDatabase.Refresh(); var window = EditorWindow.GetWindow <XmlLayoutSetControllerWindow>(); window.SetAction(xmlLayout.gameObject.GetInstanceID(), newControllerName); } } this.Close(); } if (GUILayout.Button("Cancel")) { this.Close(); } GUILayout.EndVertical(); }