MrMcMuffin Posted May 29, 2015 Share Posted May 29, 2015 _____________________________________________________________________using UnityEngine;using System;using System.Timers;namespace MachGuage{ public class MachGuage : Plugin { private static Timer aTimer; aTimer.Tick //this hopefully will do all the calculations for converting m/s to mach { MachNumber = (this.Velocity * 0.0029411764705882); { Round(MachNumber); } } private Rect _windowposition = new Rect(); private GUIStyle _windowStyle, _labelStyle; private bool _hasInitStyles = false; public override void OnStart(StartState state) { aTimer = new System.Timers.Timer(20) aTimer.Enabled = true; if (state != StartState.Editor), { if (!_hasInitStyles) InitStyles(); RenderingManager.AddToPostDrawQueue(0, OnDraw); } } private void OnDraw() { if (this.vessel == FlightGlobals.ActiveVessels) _WindowPosition = GUILayout.Window(10, _windowPosition, OnWindow, "Mach Guage") } Private void OnWindow(int windowId) { GUILayout.BeginHorizontal(GuiLayout.Width(100f)); GUILayout.label(aTimer.Tick = MachNumber); if (MachNumber == 0) { GUILayout.Label("You are not moving. and now the guage is bored"); } GUILayout.EndHorizontal(); GUI.DragWindow(); } prvate void InitStyles() { _windowStyle = new GUIStyle(HighLogic.Skin.Window); _windowStyle.fixedWidth = 100f _labelStyle = new GUIStyle(HighLogic.Skin.label); _labelStyle.stretchWidth = true; _hasInitStyles = true; } }}the copy from pastebin messed up the brackets and stuff sorry about that_______________________________________________________________________________________________This is supposed to be a mach gauge, and my first time doing anything with C#. If you revise it will you please send me the code via private message. You will be given credit for your help when i eventually release the plugin. by the way, I would like integration with the default toolbar so i dont have to make a part.Thanks,Ryan:D:D Link to comment Share on other sites More sharing options...
MrHappyFace Posted May 29, 2015 Share Posted May 29, 2015 (edited) All of it seems fine except this:private static Timer aTimer;aTimer.Tick //this hopefully will do all the calculations for converting m/s to mach{MachNumber = (this.Velocity * 0.0029411764705882);{Round(MachNumber);}}You should just use the OnUpdate() method like this:public override void OnUpdate (){ MachNumber = (this.Velocity * 0.0029411764705882); Round(MachNumber);}Also, you should extend PartModule, not Plugin. Plugin isn't even a class.Also, are you using an IDE like MonoDevelop/Xamarin Studio or Visual Studio, or are you just using Notepad, because you should be using an IDE. Edited May 29, 2015 by MrHappyFace Link to comment Share on other sites More sharing options...
MrMcMuffin Posted May 29, 2015 Author Share Posted May 29, 2015 Thanks so much MrHappyFace, I'm about to transfer it to an IDE. should this work without a part, and how do i get it on the toolbar Link to comment Share on other sites More sharing options...
MrHappyFace Posted May 29, 2015 Share Posted May 29, 2015 If you want it without a part, then do something like this:[KSPAddon(KSPAddon.Startup.Flight, false)] //this spawns your addon seperate from any part. Can run in any game scene including the loading screen, the main menu, the editor, and in flightpublic class MachGauge : MonoBehaviour //Read up on the unity documentation for MonoBehaviour [URL="http://docs.unity3d.com/ScriptReference/MonoBehaviour.html"]here[/URL]{ //replace OnStart(StartState state) with Start() //replace OnUpdate() with Update() //use FlightGlobals.ActiveVessel instead of vessel or part}And for the toolbar, use the official documentation: http://forum.kerbalspaceprogram.com/threads/86682-Appilcation-Launcher-and-Mods Link to comment Share on other sites More sharing options...
NathanKell Posted May 30, 2015 Share Posted May 30, 2015 Also, parts and vessels already have mach numbers (vessel.mach and part.machNumber) you don't have to (and shouldn't*) calculate it yourself.*I mean, you could. But if you do, you'll need to calculate the speed of sound, first. Link to comment Share on other sites More sharing options...
MrMcMuffin Posted May 30, 2015 Author Share Posted May 30, 2015 You are right nathan. I wont be calculating a single damn thing. Thanks. Here the revised label codePrivate void OnWindow(int windowId){GUILayout.BeginHorizontal(GuiLayout.Width(100f));GUILayout.label(vessel.mach);} Link to comment Share on other sites More sharing options...
MrMcMuffin Posted May 31, 2015 Author Share Posted May 31, 2015 Also, parts and vessels already have mach numbers (vessel.mach and part.machNumber) you don't have to (and shouldn't*) calculate it yourself.*I mean, you could. But if you do, you'll need to calculate the speed of sound, first.By the way you gonna update real solar system any time soon Link to comment Share on other sites More sharing options...
Crzyrndm Posted May 31, 2015 Share Posted May 31, 2015 (edited) That code won't actually work, you need to close any layout groups (ie. you're missing a GUILayout.EndHorizontal()). There's a simpler way to do it aswell:private void OnWindow(int windowId){ GUILayout.label(vessel.mach.ToString(), GUILayout.Width(100f));}EDITFormatting would probably be useful as wellprivate void OnWindow(int windowId){ GUILayout.label(vessel.mach.ToString("0.000"), GUILayout.Width(100f)); // prints a number rounded to 3dp in a label 100 units wide} Edited May 31, 2015 by Crzyrndm Link to comment Share on other sites More sharing options...
MrMcMuffin Posted May 31, 2015 Author Share Posted May 31, 2015 Good news guys, the mod is finished. thanks for all the help and support. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now