private void Start() { //we can add our own type to the StringToType system StringToType.SetConverterDelegateForType( typeof(ConsoleStaticCommandsTest.SomethingSupported), (s) => { return(new ConsoleStaticCommandsTest.SomethingSupported() { val = int.Parse(s) }); }); //we temp bind the error log to nothing, so we aren't spammed during adding items we know will // have lots of failures. var prevLog = ConsoleBindingHelper.OnErrorLogDelegate; ConsoleBindingHelper.OnErrorLogDelegate = delegate { }; //binding a class intended to have all static items added ConsoleBindingHelper.AddAllToConsole(null, null, typeof(ConsoleStaticCommandsTest)); //binding a specific instance to the console ConsoleBindingHelper.AddAllToConsole(instTest, "instTest"); //binding a class that is a monostate/c# wrapper around a singleton from Unity ConsoleBindingHelper.AddAllToConsole(null, null, typeof(Physics)); Console.Log("Try entering Console.AddStaticTypeByString Physics2D"); //restore the logger ConsoleBindingHelper.OnErrorLogDelegate = prevLog; }
// Start is called before the first frame update private void Start() { ConsoleBindingHelper.OnErrorLogDelegate = BindingLog; ConsoleBindingHelper.AddAllToConsole(null, null, typeof(Physics)); if (bindingErrors.Count > 0) { UnityEngine.Debug.LogWarning(bindingErrors.Count.ToString() + " errors during AddAll Physics"); } ConsoleBindingHelper.OnErrorLogDelegate = UnityEngine.Debug.LogError; bindingErrors.Clear(); }
public static void AddStaticTypeByString(string typeName) { var alltypes = System.AppDomain.CurrentDomain.GetAssemblies().SelectMany(x => x.GetTypes()); var t = alltypes.FirstOrDefault(x => x.Name == typeName); if (t == null) { Console.Log("Could not find type of name " + typeName + ". Make sure you are using the correct namespaces, nestedclass and assembly."); return; } ConsoleBindingHelper.AddAllToConsole(null, null, t); Console.Log("Found " + typeName + " in " + t.Assembly.FullName); }