com.xmobitea.changx.mini-autogenerate
v1.5.2
Published
XmobiTea Unity Toolkit packages
Readme
XmobiTea AutoGenerate
Editor-only Unity helper package for writing generated text files and normalizing names into restricted ASCII tokens that callers can reuse in generated code.
AI Entry Points
Use the smallest file for the task.
| Need | Use |
| --- | --- |
| Generate editor code or sanitize a constant name | AI_USAGE.md |
| Exact signatures, namespace, assembly, menu/MCP availability | AI_API_REFERENCE.md |
| Path, overwrite, refresh, and sanitization edge cases | AI_BEHAVIOR.md |
| Package-level rules and maintenance checklist | AGENTS.md |
| Missing or conflicting detail | Editor/AutoGenerate.cs |
Core Contract
- Editor-only; do not reference from Runtime/player code.
- Namespace:
XmobiTea.MiniAutoGenerate.Editor. - Main class:
AutoGenerate. - Public methods:
GenerateFile(string fileName, StringBuilder contentBuilder, string fullPath)GetConstantName(string name)
GenerateFile(...)createsfullPathwhen needed, then writes caller-provided content tofullPath + fileName.GenerateFile(...)deletes any existing target before writing the new file, so a failed write can leave the target missing or partially recreated.GenerateFile(...)refreshes the AssetDatabase only after a successful write.GetConstantName(...)keeps only ASCII letters/digits and may prepend_.GetConstantName(...)does not preserve_, does not handle C# keywords, and does not prevent collisions after normalization.- No scene setup, settings asset, menu item, editor window, runtime pipeline, or MCP Unity server entrypoint.
Common Calls
using System.Text;
using UnityEditor;
using UnityEngine;
using XmobiTea.MiniAutoGenerate.Editor;
public static class ExampleGenerator
{
[MenuItem("Tools/Generate ExampleIds.cs")]
public static void Generate()
{
var contentBuilder = new StringBuilder();
contentBuilder.AppendLine("public static class ExampleIds");
contentBuilder.AppendLine("{");
contentBuilder.AppendLine("\tpublic const string Demo = \"Demo\";");
contentBuilder.AppendLine("}");
AutoGenerate.GenerateFile(
"ExampleIds.cs",
contentBuilder,
Application.dataPath + "/XmobiTea-constant/Scripts/");
}
}using XmobiTea.MiniAutoGenerate.Editor;
string id = AutoGenerate.GetConstantName("123 Player-Name");
// "_123PlayerName"string keyword = AutoGenerate.GetConstantName("class");
// "class" -- still a C# keyword, so callers generating members must handle this caseSource Files
| File | Purpose |
| --- | --- |
| Editor/AutoGenerate.cs | editor-only helper implementation |
| Editor/com.xmobitea.changx.mini-autogenerator.editor.asmdef | editor-only assembly definition |
Package Metadata
- Package name:
com.xmobitea.changx.mini-autogenerate - Editor assembly:
com.xmobitea.changx.mini-autogenerator.editor - Unity version:
2022.3+ - License:
Apache-2.0
Hard No
- Do not call from runtime assemblies.
- Do not omit the trailing separator in
fullPath. - Do not expect delete-then-write behavior to preserve the old file when generation fails.
- Do not expect underscores, symbols, or non-ASCII letters to survive
GetConstantName(...). - Do not expect
GetConstantName(...)to produce a unique or keyword-safe C# member name by itself. - Do not treat this as a full code-generation framework.
