Initial commit: Client Doc docs Server Tools
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
#if UNITY_EDITOR
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
public static class CharacterConfigGenerator
|
||||
{
|
||||
private const string ActorPrefabFolder = "Assets/Game/Art/Actor/Prefab";
|
||||
private const string ConfigPath = "Assets/Resources/Config/CharacterConfig.json";
|
||||
|
||||
[MenuItem("Tools/Character/Generate Character Config")]
|
||||
public static void Generate()
|
||||
{
|
||||
string[] prefabGuids = AssetDatabase.FindAssets("t:Prefab", new[] { ActorPrefabFolder });
|
||||
EditorCharacterConfigData config = new EditorCharacterConfigData();
|
||||
config.spawnPosition = Vector3.zero;
|
||||
config.spawnEuler = new Vector3(0f, 180f, 0f);
|
||||
|
||||
for (int i = 0; i < prefabGuids.Length; i++)
|
||||
{
|
||||
string path = AssetDatabase.GUIDToAssetPath(prefabGuids[i]);
|
||||
string id = Path.GetFileNameWithoutExtension(path);
|
||||
config.characters.Add(new EditorCharacterConfigItem
|
||||
{
|
||||
id = id,
|
||||
displayName = id,
|
||||
prefabPath = path
|
||||
});
|
||||
}
|
||||
|
||||
config.characters.Sort((left, right) => string.CompareOrdinal(left.id, right.id));
|
||||
if (config.characters.Count > 0)
|
||||
{
|
||||
config.defaultCharacterId = config.characters[0].id;
|
||||
}
|
||||
|
||||
string fullPath = Path.GetFullPath(Path.Combine(Application.dataPath, "../", ConfigPath));
|
||||
string directory = Path.GetDirectoryName(fullPath);
|
||||
if (!Directory.Exists(directory))
|
||||
{
|
||||
Directory.CreateDirectory(directory);
|
||||
}
|
||||
|
||||
File.WriteAllText(fullPath, JsonUtility.ToJson(config, true));
|
||||
AssetDatabase.Refresh();
|
||||
Debug.Log("Generated character config: " + ConfigPath + " (" + config.characters.Count + " characters)");
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
private class EditorCharacterConfigData
|
||||
{
|
||||
public string defaultCharacterId;
|
||||
public Vector3 spawnPosition;
|
||||
public Vector3 spawnEuler;
|
||||
public List<EditorCharacterConfigItem> characters = new List<EditorCharacterConfigItem>();
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
private class EditorCharacterConfigItem
|
||||
{
|
||||
public string id;
|
||||
public string displayName;
|
||||
public string prefabPath;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user