示例#1
0
        public override void OnInspectorGUI()
        {
            settings = target as LuaProfilerPrecompileSetting;

            EditorGUI.BeginChangeCheck();

            EditorGUILayout.BeginVertical();

            #region lua folders
            var dirList = settings.luaDirList;
            EditorGUILayout.LabelField("Lua Folder");
            for (int i = dirList.Count - 1, imin = 0; i >= imin; i--)
            {
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.TextField(dirList[i].scriptFolder);
                if (GUILayout.Button("remove", GUILayout.ExpandWidth(false)))
                {
                    dirList.RemoveAt(i);
                    EditorUtility.SetDirty(settings);
                    AssetDatabase.SaveAssets();
                }
                EditorGUILayout.EndHorizontal();
            }

            if (GUILayout.Button("Add Lua Folder", GUILayout.Height(50)))
            {
                GUI.FocusControl(null);
                string newPath = EditorUtility.OpenFolderPanel("Add Lua Folder", null, null);
                if (!string.IsNullOrEmpty(newPath))
                {
                    var item = new PreCompileFolderInfo();
                    item.scriptFolder = LuaProfilerPrecompileSetting.MakePathRelative(newPath);
                    dirList.Add(item);
                    EditorUtility.SetDirty(settings);
                    AssetDatabase.SaveAssets();
                    Repaint();
                }
            }
            #endregion

            #region lua filter folders
            var filterDirList = settings.luaFilterDirList;
            EditorGUILayout.LabelField("Lua filter Folder");
            for (int i = filterDirList.Count - 1, imin = 0; i >= imin; i--)
            {
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.TextField(filterDirList[i]);
                if (GUILayout.Button("remove", GUILayout.ExpandWidth(false)))
                {
                    filterDirList.RemoveAt(i);
                    EditorUtility.SetDirty(settings);
                    AssetDatabase.SaveAssets();
                }
                EditorGUILayout.EndHorizontal();
            }

            if (GUILayout.Button("Add Lua Filter Folder", GUILayout.Height(50)))
            {
                GUI.FocusControl(null);
                string defaultPath = null;
                if (dirList.Count > 0)
                {
                    defaultPath = dirList[0].scriptFolder;
                }
                string newPath = EditorUtility.OpenFolderPanel("Add Lua Folder", defaultPath, null);
                if (!string.IsNullOrEmpty(newPath))
                {
                    filterDirList.Add(LuaProfilerPrecompileSetting.MakePathRelative(newPath));
                    EditorUtility.SetDirty(settings);
                    AssetDatabase.SaveAssets();
                    Repaint();
                }
            }
            #endregion

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Lua suffix:", GUILayout.Width(80));
            string oldStr = settings.luaSuffix;
            settings.luaSuffix = EditorGUILayout.TextField(settings.luaSuffix);
            if (oldStr != settings.luaSuffix)
            {
                EditorUtility.SetDirty(settings);
            }
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.LabelField("Out Path");
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.TextField(settings.outFolder);
            if (GUILayout.Button("browse", GUILayout.ExpandWidth(false)))
            {
                GUI.FocusControl(null);
                string newPath = EditorUtility.OpenFolderPanel("Out Folder", null, null);
                if (!string.IsNullOrEmpty(newPath))
                {
                    settings.outFolder = LuaProfilerPrecompileSetting.MakePathRelative(newPath);
                    EditorUtility.SetDirty(settings);
                    AssetDatabase.SaveAssets();
                }
            }
            EditorGUILayout.EndHorizontal();

            if (GUILayout.Button("Pre Compile", GUILayout.Height(50)))
            {
                if (LuaProfilerPrecompileSetting.CompileLuaScript(true))
                {
                    Debug.Log("success");
                    foreach (var item in settings.luaDirList)
                    {
                        System.Diagnostics.Process.Start("explorer.exe", Environment.CurrentDirectory + "\\" + settings.outFolder);
                    }
                }
                else
                {
                    Debug.LogError("fail");
                }
                EditorUtility.SetDirty(settings);
                AssetDatabase.SaveAssets();
            }

            if (GUILayout.Button("Clear", GUILayout.Height(50)))
            {
                foreach (var item in settings.luaDirList)
                {
                    item.ClearDict();
                }

                var outFiles = Directory.GetFiles(settings.outFolder, settings.luaSuffix, SearchOption.AllDirectories);
                for (int i = 0, imax = outFiles.Length; i < imax; i++)
                {
                    File.Delete(outFiles[i]);
                }
                var outFolder = Directory.GetDirectories(settings.outFolder);
                for (int i = 0, imax = outFolder.Length; i < imax; i++)
                {
                    Directory.Delete(outFolder[i], true);
                }
                EditorUtility.SetDirty(settings);
                AssetDatabase.SaveAssets();
            }
            EditorGUILayout.EndVertical();

            EditorGUI.EndChangeCheck();
        }
示例#2
0
        public static void OnStartGame()
        {
#if UNITY_EDITOR
            if (!Application.isPlaying)
            {
                return;
            }
#endif
#if UNITY_EDITOR_WIN
            string path  = null;
            var    files = System.IO.Directory.GetFiles(Application.dataPath, "EasyHook64.bin", System.IO.SearchOption.AllDirectories);
            if (files.Length > 0)
            {
                path = files[0];
            }
            if (!string.IsNullOrEmpty(path))
            {
                IntPtr ptr = LoadLibrary(path);
                if (ptr == null)
                {
                    Debug.LogError("dont't move dll file to other place");
                    return;
                }
            }
            else
            {
                Debug.LogError("no EasyHook64.bin");
                return;
            }
#endif
            if (isInite)
            {
                return;
            }

            isInite = true;
            setting = LuaDeepProfilerSetting.Instance;
            LuaProfiler.mainThreadId = System.Threading.Thread.CurrentThread.ManagedThreadId;
            if (setting.isNeedCapture)
            {
                Screen.SetResolution(480, 270, true);
            }

#if UNITY_EDITOR
            if (setting.isDeepLuaProfiler)
            {
                LuaDLL.Uninstall();
                LuaDLL.HookLoadLibrary();
                LuaDLL.BindEasyHook();
                //LuaDLL.Install();

                if (setting.isCleanMode)
                {
                    LuaProfilerPrecompileSetting.CompileLuaScript(false);
                }
            }
#endif

            if (setting.isDeepLuaProfiler || setting.isDeepMonoProfiler || setting.isCleanMode)
            {
                GameObject go = new GameObject();
                go.name      = "MikuLuaProfiler";
                go.hideFlags = HideFlags.HideAndDontSave;
                DontDestroyOnLoad(go);
                go.AddComponent <HookLuaSetup>();
                if (!setting.isLocal)
                {
                    NetWorkClient.ConnectServer(setting.ip, setting.port);
                }
            }
        }
示例#3
0
        public static void OnStartGame()
        {
#if UNITY_EDITOR
            if (!Application.isPlaying)
            {
                return;
            }
#endif
#if UNITY_EDITOR_WIN
            System.Diagnostics.StackTrace st = new System.Diagnostics.StackTrace(true);
            System.Diagnostics.StackFrame sf = st.GetFrame(0);
            string path = sf.GetFileName();

            path = path.Replace("Core\\LuaHookSetup.cs", "Plugins\\EasyHook64.dll");
            IntPtr ptr = LoadLibrary(path);
            if (ptr == null)
            {
                Debug.LogError("dont't move dll file to other place");
                return;
            }
#endif
            if (isInite)
            {
                return;
            }

            isInite = true;
            setting = LuaDeepProfilerSetting.Instance;
            LuaProfiler.mainThreadId = System.Threading.Thread.CurrentThread.ManagedThreadId;
            if (setting.isNeedCapture)
            {
                Screen.SetResolution(480, 270, true);
            }

#if UNITY_EDITOR
            if (setting.isDeepLuaProfiler)
            {
                LuaDLL.Uninstall();
                LuaDLL.HookLoadLibrary();
                LuaDLL.BindEasyHook();
                //LuaDLL.Install();

                if (setting.isCleanMode)
                {
                    LuaProfilerPrecompileSetting.CompileLuaScript(false);
                }
            }
#endif

            if (setting.isDeepLuaProfiler || setting.isDeepMonoProfiler || setting.isCleanMode)
            {
                GameObject go = new GameObject();
                go.name      = "MikuLuaProfiler";
                go.hideFlags = HideFlags.HideAndDontSave;
                DontDestroyOnLoad(go);
                go.AddComponent <HookLuaSetup>();
                if (!setting.isLocal)
                {
                    NetWorkClient.ConnectServer(setting.ip, setting.port);
                }
            }
        }