示例#1
0
        private static string OnGeneratedCSProject(string path, string content)
        {
            // Find asmdef.
            var assemblyName = Path.GetFileNameWithoutExtension(path);
            var asmdefPath   = AssetDatabase.FindAssets("t:AssemblyDefinitionAsset " + Path.GetFileNameWithoutExtension(path))
                               .Select(x => AssetDatabase.GUIDToAssetPath(x))
                               .FirstOrDefault(x => Path.GetFileName(x) == assemblyName + ".asmdef");

            Core.LogDebug("<color=orange>OnGeneratedCSProject</color> {0} -> {1} ({2})", path, assemblyName, asmdefPath);
            var setting = CscSettingsAsset.GetAtPath(asmdefPath) ?? CscSettingsAsset.instance;

            // Modify define symbols.
            var defines = Regex.Match(content, "<DefineConstants>(.*)</DefineConstants>").Groups[1].Value.Split(';', ',');

            defines = Core.ModifyDefineSymbols(defines, setting.AdditionalSymbols);
            var defineText = string.Join(";", defines);

            content = Regex.Replace(content, "<DefineConstants>(.*)</DefineConstants>", string.Format("<DefineConstants>{0}</DefineConstants>", defineText), RegexOptions.Multiline);

            // Language version.
            if (!setting.UseDefaultCompiler)
            {
                content = Regex.Replace(content, "<LangVersion>.*</LangVersion>", "<LangVersion>" + setting.LanguageVersion + "</LangVersion>", RegexOptions.Multiline);
            }

            // Enable nullable.
            if (setting.EnableNullable)
            {
                content = Regex.Replace(content, "(\\s+)(<LangVersion>.*</LangVersion>)([\r\n]+)", "$1$2$3$1<Nullable>enable</Nullable>$3");
            }

            return(content);
        }
示例#2
0
        private static void OnPostHeaderGUI(Editor editor)
        {
            var importer = editor.target as AssemblyDefinitionImporter;

            if (!importer || 1 < editor.targets.Length || _ignoredAssetPaths.Contains(importer.assetPath))
            {
                return;
            }

            if (_assetPath == null || _assetPath != importer.assetPath)
            {
                _assetPath        = importer.assetPath;
                _serializedObject = new SerializedObject(CscSettingsAsset.CreateFromJson(importer.userData));
                _hasPortableDll   = Core.HasPortableDll(importer.assetPath);
                _changed          = false;
            }

            // Enable.
            EditorGUILayout.BeginVertical(EditorStyles.helpBox);
            EditorGUI.BeginChangeCheck();
            _hasPortableDll = EditorGUILayout.ToggleLeft(s_EnableText, _hasPortableDll, EditorStyles.boldLabel);
            if (_hasPortableDll)
            {
                var spCompilerType = _serializedObject.FindProperty("m_CompilerType");
                EditorGUILayout.PropertyField(spCompilerType);

                if (spCompilerType.intValue == (int)CompilerType.CustomPackage)
                {
                    EditorGUI.indentLevel++;
                    EditorGUILayout.PropertyField(_serializedObject.FindProperty("m_PackageName"));
                    EditorGUILayout.PropertyField(_serializedObject.FindProperty("m_PackageVersion"));
                    EditorGUILayout.PropertyField(_serializedObject.FindProperty("m_LanguageVersion"));
                    EditorGUILayout.PropertyField(_serializedObject.FindProperty("m_EnableNullable"));
                    EditorGUI.indentLevel--;
                }

                EditorGUILayout.PropertyField(_serializedObject.FindProperty("m_ModifySymbols"));
            }

            _changed |= EditorGUI.EndChangeCheck();

            // Controls
            using (new GUILayout.HorizontalScope())
            {
                GUILayout.FlexibleSpace();

                using (new EditorGUI.DisabledScope(!_changed))
                {
                    if (GUILayout.Button(s_RevertText))
                    {
                        _assetPath = null;
                    }

                    if (GUILayout.Button(s_ApplyText))
                    {
                        _assetPath = null;
                        _serializedObject.ApplyModifiedProperties();
                        importer.userData = JsonUtility.ToJson(_serializedObject.targetObject);
                        importer.SaveAndReimport();

                        if (_hasPortableDll != Core.HasPortableDll(importer.assetPath))
                        {
                            EnablePortableDll(importer.assetPath, _hasPortableDll);
                        }
                    }
                }

                using (new EditorGUI.DisabledScope(!_hasPortableDll))
                {
                    if (GUILayout.Button(s_ReloadText))
                    {
                        _assetPath = null;
                        EnablePortableDll(importer.assetPath, true);
                        AutoImporter.ImportOnFinishedCompilation(importer.assetPath);
                    }
                }

                if (GUILayout.Button(s_PublishText))
                {
                    _assetPath              = null;
                    s_AsmdefPathToPublish   = importer.assetPath;
                    s_AssemblyNameToPublish = Core.GetAssemblyName(importer.assetPath);
                    Core.LogInfo("<b><color=#22aa22>Request to publish dll:</color> {0}</b>", s_AssemblyNameToPublish);

                    importer.SaveAndReimport();
                }
            }

            EditorGUILayout.EndVertical();
        }