Beispiel #1
0
        public Entity BindToNewEntity(UnityModel model)
        {
            var entity = new Entity(model.transform.position, 0.1f);

            if (model.gameObject.tag == "Player")
            {
                inputProcessor = new InputProcessor(
                    this,
                    camera,
                    entity,
                    interactables,
                    entityConfig);
                player = entity;
            }
            //else
            //{
            //    entity.Add(new MoveToDestination(entity, new Vector3(35.13f, 1.13f, -31.63f)));
            //}
            entities.Add(entity);
            models.Add(model);
            Debug.Log(
                "Registered pre-existing entity '"
                + model.gameObject.name
                + "'"
                + " at location "
                + entity.Location);
            return(entity);
        }
        private void CreateProtocol(FileSystemPath protocolInstancePath, Solution solution)
        {
            int port;

            try
            {
                var protocolInstance =
                    JsonConvert.DeserializeObject <ProtocolInstance>(protocolInstancePath.ReadAllText2().Text);
                port = protocolInstance.port_id;
            }
            catch (Exception e)
            {
                myLogger.Warn($"Unable to parse {protocolInstancePath}" + Environment.NewLine + e);
                return;
            }

            myLogger.Info($"UNITY_Port {port}.");

            try
            {
                var lifetime = mySessionLifetimes.Next();
                myLogger.Info("Create protocol...");

                myLogger.Info("Creating SocketWire with port = {0}", port);
                var wire = new SocketWire.Client(lifetime, myDispatcher, port, "UnityClient");
                wire.Connected.WhenTrue(lifetime, lf =>
                {
                    myLogger.Info("WireConnected.");

                    var protocol = new Protocol("UnityEditorPlugin", new Serializers(), new Identities(IdKind.Client), myDispatcher, wire);
                    var model    = new UnityModel(lf, protocol);
                    model.IsBackendConnected.Set(rdVoid => true);
                    model.RiderProcessId.SetValue(Process.GetCurrentProcess().Id);
                    solution.SetCustomData("UNITY_SessionInitialized", "true");

                    SubscribeToLogs(lf, model, solution);
                    SubscribeToOpenFile(model, solution);
                    model.Play.AdviseNotNull(lf, b => solution.SetCustomData("UNITY_Play", b.ToString().ToLower()));
                    model.Pause.AdviseNotNull(lf, b => solution.SetCustomData("UNITY_Pause", b.ToString().ToLower()));

                    myLocks.ExecuteOrQueueEx(myLifetime, "setModel",
                                             () => { myUnityModel.SetValue(model, myReadonlyToken); });
                    lf.AddAction(() =>
                    {
                        myLocks.ExecuteOrQueueEx(myLifetime, "clearModel", () =>
                        {
                            myLogger.Info("Wire disconnected.");
                            solution.SetCustomData("UNITY_SessionInitialized", "false");
                            myUnityModel.SetValue(null, myReadonlyToken);
                        });
                    });
                });
            }
            catch (Exception ex)
            {
                myLogger.Error(ex);
            }
        }
Beispiel #3
0
        private void RunInternal(IUnitTestRun firstRun, Lifetime connectionLifetime, UnityModel unityModel, TaskCompletionSource <bool> tcs)
        {
            mySolution.Locks.AssertMainThread();

            var elementToIdMap   = new Dictionary <string, IUnitTestElement>();
            var unitTestElements = CollectElementsToRunInUnityEditor(firstRun);
            var allNames         = InitElementsMap(unitTestElements, elementToIdMap);
            var emptyList        = new List <string>();

            var launch = new UnitTestLaunch(allNames, emptyList, emptyList);

            launch.TestResult.Advise(connectionLifetime, result =>
            {
                var unitTestElement = GetElementById(result.TestId, elementToIdMap);
                if (unitTestElement == null)
                {
                    return;
                }

                switch (result.Status)
                {
                case Status.Pending:
                    myUnitTestResultManager.MarkPending(unitTestElement,
                                                        firstRun.Launch.Session);
                    break;

                case Status.Running:
                    myUnitTestResultManager.TestStarting(unitTestElement,
                                                         firstRun.Launch.Session);
                    break;

                case Status.Passed:
                case Status.Failed:
                    var taskResult = result.Status == Status.Failed ? TaskResult.Error : TaskResult.Success;
                    var message    = result.Status == Status.Failed ? "Failed" : "Passed";

                    myUnitTestResultManager.TestOutput(unitTestElement, firstRun.Launch.Session, result.Output, TaskOutputType.STDOUT);
                    myUnitTestResultManager.TestDuration(unitTestElement, firstRun.Launch.Session, TimeSpan.FromMilliseconds(result.Duration));
                    myUnitTestResultManager.TestFinishing(unitTestElement,
                                                          firstRun.Launch.Session, message, taskResult);
                    break;

                default:
                    throw new ArgumentOutOfRangeException(
                        $"Unknown test result from the protocol: {result.Status}");
                }
            });

            launch.RunResult.Advise(connectionLifetime, result =>
            {
                tcs.SetResult(true);
            });

            unityModel.UnitTestLaunch.Value = launch;
        }
Beispiel #4
0
 private void SubscribeToLogs(Lifetime lifetime, UnityModel model, Solution solution)
 {
     model.LogModelInitialized.Advise(lifetime, modelInitialized =>
     {
         modelInitialized.Log.Advise(lifetime, entry =>
         {
             myLogger.Verbose(entry.Mode + " " + entry.Type + " " + entry.Message + " " + Environment.NewLine + " " + entry.StackTrace);
             SetOrCreateDataKeyValuePair(solution, "UNITY_LogEntry", JsonConvert.SerializeObject(entry));
         });
     });
 }
    public override void OnImportAsset(AssetImportContext ctx)
    {
        FileStream stream = new FileStream(ctx.assetPath, FileMode.Open);

        Fmdl       fmdl  = new Fmdl(Path.GetFileNameWithoutExtension(ctx.assetPath));
        UnityModel model = new UnityModel();

        fmdl.Read(stream);
        GameObject fmdlGameObject = model.GetDataFromFmdl(fmdl);

        ctx.AddObjectToAsset(ctx.assetPath, fmdlGameObject);
        ctx.SetMainObject(fmdlGameObject);
        stream.Close();
    }
Beispiel #6
0
        private void SubscribeToOpenFile([NotNull] UnityModel model, Solution solution)
        {
            model.OpenFileLineCol.Set(args =>
            {
                using (ReadLockCookie.Create())
                {
                    var textControl = mySolution.GetComponent <IEditorManager>()
                                      .OpenFile(FileSystemPath.Parse(args.Path), OpenFileOptions.DefaultActivate);
                    if (textControl == null)
                    {
                        return(false);
                    }
                    if (args.Line > 0 || args.Col > 0)
                    {
                        textControl.Caret.MoveTo((Int32 <DocLine>)(args.Line - 1), (Int32 <DocColumn>)args.Col, CaretVisualPlacement.Generic);
                    }
                }

                SetOrCreateDataKeyValuePair(solution, "UNITY_ActivateRider", "true");
                return(true);
            });
        }
        private static void AdviseModel(Lifetime connectionLifetime, UnityModel modelValue)
        {
            modelValue.GetUnityEditorState.Set(rdVoid =>
            {
                if (EditorApplication.isPlaying)
                {
                    return(UnityEditorState.Play);
                }

                if (EditorApplication.isCompiling || EditorApplication.isUpdating)
                {
                    return(UnityEditorState.Refresh);
                }

                return(UnityEditorState.Idle);
            });

            modelValue.UnitTestLaunch.Change.Advise(connectionLifetime, launch =>
            {
                var unityEditorTestLauncher = new UnityEditorTestLauncher(launch);
                unityEditorTestLauncher.TryLaunchUnitTests();
            });
        }
        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);
        }
Beispiel #9
0
 public void UnbindFromEntity(UnityModel model)
 {
     models.Remove(model);
 }
 private void SendLogEvent(UnityModel model, RdLogEvent logEvent)
 {
     //if (!message.StartsWith("[Rider][TRACE]")) // avoid sending because in Trace mode log about sending log event to Rider, will also appear in unity log
     model.LogModelInitialized.Value.Log.Fire(logEvent);
 }
Beispiel #11
0
 private void Awake()
 {
     unityModel = GetComponent <UnityModel>();
 }
Beispiel #12
0
 public EcjJob(UnityModel unityModel)
 {
     this.unityModel = unityModel;
 }