public void SaveCurrentType(bool warning = false, string baseType = null) { // Verify properties list for (var i = 0; i < _selectedProperties.Length; i++) { CustomPropertyInfo property = _selectedProperties[i]; if (string.IsNullOrEmpty(property.Name) || char.IsNumber(property.Name[0])) { property.Name = ""; if (warning) { EditorUtility.DisplayDialog("Save script error", "Property name cannot be a digit, null or empty!", "OK"); } return; } for (var j = 0; j < _selectedProperties.Length; j++) { if (j != i && _selectedProperties[i].Name.ToLower() == _selectedProperties[j].Name.ToLower()) { _selectedProperties[j].Name = ""; if (warning) { EditorUtility.DisplayDialog("Save script error", "There are one or more properties are have the same name!", "OK"); } return; } } } if (baseType == null) { baseType = _selectedType.BaseType.Name; } var inheritance = baseType == nameof(ObservableModel) ? $" : {baseType}" : string.Empty; if (!string.IsNullOrEmpty(_currentScriptPath)) { var backupCode = UIManCodeGenerator.DeleteScript(_handlerScriptPath); var code = UIManCodeGenerator.GenerateType(_selectedType.Name, inheritance, _selectedTypeIsSealed, _config, this.namespaceField.Text, _selectedProperties); var saved = UIManCodeGenerator.SaveScript(_currentScriptPath, code, true); if (baseType != nameof(ObservableModel)) { GenerateHandler(backupCode, baseType); saved = false; } if (saved) { AssetDatabase.Refresh(ImportAssetOptions.Default); } } }
public void GenerateType() { if (this.typeName.Contains(" ")) { EditorUtility.DisplayDialog("Error", "Class name cannot constain special characters", "OK"); return; } var warn = false; if (this.typeName.Length <= 1 || (!this.typeName.Substring(0, 2).Equals("UI") && !this.baseTypePopup.SelectedItem.Equals(UIGenerator.GetSupportTypeName(0)))) { this.typeName = "UI" + this.typeName; warn = true; } this.baseType = this.baseTypePopup.SelectedItem; var config = EditorHelper.GetOrCreateScriptableObject <UIManConfig>(false); var savePath = ""; if (this.baseType.Equals(UIGenerator.GetSupportTypeName(0))) { savePath = config.modelScriptFolder; config.generatingTypeIsDialog = false; } else if (this.baseType.Equals(UIGenerator.GetSupportTypeName(1))) { savePath = config.screenScriptFolder; config.generatingTypeIsDialog = false; } else if (this.baseType.Equals(UIGenerator.GetSupportTypeName(2))) { savePath = config.dialogScriptFolder; config.generatingTypeIsDialog = true; } savePath = Application.dataPath + "/" + savePath + "/" + this.typeName + ".cs"; if (File.Exists(savePath) || UIGenerator.IsViewModelExisted(this.typeName)) { EditorUtility.DisplayDialog("Error", "A class of the same name has already existed", "OK"); return; } var paths = Regex.Split(savePath, "/"); var inheritance = string.Empty; if (this.baseType != this.arrSupportType[0]) { config.generatingType = this.typeName; } else { inheritance = $" : {this.baseType}"; } var code = UIManCodeGenerator.GenerateType(this.typeName, inheritance, false, config, this.namespaceField.Text); UIManCodeGenerator.SaveScript(savePath, code, true); if (this.baseType != this.arrSupportType[0]) { GenerateHandler(savePath); } AssetDatabase.Refresh(ImportAssetOptions.Default); if (warn) { UnuLogger.LogWarning("Code generation warning: Class name is invalid. New name is generated."); } Close(); }