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");
            }
        }
        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);
        }
Beispiel #3
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;
         }
     }
 }
        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}");
            }
        }
 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}");
         }
     }
 }
Beispiel #6
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);
                }
            });
        }
        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
        }
Beispiel #8
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);
        }
        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}");
            });
        }