Esempio n. 1
0
        public static LunaScene ToLunaScene(this Scene scene)
        {
            LunaScene lunaScene = new LunaScene();

            lunaScene.From(scene);

            return(lunaScene);
        }
        static void ExportToHtml5()
        {
            if (templatePath == null)
            {
                templatePath = Application.dataPath + "/Libraries/LunaLab/Template";
            }

            Scene activeScene = SceneManager.GetActiveScene();
            var   destination = EditorUtility.SaveFilePanel("Export to Html", "", activeScene.name, "");

            destination = Path.ChangeExtension(destination, null);

            Directory.CreateDirectory(destination);
            FileUtil.CopyFileOrDirectory(templatePath + "/index.html", destination + "/index.html");
            FileUtil.CopyFileOrDirectory(templatePath + "/js", destination + "/js");

            JSONObject gameConfig = new JSONObject(JSONObject.Type.OBJECT);
            JSONObject scenesJson = new JSONObject(JSONObject.Type.ARRAY);
            JSONObject windowJson = new JSONObject(JSONObject.Type.OBJECT);

            LunaScene lunaScene = activeScene.ToLunaScene();

            scenesJson.Add(lunaScene.ToJsonObject());

            Window window = instance ? instance.window : new Window();
            Export export = instance ? instance.export : new Export();

            windowJson.AddField("width", window.width);
            windowJson.AddField("height", window.height);

            gameConfig.AddField("scenes", scenesJson);
            gameConfig.AddField("window", windowJson);
            gameConfig.AddField("useShadowMap", true);

            string jsonSavePath = destination + "/game_config.json";

            File.WriteAllText(jsonSavePath, gameConfig.ToString());

            EditorUtility.RevealInFinder(destination);

            if (export.startServer)
            {
                HttpFileServer myServer = new HttpFileServer(destination, export.serverPort);
                Application.OpenURL($"http://localhost:{export.serverPort}/index.html");
            }
        }