Reupload to git vps.
This commit is contained in:
commit
922d38ee51
5 changed files with 156 additions and 0 deletions
8
Editor.meta
Normal file
8
Editor.meta
Normal file
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 1ef57e1dadf599b4ba71061a638fd258
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
126
Editor/DictionaryProcessorWindow.cs
Normal file
126
Editor/DictionaryProcessorWindow.cs
Normal file
|
@ -0,0 +1,126 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
public class DictionaryProcessorWindow : EditorWindow
|
||||
{
|
||||
private int _filteredWordCount;
|
||||
private int _maxWordLength = 6;
|
||||
private int _minWordLength = 3;
|
||||
private int _originalWordCount;
|
||||
private string _outputFileName = "FilteredDictionary";
|
||||
private string _previewText = "";
|
||||
private Vector2 _scrollPosition;
|
||||
private TextAsset _sourceFile;
|
||||
|
||||
private void OnGUI()
|
||||
{
|
||||
GUILayout.Label("Dictionary Processing Tool", EditorStyles.boldLabel);
|
||||
|
||||
EditorGUILayout.Space();
|
||||
|
||||
_sourceFile = (TextAsset)EditorGUILayout.ObjectField("Source Dictionary",
|
||||
_sourceFile, typeof(TextAsset), false);
|
||||
|
||||
EditorGUILayout.Space();
|
||||
|
||||
GUILayout.Label("Filtering Options", EditorStyles.boldLabel);
|
||||
_minWordLength = EditorGUILayout.IntSlider("Min Word Length", _minWordLength, 1, 10);
|
||||
_maxWordLength = EditorGUILayout.IntSlider("Max Word Length", _maxWordLength, 1, 15);
|
||||
|
||||
EditorGUILayout.Space();
|
||||
|
||||
GUILayout.Label("Output Settings", EditorStyles.boldLabel);
|
||||
_outputFileName = EditorGUILayout.TextField("Output File Name", _outputFileName);
|
||||
|
||||
EditorGUILayout.Space();
|
||||
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
if (GUILayout.Button("Preview")) PreviewFiltering();
|
||||
|
||||
GUI.enabled = _sourceFile;
|
||||
if (GUILayout.Button("Process & Save")) ProcessAndSave();
|
||||
GUI.enabled = true;
|
||||
EditorGUILayout.EndHorizontal();
|
||||
|
||||
if (_originalWordCount > 0)
|
||||
{
|
||||
EditorGUILayout.Space();
|
||||
EditorGUILayout.LabelField($"Original: {_originalWordCount:N0} words");
|
||||
EditorGUILayout.LabelField(
|
||||
$"Filtered: {_filteredWordCount:N0} words ({(float)_filteredWordCount / _originalWordCount * 100:F1}% kept)");
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(_previewText))
|
||||
{
|
||||
EditorGUILayout.Space();
|
||||
GUILayout.Label("Preview (first 50 words):", EditorStyles.boldLabel);
|
||||
_scrollPosition = EditorGUILayout.BeginScrollView(_scrollPosition, GUILayout.Height(200));
|
||||
EditorGUILayout.TextArea(_previewText, GUILayout.ExpandHeight(true));
|
||||
EditorGUILayout.EndScrollView();
|
||||
}
|
||||
}
|
||||
|
||||
[MenuItem("Tools/Dictionary Processor")]
|
||||
public static void ShowWindow()
|
||||
{
|
||||
GetWindow<DictionaryProcessorWindow>("Dictionary Processor");
|
||||
}
|
||||
|
||||
private void PreviewFiltering()
|
||||
{
|
||||
if (!_sourceFile) return;
|
||||
|
||||
var filteredWords = ProcessWords(_sourceFile.text);
|
||||
_originalWordCount = _sourceFile.text.Split('\n').Length;
|
||||
_filteredWordCount = filteredWords.Count;
|
||||
|
||||
_previewText = string.Join("\n", filteredWords.Take(50));
|
||||
if (filteredWords.Count > 50)
|
||||
_previewText += $"\n... and {filteredWords.Count - 50} more words";
|
||||
}
|
||||
|
||||
private void ProcessAndSave()
|
||||
{
|
||||
if (!_sourceFile) return;
|
||||
|
||||
var filteredWords = ProcessWords(_sourceFile.text);
|
||||
|
||||
var outputPath = Path.Combine(Application.dataPath, "StreamingAssets", $"{_outputFileName}.txt");
|
||||
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(outputPath) ?? throw new NullReferenceException("Invalid path"));
|
||||
|
||||
File.WriteAllText(outputPath, string.Join("\n", filteredWords));
|
||||
|
||||
AssetDatabase.Refresh();
|
||||
|
||||
Debug.Log($"Dictionary processed! {filteredWords.Count} words saved to: {outputPath}");
|
||||
|
||||
_originalWordCount = _sourceFile.text.Split('\n').Length;
|
||||
_filteredWordCount = filteredWords.Count;
|
||||
}
|
||||
|
||||
private List<string> ProcessWords(string text)
|
||||
{
|
||||
var words = text.Split(new[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
var filteredWords = new List<string>();
|
||||
|
||||
foreach (var rawWord in words)
|
||||
{
|
||||
var word = rawWord.Trim().ToLowerInvariant();
|
||||
|
||||
if (word.Length < _minWordLength || word.Length > _maxWordLength)
|
||||
continue;
|
||||
|
||||
if (!Regex.IsMatch(word, @"^[a-z]+$"))
|
||||
continue;
|
||||
|
||||
filteredWords.Add(word);
|
||||
}
|
||||
return filteredWords.Distinct().OrderBy(w => w).ToList();
|
||||
}
|
||||
}
|
2
Editor/DictionaryProcessorWindow.cs.meta
Normal file
2
Editor/DictionaryProcessorWindow.cs.meta
Normal file
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: a7ebd227f3b8fbb4b9723d3f17cc1c43
|
13
package.json
Normal file
13
package.json
Normal file
|
@ -0,0 +1,13 @@
|
|||
{
|
||||
"name": "com.danielcumbor.dictionaryprocessor",
|
||||
"version": "1.0.0",
|
||||
"displayName": "DC Dictionary Processor",
|
||||
"description": "A custom Unity tool window for filtering dictionaries.",
|
||||
"unity": "6000.0",
|
||||
"unityRelease": "23f1",
|
||||
"author": {
|
||||
"name": "Daniel Cumbor",
|
||||
"email": "danc@ultr.uk",
|
||||
"url": "https://www.danielcumbor.uk"
|
||||
}
|
||||
}
|
7
package.json.meta
Normal file
7
package.json.meta
Normal file
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 71f47fb424c5a4e45a5a8bdb452ac2fa
|
||||
PackageManifestImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
Reference in a new issue