Created
February 4, 2019 10:05
-
-
Save dimmduh/bd8c900c83c175964ccb92f03c51b39e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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