Search the Community
Showing results for tags 'callback'.
-
Hello, I am trying to create a new GUI window in KSP but when I call my delegate callback(onDraw()), VS errors on me. I've looked at the API pages, Unity tutorials and C# pages for help but have been unable to fix the issues. I'd greatly appreciate any help. Below is my code along with the VS errors. namespace KSP_Wind_Display { // public delegate CallBack(int que, int onDraw); public class Wind_GUI_Display : PartModule { delegate void CallBack(); CallBack callback; private Rect window_pos = new Rect(); // New blank window private GUIStyle window_style, label_style; private bool has_init_styles = false; public override void OnStart(PartModule.StartState state) { base.OnStart(state); if (!has_init_styles) init_styles(); callback += onDraw; if (state != StartState.Editor) RenderingManager.AddToPostDrawQueue(0, callback()); <-------- Error 11 The best overloaded method match for 'RenderingManager.AddToPostDrawQueue(int, Callback)' has some invalid arguments <-------- Error 12 Argument 2: cannot convert from 'void' to 'Callback' } private void onDraw() // Start up the window { if (this.vessel == FlightGlobals.ActiveVessel) window_pos = GUILayout.Window(10, window_pos, onWindow, "Wind Direction", window_style); } private void onWindow(int window_id) { GUILayout.BeginHorizontal(); GUILayout.EndHorizontal(); GUI.DragWindow(); // Makes the window draggable } private void init_styles() { window_style = new GUIStyle(HighLogic.Skin.window); window_style.fixedWidth = 250.0f; label_style = new GUIStyle(HighLogic.Skin.label); label_style.stretchWidth = true; // stretches the label width to that of the window has_init_styles = true; } } } For Error 11, shouldn't that result in onDraw() being called. AddToPostDrawQueue needs an int and Callback as it's arguments and that's what I am passing it. For Error 12, I suspect the problem is where I first declare Callback to be void type of delegate. However, I don't want Callback to return anything so it has to be a void. I've worked at this problem for about 2 hours now and online forums, tutorials and man pages haven't help. Can someone here spot the issue and at least give me a hint on how to resolve it? Thanks in advance.