Пример #1
0
        private static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
        {
            m_resolvers.Clear();

            ProcessPaths(importedAssets, m_sources, m_resolvers);
            ProcessPaths(deletedAssets, m_sources, m_resolvers);
            ProcessPaths(movedAssets, m_sources, m_resolvers);

            foreach (string resolverPath in m_resolvers)
            {
                if (Utf8JsonResolverAssetEditorUtility.CanGenerateResolver(resolverPath))
                {
                    Utf8JsonResolverAssetEditorUtility.GenerateResolver(resolverPath);
                }
            }
        }
        public override void OnInspectorGUI()
        {
            SerializedProperty propertyResolverName      = extraDataSerializedObject.FindProperty("m_info.m_resolverName");
            SerializedProperty propertyDestinationSource = extraDataSerializedObject.FindProperty("m_info.m_destinationSource");

            m_destinationPath             = Utf8JsonResolverAssetEditorUtility.GetDestinationSourcePath(m_importer.assetPath, propertyResolverName.stringValue, propertyDestinationSource.objectReferenceValue as TextAsset);
            m_destinationPathAnotherExist = propertyDestinationSource.objectReferenceValue == null && File.Exists(m_destinationPath);

            base.OnInspectorGUI();

            if (m_destinationPathAnotherExist)
            {
                string assetName = $"{propertyResolverName.stringValue}Asset";

                EditorGUILayout.Space();
                EditorGUILayout.HelpBox($"A file with the same name of the generate source already exists: '{assetName}'.\nPath: '{m_destinationPath}'.", MessageType.Warning);
            }
        }
        protected override bool OnApplyRevertGUI()
        {
            SerializedProperty propertyDestinationSource = extraDataSerializedObject.FindProperty("m_info.m_destinationSource");

            bool canClear    = File.Exists(m_destinationPath) && propertyDestinationSource.objectReferenceValue != null;
            bool canGenerate = Utf8JsonResolverAssetEditorUtility.CanGenerateResolver(m_importer.assetPath);

            using (new EditorGUI.DisabledScope(HasModified()))
            {
                if (GUILayout.Button("Generate All"))
                {
                    Utf8JsonResolverAssetEditorUtility.GenerateResolverAll();
                }

                using (new EditorGUI.DisabledScope(m_destinationPathAnotherExist || !canGenerate))
                {
                    if (GUILayout.Button("Generate"))
                    {
                        Utf8JsonResolverAssetEditorUtility.GenerateResolver(m_importer.assetPath);
                    }
                }

                using (new EditorGUI.DisabledScope(!canClear || !canGenerate))
                {
                    if (GUILayout.Button("Clear"))
                    {
                        if (EditorUtility.DisplayDialog("Delete Utf8Json Generated Script?", $"{m_destinationPath}\nYou cannot undo this action.", "Delete", "Cancel"))
                        {
                            Utf8JsonResolverAssetEditorUtility.ClearResolver(m_importer.assetPath);
                        }
                    }
                }
            }

            return(base.OnApplyRevertGUI());
        }