|
24 | 24 | 1. Clone or download the **O2 Console** repository or download the unity package. |
25 | 25 | 2. Import the O2 Console scripts into your Unity project. |
26 | 26 | 3. **Set up the Console UI**: The project includes a ready-to-use prefab for the console. Simply drag and drop the prefab into your scene to integrate the in-game console with an input field and log display. |
27 | | - |
28 | 27 | 4. Optionally, configure a hotkey to toggle the console (e.g., `~` key). |
29 | 28 |
|
30 | 29 | ### Usage |
31 | 30 |
|
32 | 31 | To define a console command, simply use the `[ConsoleCommand]` attribute above any static or instance method, as well as public or private properties. The console will automatically register it for in-game use. |
33 | 32 |
|
| 33 | +Property & Field Example (Public & private) |
34 | 34 | ```csharp |
35 | | -// Method Example |
36 | | -[ConsoleCommand("SomeFunction")] |
37 | | -static void SomeFunction() |
38 | | -{ |
39 | | - // Do Something |
40 | | -} |
41 | | - |
42 | | -// Property Example (Public) |
43 | | -public class ExampleClass |
44 | | -{ |
45 | | - private int _value; |
46 | | - |
47 | 35 | [ConsoleCommand("GetValue")] |
48 | | - public int Value |
49 | | - { |
50 | | - get { return _value; } |
51 | | - set { _value = value; } |
52 | | - } |
53 | | -} |
| 36 | + public int Value {get; set;} |
54 | 37 |
|
55 | | -// Property Example (Private) |
56 | | -public class ExampleClass |
57 | | -{ |
58 | | - private int _privateValue; |
| 38 | + [ConsoleCommand("GetStaticValue")] |
| 39 | + public static int StaticValue {get; set;} |
59 | 40 |
|
60 | 41 | [ConsoleCommand("GetPrivateValue")] |
61 | | - private int PrivateValue |
62 | | - { |
63 | | - get { return _privateValue; } |
64 | | - } |
65 | | -} |
| 42 | + private int PrivateValue; |
| 43 | +``````` |
| 44 | +Instance & Static Method Example |
| 45 | +```csharp |
66 | 46 |
|
67 | | -// Instance Method Example |
68 | | -public class ExampleInstance |
69 | | -{ |
70 | 47 | [ConsoleCommand("InstanceMethod")] |
71 | 48 | public void InstanceMethod() |
72 | 49 | { |
73 | 50 | // Do Something |
74 | 51 | } |
75 | | -} |
76 | | - |
77 | | -// Static Property Example |
78 | | -public class StaticExample |
79 | | -{ |
80 | | - private static int _staticValue; |
81 | | - |
82 | | - [ConsoleCommand("GetStaticValue")] |
83 | | - public static int StaticValue |
| 52 | + |
| 53 | + [ConsoleCommand("SomeFunction")] |
| 54 | + static string SomeFunction() |
84 | 55 | { |
85 | | - get { return _staticValue; } |
86 | | - set { _staticValue = value; } |
| 56 | + return // Do Something |
87 | 57 | } |
88 | | -} |
89 | 58 | ``````` |
0 commit comments