/// <summary>
    /// Creates and saves a LogEntry for all currently tracked objects
    /// </summary>
    /// <param name="time">Current time to save with log entry</param>
    void LogObjects(float time)
    {
        LogEntry newEntry = new LogEntry(time);

        foreach (var obj in tracked_objs)
        {
            // hands do not report velocity through their RigidBody
            NewtonVR.NVRHand hand = obj.GetComponent <NewtonVR.NVRHand>();
            if (hand != null)
            {
                newEntry.Add(obj.name, obj.transform.position, obj.transform.rotation, hand.GetVelocityEstimation());
                continue;
            }

            // all other objects should have a normal velocity
            Rigidbody rb = obj.GetComponentInChildren <Rigidbody>();
            if (rb != null)
            {
                newEntry.Add(obj.name, obj.transform.position, obj.transform.rotation, rb.velocity);
            }
            else
            {
                newEntry.Add(obj.name, obj.transform.position, obj.transform.rotation);
            }
        }
        foreach (var hand in tracked_hands)
        {
            LogEvent(hand.gameObject, "HoldAxis", hand.HoldButtonAxis.ToString());
        }

        AddLogEntry(newEntry);
    }
    /// <summary>
    /// Adds a log entry for the given GameObject mentioning that the given event has happened.
    /// Useful for recording object-specific events, like button presses or collisions.
    /// Intended to be called asynchronously during recording by other classes. Events are not
    /// automatically tracked by the LogManager.
    ///
    /// Should only be called after recording has already started.
    /// </summary>
    /// <param name="obj">The object which received or triggered the event</param>
    /// <param name="eventName">The event name</param>
    /// <param name="property">Any related event parameters</param>
    public void LogEvent(GameObject obj, string eventName, string property)
    {
        if (!recording)
        {
            return;
        }
        LogEntry newEntry = new LogEntry(GetLogTime());

        NewtonVR.NVRHand hand = obj.GetComponent <NewtonVR.NVRHand>();
        Rigidbody        rb   = obj.GetComponentInChildren <Rigidbody>();

        if (hand != null)
        {
            newEntry.Add(obj.name, obj.transform.position, obj.transform.rotation, hand.GetVelocityEstimation(), eventName, property);
        }
        else if (rb != null)
        {
            newEntry.Add(obj.name, obj.transform.position, obj.transform.rotation, rb.velocity, eventName, property);
        }
        else
        {
            newEntry.Add(obj.name, obj.transform.position, obj.transform.rotation, eventName, property);
        }

        AddLogEntry(newEntry);
    }
Exemplo n.º 3
0
    public bool Eval(List <LogEntry> logEntries, string code)
    {
        EditorApplication.LockReloadAssemblies();

        bool     status    = false;
        bool     hasOutput = false;
        object   output    = null;
        LogEntry cmdEntry  = null;

        string tmpCode = code.Trim();

        cmdEntry = new LogEntry()
        {
            logEntryType = LogEntryType.Command,
            command      = tmpCode
        };

        bool isExpression = false;

        try {
            if (tmpCode.StartsWith("="))
            {
                tmpCode      = "(" + tmpCode.Substring(1, tmpCode.Length - 1) + ");";
                isExpression = true;
            }
            Application.RegisterLogCallback(delegate(string cond, string sTrace, LogType lType) {
                cmdEntry.Add(new LogEntry()
                {
                    logEntryType   = LogEntryType.ConsoleLog,
                    condition      = cond,
                    stackTrace     = sTrace,
                    consoleLogType = lType
                });
            });
            status = Evaluator.Evaluate(tmpCode, out output, out hasOutput) == null;
            if (status)
            {
                logEntries.Add(cmdEntry);
            }
        } catch (Exception e) {
            cmdEntry.Add(new LogEntry()
            {
                logEntryType = LogEntryType.EvaluationError,
                error        = e.ToString().Trim() // TODO: Produce a stack trace a la Debug, and put it in stackTrace so we can filter it.
            });

            output    = new Evaluator.NoValueSet();
            hasOutput = false;
            status    = true; // Need this to avoid 'stickiness' where we let user
                              // continue editing due to incomplete code.
            logEntries.Add(cmdEntry);
        } finally {
            Application.RegisterLogCallback(null);
        }

        // Catch compile errors that are not dismissed as a product of interactive
        // editing by Mono.CSharp.Evaluator...
        StringBuilder buffer = FluffReporter();
        string        tmp    = buffer.ToString().Trim();

        buffer.Length = 0;
        if (!String.IsNullOrEmpty(tmp))
        {
            cmdEntry.Add(new LogEntry()
            {
                logEntryType = LogEntryType.SystemConsole,
                error        = tmp
            });
            status = false;
        }

        if (hasOutput && (isExpression || output is REPLMessage))
        {
            if (status)
            {
                outputBuffer.Length = 0;
                PrettyPrint.PP(outputBuffer, output);
                cmdEntry.Add(new LogEntry()
                {
                    logEntryType = LogEntryType.Output,
                    output       = outputBuffer.ToString().Trim()
                });
            }
        }

        EditorApplication.UnlockReloadAssemblies();
        return(status);
    }
Exemplo n.º 4
0
        private LogEntry Match(Transform local, Transform model)
        {
            Component[] components = model.GetComponents <Component>();

            if (components.Any(c => c is MultiModel))
            {
                return(new LogEntry("Nested multimodel", local, model));
            }

            LogEntry log = new LogEntry("Transforms", local, model);

            if (!dryRun)
            {
                local.gameObject.SetActive(model.gameObject.activeSelf);
            }

            foreach (Component modelComponent in components)
            {
                if (modelComponent is Transform)
                {
                    continue;
                }

                Type      type           = modelComponent.GetType();
                Component localComponent = local.GetComponent(type);
                if (!dryRun && localComponent == null)
                {
                    local.gameObject.AddComponent(type);
                }

#if UNITY_EDITOR
                if (local.GetComponents(type).Length > 1)
                {
                    throw new Exception();
                }
#endif
                log.Add(Match(localComponent, modelComponent));
            }

            Dictionary <string, Transform> childDictionary = CreateChildDictionary(local);

            foreach (Transform modelChild in model)
            {
                Transform localChild;
                string    name         = modelChild.name;
                bool      missingChild = false;
                if (childDictionary.ContainsKey(name))
                {
                    localChild = childDictionary[name];
                    childDictionary.Remove(name);
                }
                else
                {
                    missingChild = true;
                    localChild   = new GameObject(name).transform;
                    localChild.SetParent(local);
                }


                localChild.localPosition = modelChild.localPosition;
                localChild.localRotation = modelChild.localRotation;
                localChild.localScale    = modelChild.localScale;

                log.Add(Match(localChild, modelChild));

                if (missingChild && dryRun)
                {
                    Object.DestroyImmediate(localChild.gameObject);
                }
            }

            foreach (Transform unvisited in childDictionary.Values)
            {
                //IDEA: check if this was in the _currentModel
                if (!dryRun && unvisited.GetComponent <SkinnedMeshRenderer>() != null)
                {
                    unvisited.gameObject.SetActive(false);
                }
                log.Add(new LogEntry("unvisited", unvisited, null));
            }

            return(log);
        }
Exemplo n.º 5
0
    private bool CatchMessages(LogEntry cmdEntry, bool status)
    {
        StringBuilder outBuffer = reportOutWriter.GetStringBuilder();
        StringBuilder errBuffer = reportErrorWriter.GetStringBuilder();

        string tmpOut = outBuffer.ToString().Trim(),
           tmpErr = errBuffer.ToString().Trim();

        outBuffer.Length = 0;
        errBuffer.Length = 0;

        if(outWriter != null)
          System.Console.SetOut(outWriter);
        if(errWriter != null)
          System.Console.SetError(errWriter);

        if(!String.IsNullOrEmpty(tmpOut)) {
          cmdEntry.Add(new LogEntry() {
        logEntryType = LogEntryType.SystemConsoleOut,
        error = tmpOut
          });
          status = false;
        }
        if(!String.IsNullOrEmpty(tmpErr)) {
          cmdEntry.Add(new LogEntry() {
        logEntryType = LogEntryType.SystemConsoleErr,
        error = tmpErr
          });
          status = false;
        }
        return status;
    }
Exemplo n.º 6
0
    public bool Eval(List<LogEntry> logEntries, string code)
    {
        EditorApplication.LockReloadAssemblies();

        bool status = false,
         hasOutput = false,
         hasAddedLogToEntries = false;
        object output = null;
        string res = null,
           tmpCode = code.Trim();
        LogEntry cmdEntry = new LogEntry() {
          logEntryType = LogEntryType.Command,
          command = tmpCode
        };

        try {
          FluffReporter();

          if(tmpCode.StartsWith("=")) {
        // Special case handling of calculator mode.  The problem is that
        // expressions involving multiplication are grammatically ambiguous
        // without a var declaration or some other grammatical construct.
        tmpCode = "(" + tmpCode.Substring(1, tmpCode.Length-1) + ");";
          }
          Application.RegisterLogCallback(delegate(string cond, string sTrace, LogType lType) {
        cmdEntry.Add(new LogEntry() {
          logEntryType = LogEntryType.ConsoleLog,
          condition = cond,
          stackTrace = sTrace,
          consoleLogType = lType
        });
          });
          res = Evaluator.Evaluate(tmpCode, out output, out hasOutput);
          //if(res == tmpCode)
          //  Debug.Log("Unfinished input...");
        } catch(Exception e) {
          cmdEntry.Add(new LogEntry() {
        logEntryType = LogEntryType.EvaluationError,
        error = e.ToString().Trim() // TODO: Produce a stack trace a la Debug, and put it in stackTrace so we can filter it.
          });

          output = new Evaluator.NoValueSet();
          hasOutput = false;
          status = true; // Need this to avoid 'stickiness' where we let user
                     // continue editing due to incomplete code.
        } finally {
          status = res == null;
          Application.RegisterLogCallback(null);
          if(res != tmpCode) {
        logEntries.Add(cmdEntry);
        hasAddedLogToEntries = true;
          }
          status = CatchMessages(cmdEntry, status);
        }

        if(hasOutput) {
          if(status) {
        outputBuffer.Length = 0;

        try {
          FluffReporter();
          PrettyPrint.PP(outputBuffer, output, true);
        } catch(Exception e) {
          cmdEntry.Add(new LogEntry() {
            logEntryType = LogEntryType.EvaluationError,
            error = e.ToString().Trim() // TODO: Produce a stack trace a la Debug, and put it in stackTrace so we can filter it.
          });
          if(!hasAddedLogToEntries) {
            logEntries.Add(cmdEntry);
            hasAddedLogToEntries = true;
          }
        } finally {
          bool result = CatchMessages(cmdEntry, true);
          if(!result && !hasAddedLogToEntries) {
            logEntries.Add(cmdEntry);
            hasAddedLogToEntries = true;
          }
        }

        string tmp = outputBuffer.ToString().Trim();
        if(!String.IsNullOrEmpty(tmp)) {
          cmdEntry.Add(new LogEntry() {
            logEntryType = LogEntryType.Output,
            output = outputBuffer.ToString().Trim()
          });
          if(!hasAddedLogToEntries) {
            logEntries.Add(cmdEntry);
            hasAddedLogToEntries = true;
          }
        }
          }
        }

        EditorApplication.UnlockReloadAssemblies();
        return status;
    }
Exemplo n.º 7
0
    public bool Eval(List<LogEntry> logEntries, string code)
    {
        EditorApplication.LockReloadAssemblies();

        bool status = false;
        bool hasOutput = false;
        object output = null;
        LogEntry cmdEntry = null;

        string tmpCode = code.Trim();

        cmdEntry = new LogEntry() {
          logEntryType = LogEntryType.Command,
          command = tmpCode
        };

        bool isExpression = false;
        try {
          if(tmpCode.StartsWith("=")) {
        tmpCode = "(" + tmpCode.Substring(1, tmpCode.Length-1) + ");";
        isExpression = true;
          }
          Application.RegisterLogCallback(delegate(string cond, string sTrace, LogType lType) {
        cmdEntry.Add(new LogEntry() {
          logEntryType = LogEntryType.ConsoleLog,
          condition = cond,
          stackTrace = sTrace,
          consoleLogType = lType
        });
          });
          status = Evaluator.Evaluate(tmpCode, out output, out hasOutput) == null;
          if(status)
        logEntries.Add(cmdEntry);
        } catch(Exception e) {
          cmdEntry.Add(new LogEntry() {
        logEntryType = LogEntryType.EvaluationError,
        error = e.ToString().Trim() // TODO: Produce a stack trace a la Debug, and put it in stackTrace so we can filter it.
          });

          output = new Evaluator.NoValueSet();
          hasOutput = false;
          status = true; // Need this to avoid 'stickiness' where we let user
                     // continue editing due to incomplete code.
          logEntries.Add(cmdEntry);
        } finally {
          Application.RegisterLogCallback(null);
        }

        // Catch compile errors that are not dismissed as a product of interactive
        // editing by Mono.CSharp.Evaluator...
        StringBuilder buffer = FluffReporter();
        string tmp = buffer.ToString().Trim();
        buffer.Length = 0;
        if(!String.IsNullOrEmpty(tmp)) {
          cmdEntry.Add(new LogEntry() {
        logEntryType = LogEntryType.SystemConsole,
        error = tmp
          });
          status = false;
        }

        if(hasOutput && (isExpression || output is REPLMessage)) {
          if(status) {
        outputBuffer.Length = 0;
        PrettyPrint.PP(outputBuffer, output);
        cmdEntry.Add(new LogEntry() {
          logEntryType = LogEntryType.Output,
          output = outputBuffer.ToString().Trim()
        });
          }
        }

        EditorApplication.UnlockReloadAssemblies();
        return status;
    }