Skip to content

Instantly share code, notes, and snippets.

@dimmduh
Created February 4, 2019 10:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dimmduh/bd8c900c83c175964ccb92f03c51b39e to your computer and use it in GitHub Desktop.
Save dimmduh/bd8c900c83c175964ccb92f03c51b39e to your computer and use it in GitHub Desktop.
using System.Collections.Generic;
using System.IO;
using Newtonsoft.Json;
using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine;
public class ExportLocalization : MonoBehaviour {
[MenuItem("IO Games/Localization/Export")]
static void Export()
{
//remember
var startScenePath = EditorSceneManager.GetActiveScene().path;
var items = new List<LocalizationItem>();
foreach (var scene in EditorBuildSettings.scenes)
{
if (!scene.enabled)
continue;
EditorSceneManager.OpenScene(scene.path, OpenSceneMode.Single);
var comps = Resources.FindObjectsOfTypeAll<MyLocalization>();
foreach (var comp in comps)
{
var item = new LocalizationItem
{
textEn = comp.textEn,
textRu = comp.textRu,
textZh = comp.textZh ?? "",
scene = scene.path,
path = GetGameObjectPath(comp.transform),
};
items.Add(item);
}
}
//save
var json = JsonConvert.SerializeObject(items, Formatting.Indented);
File.WriteAllText(Application.dataPath + "/localization.json", json);
//open start scene
EditorSceneManager.OpenScene(startScenePath, OpenSceneMode.Single);
}
[MenuItem("IO Games/Localization/Import")]
static void Import()
{
}
private static string GetGameObjectPath(Transform transform)
{
string path = transform.name;
while (transform.parent != null)
{
transform = transform.parent;
path = transform.name + "/" + path;
}
return path;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment