private void Start() { AllPlayers.Add(this); if (HasLocalOwnership) { UI.AddDrawer(DrawUI); } }
private void Start() { JNet.Init("Project B"); // TODO move to somewhere more sensible, such as 'game manager' Spawnables.NetRegisterAll(); UI.AddDrawer(DrawUI); }
private void Awake() { UI.AddDrawer(DrawUI); LoadCommands(); Input = new IMGUIWindow(int.MaxValue, new Rect(100, 100, Width, Height), "Console", () => { var e = Event.current; if (e.type == EventType.KeyDown && e.keyCode == KeyCode.Return && !string.IsNullOrWhiteSpace(CurrentCommand)) { SubmitCommand(CurrentCommand); CurrentCommand = string.Empty; } if (e.type == EventType.KeyDown && e.keyCode == KeyCode.UpArrow) { BrowseHistory(1); } else if (e.type == EventType.KeyDown && e.keyCode == KeyCode.DownArrow) { BrowseHistory(-1); } var items = GetSuggestions(CurrentCommand); string suggestions = GetSuggestionString(items); bool tabbed = false; if (e.type == EventType.KeyDown && e.keyCode == KeyCode.Tab) { if (items.Count > 0) { tabbed = true; } } float SafeZone = 15f; var previous = GUI.skin; GUI.skin = CustomSkin; GUILayout.Label(RichText.InColour(suggestions, Color.white * 0.8f)); GUILayout.BeginHorizontal(); if (tabbed) { CurrentCommand = items[0]; } GUI.SetNextControlName("CMDInput"); CurrentCommand = GUILayout.TextField(CurrentCommand, GUILayout.MaxWidth(Width - 50)); if (firstFrame) { GUI.FocusWindow(int.MaxValue); GUI.FocusControl("CMDInput"); firstFrame = false; } if (tabbed) { var txtF = (TextEditor)GUIUtility.GetStateObject(typeof(TextEditor), GUIUtility.keyboardControl); txtF.cursorIndex = CurrentCommand.Length; txtF.selectIndex = CurrentCommand.Length; } bool pin = GUILayout.Button(Pin, GUILayout.ExpandWidth(false)); if (pin) { PinCmd(CurrentCommand); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); // Log view area. scroll = GUILayout.BeginScrollView(scroll, false, true, GUILayout.Width((Width - SafeZone) * LOG_AREA)); for (int i = Log.Count - 1; i >= 0; i--) { var item = Log[i]; item.Draw(); } GUILayout.EndScrollView(); // Pinned commands area. scroll2 = GUILayout.BeginScrollView(scroll2, false, true, GUILayout.Width((Width - SafeZone) * (1f - LOG_AREA))); // Single pinned command. for (int i = 0; i < PinnedCommands.Count; i++) { var cmd = PinnedCommands[i]; GUILayout.BeginHorizontal(); bool run = GUILayout.Button(cmd, GUILayout.MaxWidth(100)); if (run) { ExecuteCommand(cmd); } bool delete = GUILayout.Button(Bin, GUILayout.ExpandWidth(false)); if (delete) { PinnedCommands.RemoveAt(i); i--; } GUILayout.EndHorizontal(); } GUILayout.EndScrollView(); GUILayout.EndHorizontal(); GUI.skin = previous; }); }