summaryrefslogtreecommitdiff
path: root/WorldlineKeepers/Assets/Tools/LevelEditor/Editor/LevelEditor.cs
blob: e97e5b010b0a533feaed6558d80aee2508f275dc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using LitJson;
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using WK;
using WK.Data;

public class LevelEditor : EditorWindow
{

    private static LevelEditor s_LevelEditorWindow;

    [MenuItem("Tools/¹Ø¿¨±à¼­Æ÷/Open")]
    public static void OpenLevelEditor()
    {
        s_LevelEditorWindow = GetWindow<LevelEditor>();
    }

    private void OnGUI()
    {
        if(GUILayout.Button("ÐòÁл¯"))
        {
            StageMetadata stageMetadata = new StageMetadata();

            StageEntityBase[] entites = GameObject.FindObjectsOfType<StageEntityBase>();
            if(entites != null && entites.Length > 0)
            {
                for(int i = 0; i < entites.Length; ++i)
                {
                    StageEntityBase entity = entites[i];
                    if (entity == null)
                        continue;
                    GameObject go = entity.gameObject;
                    if (go.name.StartsWith("~"))
                        continue;
                    var meta = entity.OnSerialize();
                    if(meta != null)
                    {
                        stageMetadata.Write(meta);
                    }
                }
            }

            string json = JsonMapper.ToJson(stageMetadata);

            LevelExportSetting setting = GameObject.FindObjectOfType<LevelExportSetting>();
            if(setting != null)
            {
                CommonFunction.WriteFile(json, setting.targetJsonFile);
                LogHelper.Log("[LevelEditor] output=" + setting.targetJsonFile);
            }

            AssetDatabase.Refresh();
        }
    }

}