Exemplo n.º 1
0
 protected static void InternalPP(StringBuilder output, object result, bool expandTypes = false)
 {
     if (result == null)
     {
         output.Append("null");
     }
     else
     {
         if (result is REPLMessage)
         {
             // Raw, no escaping or quoting.
             output.Append(((REPLMessage)result).msg);
         }
         else if (result is Component)
         {
             string n;
             try {
                 n = ((Component)result).name;
             } catch (MissingReferenceException) {
                 n = "<destroyed>";
             }
             output.Append(n);
         }
         else if (result is GameObject)
         {
             string n;
             try {
                 n = ((GameObject)result).name;
             } catch (MissingReferenceException) {
                 n = "<destroyed>";
             }
             output.Append(n);
         }
         else if (result is Array)
         {
             Array a = (Array)result;
             int   top = a.GetUpperBound(0), bottom = a.GetLowerBound(0);
             OpenInline(output, top - bottom);
             for (int i = bottom; i <= top; i++)
             {
                 InternalPP(output, a.GetValue(i));
                 if (i != top)
                 {
                     NextItem(output, top - bottom);
                 }
             }
             CloseInline(output, top - bottom);
         }
         else if (result is bool)
         {
             output.Append(((bool)result) ? "true" : "false");
         }
         else if (result is string)
         {
             output.Append('"').Append(EscapeString((string)result)).Append('"');
         }
         else if (result is IDictionary)
         {
             IDictionary dict = (IDictionary)result;
             int         top = dict.Count, count = 0;
             Open(output);
             foreach (DictionaryEntry entry in dict)
             {
                 count++;
                 InternalPP(output, entry.Key);
                 output.Append(": ");
                 InternalPP(output, entry.Value);
                 if (count != top)
                 {
                     NextItem(output, 0);
                 }
             }
             Close(output);
         }
         else if (result is IEnumerable)
         {
             int       i   = 0;
             ArrayList tmp = new ArrayList();
             foreach (object item in (IEnumerable)result)
             {
                 tmp.Add(item);
             }
             OpenInline(output, tmp.Count);
             foreach (object item in tmp)
             {
                 if (i++ != 0)
                 {
                     NextItem(output, tmp.Count);
                 }
                 InternalPP(output, item);
             }
             CloseInline(output, tmp.Count);
         }
         else if (result is char)
         {
             EscapeChar(output, (char)result);
         }
         else if (result is Type || result.GetType().Name == "MonoType")
         {
             if (_depth > 0 || !expandTypes)
             {
                 output.Append("typeof(" + ((Type)result).Namespace + "." + ((Type)result).Name + ")");
             }
             else
             {
                 output.Append(InteractiveBase.Describe(result));
             }
         }
         else
         {
             output.Append(result.ToString());
         }
     }
 }
Exemplo n.º 2
0
        public string ProcessCommand(string command)
        {
            string result   = "";
            string dataText = "";

            command = command.Remove(0, 1);

            int indexOfOpenAngleBracket = 0;
            int indexOfOpenParentheses  = 0;

            if (!command.EndsWith("();"))
            {
                if (command.Contains("<"))
                {
                    command = command.Replace(">();", "");
                    command = command.Replace("> ();", "");
                    indexOfOpenAngleBracket = command.IndexOf('<');
                    dataText = command.Substring(indexOfOpenAngleBracket + 1);
                }

                if (command.Contains("("))
                {
                    command = command.Replace(");", "");
                    indexOfOpenParentheses = command.IndexOf('(');
                    dataText = command.Substring(indexOfOpenParentheses + 1);
                }
            }
            else
            {
                command = command.Replace("();", "");
            }

            if (RuntimeUnityEditorCore._enableDebug)
            {
                File.WriteAllText(DebugHelpers.debugPath + "TELNET_CommandProcessDebug.txt", "command: " + command + "\r\ndata: " + dataText);
            }

            switch (command)
            {
            case "help":
                result = REPL.REPL.help;
                break;

            case "Describe":
                result = InteractiveBase.Describe((object)dataText);
                break;

            case "Print":
                if (!dataText.Contains(","))
                {
                    InteractiveBase.print((object)dataText);
                }
                else
                {
                    object[] dataParams = InitializeArray <object>(20);
                    InteractiveBase.print(dataText, dataParams);
                }
                break;

            case "LoadAssembly":
                InteractiveBase.LoadAssembly(dataText);
                break;

            case "LoadPackage":
                InteractiveBase.LoadPackage(dataText);
                break;

            case "ShowUsing":
                InteractiveBase.ShowUsing();
                break;

            case "ShowVars":
                InteractiveBase.ShowVars();
                break;

            case "Time":
                //TimeSpan resTime = InteractiveBase.Time(dataText);
                //result = resTime.ToString();
                break;

            // TESTING ---------------------------------------------------------------------------------------------------------------------------------------
            case "find<":
                try
                {
                    Object obj = UnityEngine.Object.FindObjectOfType(Type.GetType("\"" + dataText + "\""));
                    File.WriteAllText(DebugHelpers.debugPath + "TELNET_CommandProcessDebug.txt", "command: " + command + "\r\ndata: " + dataText);
                    if (obj != null)
                    {
                        File.WriteAllText(DebugHelpers.debugPath + "TMP.txt", "object is not null");
                    }

                    result = obj.QuickDump();
                }
                catch (Exception e)
                {
                    result = e.Message;
                }

                break;

            // END TESTING ------------------------------------------------------------------------------------------------------------------------------------
            default:
                break;
            }

            return(result);
        }