Ejemplo n.º 1
0
        private static void AdviseRefresh(EditorPluginModel model)
        {
            model.Refresh.Set((l, force) =>
            {
                var task = new RdTask <Unit>();
                ourLogger.Verbose("Refresh: SyncSolution Enqueue");
                MainThreadDispatcher.Instance.Queue(() =>
                {
                    if (!EditorApplication.isPlaying && EditorPrefsWrapper.AutoRefresh || force != RefreshType.Normal)
                    {
                        if (force == RefreshType.ForceRequestScriptReload)
                        {
                            ourLogger.Verbose("Refresh: RequestScriptReload");
                            UnityEditorInternal.InternalEditorUtility.RequestScriptReload();
                        }

                        ourLogger.Verbose("Refresh: SyncSolution Started");
                        UnityUtils.SyncSolution();
                        ourLogger.Verbose("Refresh: SyncSolution Completed");
                    }
                    else
                    {
                        ourLogger.Verbose("AutoRefresh is disabled via Unity settings.");
                    }
                    task.Set(Unit.Instance);
                });
                return(task);
            });
        }
Ejemplo n.º 2
0
 private static void SyncSolutionOnceCallBack()
 {
     ourLogger.Verbose("Call SyncSolution once per Unity process.");
     UnityUtils.SyncSolution();
     RiderScriptableSingleton.Instance.CsprojProcessedOnce = true;
     EditorApplication.update -= SyncSolutionOnceCallBack;
 }
Ejemplo n.º 3
0
        public static void MenuOpenProject()
        {
            // Force the project files to be sync
            UnityUtils.SyncSolution();

            // Load Project
            PluginEntryPoint.CallRider(string.Format("{0}{1}{0}", "\"", PluginEntryPoint.SlnFile));
        }
Ejemplo n.º 4
0
        public bool OnOpenedAsset(int instanceID, int line)
        {
            // determine asset that has been double clicked in the project view
            var selected = EditorUtility.InstanceIDToObject(instanceID);

            var assetFilePath = Path.GetFullPath(AssetDatabase.GetAssetPath(selected));

            if (!(selected.GetType().ToString() == "UnityEditor.MonoScript" ||
                  selected.GetType().ToString() == "UnityEngine.Shader" ||
                  (selected.GetType().ToString() == "UnityEngine.TextAsset" &&
//#if UNITY_5 || UNITY_5_5_OR_NEWER
//          EditorSettings.projectGenerationUserExtensions.Contains(Path.GetExtension(assetFilePath).Substring(1))
//#else
                   EditorSettings.externalVersionControl.Contains(Path.GetExtension(assetFilePath).Substring(1))
//#endif
                  )))
            {
                return(false);
            }

            var modifiedSource = EditorPrefs.GetBool(ModificationPostProcessor.ModifiedSource, false);

            myLogger.Verbose("ModifiedSource: {0} EditorApplication.isPlaying: {1} EditorPrefsWrapper.AutoRefresh: {2}", modifiedSource, EditorApplication.isPlaying, EditorPrefsWrapper.AutoRefresh);

            if (modifiedSource && !EditorApplication.isPlaying && EditorPrefsWrapper.AutoRefresh)
            {
                UnityUtils.SyncSolution(); // added to handle opening file, which was just recently created.
                EditorPrefs.SetBool(ModificationPostProcessor.ModifiedSource, false);
            }

            var model = myModel.Maybe.ValueOrDefault;

            if (model != null)
            {
                if (PluginEntryPoint.IsProtocolConnected())
                {
                    const int column = 0;
                    myLogger.Verbose("Calling OpenFileLineCol: {0}, {1}, {2}", assetFilePath, line, column);
                    model.OpenFileLineCol.Start(new RdOpenFileArgs(assetFilePath, line, column));
                    if (model.RiderProcessId.HasValue())
                    {
                        ActivateWindow(model.RiderProcessId.Value);
                    }
                    else
                    {
                        ActivateWindow();
                    }
                    // todo: maybe fallback to CallRider, if returns false
                    return(true);
                }
            }

            var args = string.Format("{0}{1}{0} --line {2} {0}{3}{0}", "\"", mySlnFile, line, assetFilePath);

            return(CallRider(args));
        }
Ejemplo n.º 5
0
        private static void AdviseRefresh(EditorPluginModel model)
        {
            model.Refresh.Set((l, force) =>
            {
                var refreshTask = new RdTask <Unit>();
                void SendResult()
                {
                    if (!EditorApplication.isCompiling)
                    {
                        // ReSharper disable once DelegateSubtraction
                        EditorApplication.update -= SendResult;
                        ourLogger.Verbose("Refresh: SyncSolution Completed");
                        refreshTask.Set(Unit.Instance);
                    }
                }

                ourLogger.Verbose("Refresh: SyncSolution Enqueue");
                MainThreadDispatcher.Instance.Queue(() =>
                {
                    if (!EditorApplication.isPlaying && EditorPrefsWrapper.AutoRefresh || force != RefreshType.Normal)
                    {
                        try
                        {
                            if (force == RefreshType.ForceRequestScriptReload)
                            {
                                ourLogger.Verbose("Refresh: RequestScriptReload");
                                UnityEditorInternal.InternalEditorUtility.RequestScriptReload();
                            }

                            ourLogger.Verbose("Refresh: SyncSolution Started");
                            UnityUtils.SyncSolution();
                        }
                        catch (Exception e)
                        {
                            ourLogger.Error("Refresh failed with exception", e);
                        }
                        finally
                        {
                            EditorApplication.update += SendResult;
                        }
                    }
                    else
                    {
                        refreshTask.Set(Unit.Instance);
                        ourLogger.Verbose("AutoRefresh is disabled via Unity settings.");
                    }
                });
                return(refreshTask);
            });
        }
Ejemplo n.º 6
0
        public static void MenuOpenProject()
        {
            // method can be called via commandline
            if (!PluginEntryPoint.Enabled)
            {
                return;
            }

            // Force the project files to be sync
            UnityUtils.SyncSolution();

            // Load Project
            PluginEntryPoint.CallRider(string.Format("{0}{1}{0}", "\"", PluginEntryPoint.SlnFile));
        }
        [UsedImplicitly] // https://github.com/JetBrains/resharper-unity/issues/475
        public bool OnOpenedAsset(string assetFilePath, int line, int column = 0)
        {
            var modifiedSource = EditorPrefs.GetBool(ModificationPostProcessor.ModifiedSource, false);

            myLogger.Verbose("ModifiedSource: {0} EditorApplication.isPlaying: {1} EditorPrefsWrapper.AutoRefresh: {2}",
                             modifiedSource, EditorApplication.isPlaying, EditorPrefsWrapper.AutoRefresh);

            if (modifiedSource && !EditorApplication.isPlaying && EditorPrefsWrapper.AutoRefresh || !File.Exists(PluginEntryPoint.SlnFile))
            {
                UnityUtils.SyncSolution(); // added to handle opening file, which was just recently created.
                EditorPrefs.SetBool(ModificationPostProcessor.ModifiedSource, false);
            }

            var models = PluginEntryPoint.UnityModels.Where(a => a.Lifetime.IsAlive).ToArray();

            if (models.Any())
            {
                var modelLifetime = models.First();
                var model         = modelLifetime.Model;
                if (PluginEntryPoint.CheckConnectedToBackendSync(model))
                {
                    myLogger.Verbose("Calling OpenFileLineCol: {0}, {1}, {2}", assetFilePath, line, column);

                    if (model.RiderProcessId.HasValue())
                    {
                        AllowSetForegroundWindow(model.RiderProcessId.Value);
                    }
                    else
                    {
                        AllowSetForegroundWindow();
                    }

                    model.OpenFileLineCol.Start(modelLifetime.Lifetime, new RdOpenFileArgs(assetFilePath, line, column));

                    // todo: maybe fallback to CallRider, if returns false
                    return(true);
                }
            }

            var argsString = assetFilePath == "" ? "" : $" --line {line} --column {column} \"{assetFilePath}\""; // on mac empty string in quotes is causing additional solution to be opened https://github.cds.internal.unity3d.com/unity/com.unity.ide.rider/issues/21
            var args       = string.Format("{0}{1}{0}{2}", "\"", mySlnFile, argsString);

            return(CallRider(args));
        }
Ejemplo n.º 8
0
        [UsedImplicitly] // https://github.com/JetBrains/resharper-unity/issues/475
        public bool OnOpenedAsset(string assetFilePath, int line)
        {
            var modifiedSource = EditorPrefs.GetBool(ModificationPostProcessor.ModifiedSource, false);

            myLogger.Verbose("ModifiedSource: {0} EditorApplication.isPlaying: {1} EditorPrefsWrapper.AutoRefresh: {2}",
                             modifiedSource, EditorApplication.isPlaying, EditorPrefsWrapper.AutoRefresh);

            if (modifiedSource && !EditorApplication.isPlaying && EditorPrefsWrapper.AutoRefresh || !File.Exists(PluginEntryPoint.SlnFile))
            {
                UnityUtils.SyncSolution(); // added to handle opening file, which was just recently created.
                EditorPrefs.SetBool(ModificationPostProcessor.ModifiedSource, false);
            }

            var models = PluginEntryPoint.UnityModels.Where(a => !a.Lifetime.IsTerminated).ToArray();

            if (models.Any())
            {
                var model = models.First().Model;
                if (PluginEntryPoint.CheckConnectedToBackendSync(model))
                {
                    const int column = 0;
                    myLogger.Verbose("Calling OpenFileLineCol: {0}, {1}, {2}", assetFilePath, line, column);
                    if (model.RiderProcessId.HasValue())
                    {
                        ActivateWindow(model.RiderProcessId.Value);
                    }
                    else
                    {
                        ActivateWindow();
                    }

                    model.OpenFileLineCol.Start(new RdOpenFileArgs(assetFilePath, line, column));

                    // todo: maybe fallback to CallRider, if returns false
                    return(true);
                }
            }

            var args = string.Format("{0}{1}{0} --line {2} {0}{3}{0}", "\"", mySlnFile, line, assetFilePath);

            return(CallRider(args));
        }
Ejemplo n.º 9
0
 private static void AdviseRefresh(EditorPluginModel model)
 {
     model.Refresh.Set((l, force) =>
     {
         var task = new RdTask <RdVoid>();
         MainThreadDispatcher.Instance.Queue(() =>
         {
             if (!EditorApplication.isPlaying && EditorPrefsWrapper.AutoRefresh || force)
             {
                 UnityUtils.SyncSolution();
             }
             else
             {
                 ourLogger.Verbose("AutoRefresh is disabled via Unity settings.");
             }
             task.Set(RdVoid.Instance);
         });
         return(task);
     });
 }
Ejemplo n.º 10
0
 private static void MenuSyncProject()
 {
     UnityUtils.SyncSolution();
 }
Ejemplo n.º 11
0
        private static UnityModel CreateModel(Protocol protocol, Lifetime lt)
        {
            var isPlayingAction = new Action(() =>
            {
                MainThreadDispatcher.Instance.Queue(() =>
                {
                    var isPlaying = EditorApplication.isPlayingOrWillChangePlaymode && EditorApplication.isPlaying;
                    ourModel?.Maybe.ValueOrDefault?.Play.SetValue(isPlaying);

                    var isPaused = EditorApplication.isPaused;
                    ourModel?.Maybe.ValueOrDefault?.Pause.SetValue(isPaused);
                });
            });
            var model = new UnityModel(lt, protocol);

            isPlayingAction(); // get Unity state
            model.Play.Advise(lt, play =>
            {
                MainThreadDispatcher.Instance.Queue(() =>
                {
                    var res = EditorApplication.isPlayingOrWillChangePlaymode && EditorApplication.isPlaying;
                    if (res != play)
                    {
                        EditorApplication.isPlaying = play;
                    }
                });
            });

            model.Pause.Advise(lt, pause =>
            {
                MainThreadDispatcher.Instance.Queue(() =>
                {
                    EditorApplication.isPaused = pause;
                });
            });
            model.LogModelInitialized.SetValue(new UnityLogModelInitialized());
            model.Refresh.Set((l, force) =>
            {
                var task = new RdTask <RdVoid>();
                MainThreadDispatcher.Instance.Queue(() =>
                {
                    if (EditorPrefsWrapper.AutoRefresh || force)
                    {
                        UnityUtils.SyncSolution();
                    }
                    else
                    {
                        ourLogger.Verbose("AutoRefresh is disabled via Unity settings.");
                    }
                    task.Set(RdVoid.Instance);
                });
                return(task);
            });
            model.Step.Set((l, x) =>
            {
                var task = new RdTask <RdVoid>();
                MainThreadDispatcher.Instance.Queue(() =>
                {
                    EditorApplication.Step();
                    task.Set(RdVoid.Instance);
                });
                return(task);
            });

            var isPlayingHandler = new EditorApplication.CallbackFunction(() => isPlayingAction());

// left for compatibility with Unity <= 5.5
#pragma warning disable 618
            lt.AddBracket(() => { EditorApplication.playmodeStateChanged += isPlayingHandler; },
                          () => { EditorApplication.playmodeStateChanged -= isPlayingHandler; });
#pragma warning restore 618
            //isPlayingHandler();

            // new api - not present in Unity 5.5
            //lt.AddBracket(() => { EditorApplication.pauseStateChanged+= IsPauseStateChanged(model);},
            //  () => { EditorApplication.pauseStateChanged -= IsPauseStateChanged(model); });

            ourLogger.Verbose("CreateModel finished.");

            return(model);
        }