Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

In-game Console

Discussion in 'Made With Unity' started by CrashKonijn, Dec 8, 2011.

  1. CrashKonijn

    CrashKonijn

    Joined:
    Mar 4, 2010
    Posts:
    242
    Hello,

    I made a in-game console this week. I got tired of always having to lookup 10.000 of options to change them every time I start the game. I did my best to make it as variable and easy expandable as I could.

    I figured I'd show it to you guys and get some feedback and tips.

    http://www.CrashKonijn.com/unity/Console/WebPlayer.html
    The rest of the project is of my internship I started last week so don't mind that :)

    I'm working on a MB pro no windows and then you can open the console with the button above the tab/left from the 1 key. If that key doesn't work the ` key should work.

    The console is Case sensitive but you can search using a part of a command. You can select the top auto-match by pressing the down button.

    Greetings,
    Peter

    These are the commands I currently have
    Code (csharp):
    1. Help
    2. Camera.Effect.Bloom [boolean]
    3. Camera.Effect.Blur [boolean]
    4. Camera.Effect.SSAO [boolean]
    5. Camera.Effect.SunShafts [boolean]
    6. Camera.RenderingPath [Vertex/Forward/Deferred]
    7. QualitySettings.IncreaseLevel
    8. QualitySettings.DecreaseLevel
    9. QualitySettings.Quality [Fastest/Fast/Simple/Good/Beautiful/Fantastic]
    10. QualitySettings.pixelLightCount [int]
    11. QualitySettings.shadowDistance [int]
    12. QualitySettings.anisotropicFiltering [Disable/Enable/ForceEnable]
    13. QualitySettings.masterTextureLimit [Full/Half/Quarter/Eighth]
    14. Console.Settings.MaxMatch [int]
    15. Console.Settings.MaxLog [int]
    16. Console.Output.Commands
    17. Console.Output.Log
    18. Application.Quit
    19. Debug.Log [String]
    20. Debug.LogWarning [String]
    21. Debug.LogError [String]
    22. ObjectController.Select.Next
    23. ObjectController.Select.Prev
    24. ObjectController.Select.Class [int]
    I can add a command to the script like this:
    Code (csharp):
    1. AddCommand("Camera.Effect.Bloom","Camera.Effect.Bloom [boolean]","CameraEffectBloom");
    The first variable is the name of the command itself.
    The second variable is the help text that will be shown in the auto-match.
    The third variable is the name of the function.

    I can feedback to the log like this:
    Code (csharp):
    1. AddFeedback("Error: Unknown function");
    This is a example of a function:
    Code (csharp):
    1. function CameraEffectBloom(tBoolean){
    2.     tBoolean = tBoolean.ToLower();
    3.     if(tBoolean == "true" || tBoolean == "false"){
    4.         tBoolean = HandleStringBoolean(tBoolean); // tBoolean is currently a string, make it a boolean
    5.         if(Camera.main.gameObject.GetComponent(BloomAndLensFlares)){
    6.             Camera.main.gameObject.GetComponent(BloomAndLensFlares).enabled = tBoolean;
    7.             //AddFeedback("Succesfull: "+ tBoolean +" @Camera.Effect.Bloom [True/False]");
    8.             return;
    9.         }
    10.         else {
    11.             AddFeedback("Error: Unable to handle effect @Camera.Effect.Bloom [True/False]");
    12.             return;
    13.         }
    14.     }
    15.     else {
    16.         AddFeedback("Error: No boolean @Camera.Effect.Bloom [True/False]");
    17.         return;
    18.     }
    19. }
     
  2. CrashKonijn

    CrashKonijn

    Joined:
    Mar 4, 2010
    Posts:
    242
    No one has anything to say about this?
    I'm trying really hard to learn programming and since I don't have any teachers that can help (I'm studying game design) with programming I was hoping at least some of you had some tips for me.
    I'm thinking of giving it to the community for free (So we can bundle commands) but I first want to make the script very good :)
     
  3. andorov

    andorov

    Joined:
    Feb 10, 2011
    Posts:
    1,061
    Your programming actually looks pretty OK.

    How about looking into system.reflection and setting up some kind of mini parser that allows users to run free-form code?

    For example,

    // Executes the static method "Find" on the static class "GameObject" and stores the result in a temporary variables
    >> var storVar = ExecuteStatic("GameObject", "Find", "-Player")
    // Executes the method 'ToString' on the stored object
    >> ExecuteOnInstance(storVar, "ToString")
     
  4. CrashKonijn

    CrashKonijn

    Joined:
    Mar 4, 2010
    Posts:
    242
    I think that such commands should be in the console indeed.
    But I think I need to look into my function that calls the function from the commands first.
    Currently I only got it working like this:
    Code (csharp):
    1. function HandleConsoleCommands () {
    2.     if(pressedEnter){
    3.         AddFeedback(consoleInput);
    4.         var inputArray : Array = consoleInput.Split(" "[0]); // Split the text where there is a space
    5.         if(consoleCommandsMatch.length >= 1){
    6.             if(inputArray[0] == consoleCommands[consoleCommandsMatch[0]]){
    7.                 //Debug.Log("Handle: " + inputArray[0]);
    8.                
    9.                 // Create String with variables. This was an attempt to make 1 string of all the variables and send tem. But then I'd have to de-hash them in all of the functions...
    10.                 /*
    11.                 var tVariables : String = "";
    12.                 for(var i : int = 1; i < inputArray.length; i++){
    13.                     if(i >= 2){
    14.                         tVariables += ",";
    15.                     }
    16.                     tVariables += inputArray[i];
    17.                 }*/
    18.                
    19.                 if(inputArray.length >= 2){
    20.                     gameObject.SendMessage (consoleCommandsFunction[consoleCommandsMatch[0]], inputArray[1]);
    21.                 }
    22.                 else {
    23.                     gameObject.SendMessage (consoleCommandsFunction[consoleCommandsMatch[0]]);
    24.                 }
    25.             }
    26.             else {
    27.                 AddFeedback("Error: Unknown function");
    28.             }
    29.         }
    30.         else {
    31.             AddFeedback("Error: Unknown function");
    32.         }
    33.         consoleInput = "";
    34.     }
    35.     pressedEnter = false;
    36. }
    The problem here is that if you run a command that requires a variable and you don't give that variable that It will run into an error. Also its not yet possible to have more than 1 variable send to a function... So I'd better rewrite that first I guess :)

    Thanks for you're feedback! I'm going to work on it :cool:
     
  5. venhip

    venhip

    Joined:
    Jul 7, 2012
    Posts:
    6
    This looks really good, it's very impressive! I don't suppose you'd mind pointing me in the direction of a tutorial or something please? I sort of understand how you've done it but highly doubt I'd be able to implement it by myself. Thanks.