예제 #1
0
        static void OnGUI()
        {
            luaScript   = (DefaultAsset)EditorGUILayout.ObjectField("Lua Script", luaScript, typeof(DefaultAsset), allowSceneObjects: false);
            GUI.enabled = luaScript != null;
            string path = null;

            if (luaScript != null)
            {
                path = AssetDatabase.GetAssetPath(luaScript.GetInstanceID());
                var ext = Path.GetExtension(path);
                GUI.enabled = ext.ToLower() == ".lua";
            }
            EditorGUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("Upload", GUILayout.Width(100)))
            {
                var content = File.ReadAllText(path);
                conn.Send(
                    JsonConvert.SerializeObject(
                        new ECMPutFile()
                {
                    path    = "_LuaRoot/" + ScriptNameAttribute.GetScriptName(Path.Combine(stubs.BuildPath.projectDir, path)),
                    content = content
                }));
            }
            EditorGUILayout.EndHorizontal();
            GUI.enabled = true;

            EditorGUILayout.Separator();

            if (GUILayout.Button("Upload All Lua Scripts"))
            {
                var allScripts = AllLuaScriptsAttribute.GetAllLuaScripts();
                foreach (var kv in allScripts)
                {
                    var content = File.ReadAllText(kv.Value);
                    conn.Send(
                        JsonConvert.SerializeObject(
                            new ECMPutFile()
                    {
                        path    = "_LuaRoot/" + kv.Key,
                        content = content
                    }
                            ));
                }
            }
            EditorGUILayout.LabelField("Execute Lua Script:");
            lastScript = EditorGUILayout.TextArea(lastScript, GUILayout.Height(200));
            EditorGUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("Go", GUILayout.Width(100)))
            {
                conn.Send(
                    JsonConvert.SerializeObject(
                        new ECMExecLuaScript()
                {
                    content = lastScript
                }
                        ));
            }
            EditorGUILayout.EndHorizontal();
        }
예제 #2
0
        static bool Build()
        {
            var    path   = AssetDatabase.FindAssets("luac");
            string luac64 = null;
            string luac   = null;

            foreach (var p in path)
            {
                var filePath = AssetDatabase.GUIDToAssetPath(p);
                if (Path.GetFileName(filePath) == "luac.exe")
                {
                    if (filePath.Contains("x86_64"))
                    {
                        if (luac64 == null)
                        {
                            luac64 = filePath;
                        }
                        else
                        {
                            Debug.LogErrorFormat("multiple luac?\n\t{0}\n\t{1}", luac64, filePath);
                            return(false);
                        }
                    }
                    else if (filePath.Contains("x86"))
                    {
                        if (luac == null)
                        {
                            luac = filePath;
                        }
                        else
                        {
                            Debug.LogErrorFormat("multiple luac?\n\t{0}\n\t{1}", luac64, filePath);
                            return(false);
                        }
                    }
                }
            }

            if (string.IsNullOrEmpty(luac))
            {
                Debug.LogError("missing x86/luac");
                return(false);
            }
            if (string.IsNullOrEmpty(luac64))
            {
                Debug.LogError("missing x86_64/luac");
                return(false);
            }

            luac   = Path.Combine(BuildPath.projectDir, luac).Replace("/", "\\");
            luac64 = Path.Combine(BuildPath.projectDir, luac64).Replace("/", "\\");
            if (Directory.Exists(luaStagingDir))
            {
                Directory.Delete(luaStagingDir, true);
            }
            Directory.CreateDirectory(luaStagingDir);

            var allScripts = AllLuaScriptsAttribute.GetAllLuaScripts();

            foreach (var kv in allScripts)
            {
                Debug.LogFormat("build {0} <- {1}", kv.Key, kv.Value);
                Cmd.Execute(string.Format("{0} -o {2} {1}", luac, kv.Value, GetStageName(kv.Key + "_32.bytes")));
                Cmd.Execute(string.Format("{0} -o {2} {1}", luac64, kv.Value, GetStageName(kv.Key + "_64.bytes")));
            }
            AssetDatabase.Refresh();
            return(true);
        }