private static void St2()
        {
            var hasLibCSharpFileMakeCompileSlow = false;

            foreach (var p in RoFile.Ls(EditorScript.Ro.EditorEnv.assetsPath))
            {
                var isLibDir = RoFile.IsDir(p) && !RoFile.Basename(p)
                               .IsMatch(@"^(Script|PostProcessing|Scripts|Editor|EditorScript|Draft|Test|Plugins|Standard Assets)$");
                if (isLibDir)
                {
                    foreach (var p2 in RoFile.FF(p))
                    {
                        if (p2.IsMatch("\\.cs$"))
                        {
                            hasLibCSharpFileMakeCompileSlow = true;
                            var rootDir = RoFile.Rel(p2, EditorEnv.assetsPath).Match("[^/]+").ToString();
                            Shell.NotifyWarn(
                                $"In *Assets/{rootDir}*, it has lib c# file in Assets not *Assets/Standard Assets* to make compile slow, run *mad compile time optimizer* or maunally moving all lib c# files to *Assets/Standard Assets* to improve it");
                            break;
                        }
                    }
                }

                if (hasLibCSharpFileMakeCompileSlow)
                {
                    break;
                }
            }
        }
        public static void InitAndroidDebug(string apkRelPath)
        {
            var sdk = EditorPrefs.GetString("AndroidSdkRoot");
            var adb = $"{sdk}/platform-tools/adb";

            var    lines  = Sh($"{adb} devices").Split("\n");
            string device = "";

            for (int i = 0; i < lines.Length; i++)
            {
                var line = lines[i];
                var m    = line.Match(@"(\d+\.\d+\.\d+\.\d+\:\d+)[\t\s]+device");
                if (m.Groups[0].Value != "")
                {
                    device = m.Groups[1].Value;
                    break;
                }
            }

            if (device != "")
            {
                var buildToolsDir = RoFile.Ls($"{sdk}/build-tools").SortBy((path) => { return(path); }).Last();
                var aapt          = RoFile.Join(buildToolsDir, "aapt");

                var apk         = RoFile.Join(EditorEnv.pj, apkRelPath);
                var dumpStr     = Sh($"{aapt} dump badging \"{apk}\"");
                var pkgName     = dumpStr.Match(@"package: name='(\S+)'").Groups[1].Value;
                var mainAct     = dumpStr.Match(@"launchable-activity: name='(\S+)'").Groups[1].Value;
                var forwardPort =
                    UnityEditorInternal.ProfilerDriver.directConnectionPort.ToInt() +
                    1; // make sure forward port is not equal profile port, profile port will always bind when unity editor start

//                if (startDebugThr != null)
//                {
//                    startDebugThr.Abort();
//                    startDebugThr = null;
//                }
//
//                startDebugThr = new Thread(() =>
//                {
                var forwardCmd = $"{adb} -s {device} forward \"tcp:{forwardPort}\" localabstract:Unity-{pkgName}";
                Debug.Log($"run - {forwardCmd}");
                Sys(forwardCmd);
                var installCmd = $"{adb} -s {device} install -r \"{apk}\"";
                Debug.Log($"run - {installCmd}");
                Sys(installCmd);
                var startCmd = $"{adb} -s {device} shell am start -n {pkgName}/{mainAct}";
                Debug.Log($"run - {startCmd}");
                Sys(startCmd);
                Notify("Init Debug finish");
//                });
//                Notify("start install apk and launch android debug server");
//                startDebugThr.Start();
            }
            else
            {
                throw new SystemException(
                          "cannot find wireless connected real android device, please use real android device and connect it with wireless, for ex, adb connect 192.168.1.102:5555");
            }
        }
예제 #3
0
        public static void St()
        {
            var path = EditorUtility.OpenFolderPanel("Select Unity Pj",
                                                     RoFile.Parent(RoFile.Parent(Application.dataPath)), "");

            EditorApplication.OpenProject(path);
        }
        private static void St2()
        {
            var shouldBeIgnoredInBuildScripts = new List <string>();

            foreach (var path in RoFile.Ls(EditorEnv.assetsPath))
            {
                if (RoFile.IsDir(path))
                {
                    if (RoFile.Basename(path).IsMatch("(Editor|Script|Standard Assets)"))
                    {
                        continue;
                    }

                    var fs = RoFile.FF(path);
                    fs.Each((path2) =>
                    {
                        if (path2.IsMatch("\\.cs$") && !RoFile.Read(path2).IsMatch("#if UNITY_EDITOR"))
                        {
                            shouldBeIgnoredInBuildScripts.Add(path2);
                        }
                    });
                }
            }

            if (shouldBeIgnoredInBuildScripts.Count > 0)
            {
                throw new SystemException(
                          "following code should be marked #if UNITY_EDITOR to only run in unity editor not unity build" +
                          "\n" + shouldBeIgnoredInBuildScripts.Join("\n"));
            }
        }
 static Replay()
 {
     if (EditorUtil.GetCurrentScene().path == RoFile.Rel(EditorEnv.roTestScenePath, EditorEnv.pj))
     {
         // in some case, replay still doesn't work since it's interrupted by unity editor auto refresh, since i often use RoTestScene.unity, so after refresh, start play
         StartPlay();
     }
 }
        public static void OpenDir(string absPath)
        {
            var assetPath = $"Assets/{RoFile.Rel(absPath, Application.dataPath)}";
            var asset     = AssetDatabase.LoadMainAssetAtPath(assetPath);
            var pt        = Type.GetType("UnityEditor.ProjectBrowser,UnityEditor");
            var ins       = pt.GetField("s_LastInteractEditorScript.RojectBrowser", BindingFlags.Static | BindingFlags.Public)
                            .GetValue(null);
            var showDirMeth = pt.GetMethod("ShowFolderContents", BindingFlags.NonPublic | BindingFlags.Instance);

            showDirMeth.Invoke(ins, new object[] { asset.GetInstanceID(), true });
        }
예제 #7
0
        static void St()
        {
            var scenePath = EditorEnv.roTestScenePath;

            if (RoFile.IsFile(scenePath) && EditorSceneManager.GetActiveScene().path != scenePath)
            {
                EditorSceneManager.OpenScene(scenePath);
            }

            Replay.St();
        }
        public static GameObject LoadEditorResPrefab(string relPath)
        {
            relPath = relPath.GSub("\\.prefab$", "") + ".prefab";
            var o = LoadPrefabOrFBX(RoFile.Join("Assets/Editor/Lib/Ro.Unity/Ro/Res", relPath));

            if (!o)
            {
                o = LoadPrefabOrFBX(RoFile.Join("Assets/Editor/Ro/Res", relPath));
            }

            return(o);
        }
        public static void OpenFile(string absPath)
        {
            if (!Regex.IsMatch(absPath, @"Assets"))
            {
                throw new Exception($"{Kernel.GetCurMethName()} only support assets path");
            }

            var assetPath = $"Assets/{RoFile.Rel(absPath, Application.dataPath)}";
            var asset     = AssetDatabase.LoadMainAssetAtPath(assetPath);

            OpenObject(asset);
        }
예제 #10
0
 static void St()
 {
     foreach (UnityEngine.Object obj in Selection.GetFiltered(typeof(UnityEngine.Object), SelectionMode.Assets))
     {
         string p = AssetDatabase.GetAssetPath(obj);
         if (!string.IsNullOrEmpty(p) && RoFile.Exist(p))
         {
             Kernel.ToClip(RoFile.Join(EditorEnv.pj, p));
             break;
         }
     }
 }
예제 #11
0
 private static void ChangeTitleWhenSceneOnRuntime()
 {
     if ((DateTime.Now - lastTime).TotalSeconds > 5)
     {
         pjName    = RoFile.Basename(EditorUtil.GetProject());
         sceneName = SceneManager.GetActiveScene().name;
         Thr(() =>
         {
             lastTime = DateTime.Now;
             ChangeTitle();
         });
     }
 }
        static void St()
        {
            var gameObjs = EditorUtil.GetAllGameObjects();
            var toF      = RoFile.Join(EditorEnv.pj, "tmp/game_objects.json");
            var data     = new Hashtable();

            gameObjs.Each(obj => { data[obj.name] = GetPropsHash(obj); });
            RoFile.Write(toF, JSON.PrettyDump(data));
            if (!EditorUtil.OpenWithRider(toF))
            {
                Kernel.ToClip(toF);
                Kernel.Notify($"game objects json file path has cp to clip: {toF}");
            }
        }
예제 #13
0
        public static void St()
        {
            Thr(() =>
            {
                var gitattrsPath = RoFile.Join(EditorEnv.pj, ".gitattributes");
                if (!RoFile.IsFile(gitattrsPath))
                {
                    RoFile.Write(gitattrsPath, gitattributes);
                }

                var gitignorePath = RoFile.Join(EditorEnv.pj, ".gitignore");
                if (!RoFile.IsFile(gitignorePath))
                {
                    RoFile.Write(gitignorePath, gitignore);
                }
            });
        }
 static void St()
 {
     if (ReceiveRiderCmd.serverIsStarted)
     {
         EditorUtil.SendCmdToRider("show_log");
     }
     else
     {
         var toF = RoFile.Join(EditorEnv.pj, "tmp/err.log");
         RoFile.Write(toF, errs.Map(err => { return(err.ToString()); }).Join("\n"));
         if (!EditorUtil.OpenWithRider(toF))
         {
             Kernel.ToClip(toF);
             Kernel.Notify($"cp err.log path to clip: {toF}");
         }
     }
 }
        private static AssetDeleteResult OnWillDeleteAsset(string assetPath, RemoveAssetOptions options)
        {
            var trashD        = RoFile.Join(EditorEnv.pj, "Trash");
            var bakPath       = RoFile.Join(trashD, $"{RoTime.now.Strftime("yyyyMMddHHmmss")}/{assetPath}");
            var assetFullPath = RoFile.Join(EditorEnv.pj, assetPath);

            if (assetFullPath.IsMatch("InitTestScene\\d+\\.unity"))
            {
                return(AssetDeleteResult.DidNotDelete);
            }

            try
            {
                if (RoFile.IsDir(assetFullPath))
                {
                    RoFile.D2D(assetFullPath, bakPath);
                }
                else
                {
                    RoFile.Cp(assetFullPath, bakPath);
                }

                var msg = $"bak {assetPath} to {bakPath} and del it";
                Shell.Notify(msg);
                Debug.Log(msg);
                return(AssetDeleteResult.DidNotDelete);
            }

            catch (Exception e)
            {
                Shell.NotifyWarn(e.Message);
                throw e;
            }


            // didnotdelete means it hasn't delete file, it should delete it
        }
        public static void St()
        {
            Thr(() =>
            {
                var editorScriptsDir = RoFile.Join(EditorEnv.assetsPath, "EditorScript/Ro");
                if (RoFile.IsDir(editorScriptsDir))
                {
                    var shouldMarkIf_UNITY_EDITOR_scripts = new List <string>();
                    RoFile.FF(editorScriptsDir).Each((path) =>
                    {
                        if (path.IsMatch("\\.cs$") && !RoFile.Read(path).IsMatch("#if\\s+UNITY_EDITOR"))
                        {
                            Notify($"wrap with #if UNITY_EDITOR, script: {path}");
                            RoFile.Write(path, $"#if UNITY_EDITOR\n{RoFile.Read(path)}\n#endif");
                        }
                    });
                }

//                var shouldMarkStr = shouldMarkIf_UNITY_EDITOR_scripts.Map((script) => { return $"    {script}"; })
//                    .Join("\n");
//                throw new SystemException(
//                    $"following scripts should mark #if UNITY_EDITOR\n{shouldMarkStr}");
            });
        }
예제 #17
0
        static bool St(int instanceId, int line)
        {
            var relPath = AssetDatabase.GetAssetPath(instanceId);
            var path    = RoFile.Join(EditorEnv.pj, relPath);

            if (path.IsMatch("\\.(cs|shader)$"))
            {
                string arg;
                if (line >= 0)
                {
                    arg = $"{path}:{line}";
                }
                else
                {
                    arg = $"{path}";
                }

                var pjName = RoFile.Basename(EditorEnv.pj);
                Shell.Sys(
                    $"xdotool search --onlyvisible --limit 1 \"{pjName}.*\\\\s-\\\\sJetBrains Rider\" windowactivate; rider \"{arg}\" &");
            }

            return(false);
        }
예제 #18
0
 private static string GetProjectName()
 {
     return(RoFile.Basename(EditorUtil.GetProject()));
 }
        public static void OpenAssetInIDE(string assetPath)
        {
            var assetPath2 = RoFile.Rel(assetPath, EditorEnv.pj);

            AssetDatabase.OpenAsset(AssetDatabase.LoadAssetAtPath <TextAsset>(assetPath2));
        }