-
Posts
2,077 -
Joined
-
Last visited
Content Type
Profiles
Forums
Developer Articles
KSP2 Release Notes
Everything posted by Diazo
-
Changing maximum Resource in-flight
Diazo replied to steedcrugeon's topic in KSP1 C# Plugin Development Help and Support
I don't think MM can do what you want, MM can only edit 'the' part, not 'a' part. By that I mean if you change the max EC on a part, you change it on all parts in-game. This includes the 'unbuilt' parts in the editor and all parts that exist in flight. First, you are trying to do the following correct? -Part spawns with 3001 max EC which auto-fills on launch. -Cryo happens, part max EC drops to 50. -Some other trigger (Time delay?), the part max EC goes back to 3001. You can set the original max amount with MM (or just in the part.cfg as you are making this part I assume), but changing it in game will require a plug-in to detect when the change should happen and then editing the Part.Resources.Get("ElectricCharge").maxAmount value as needed. As for what @Li0n suggested, I wouldn't recommend it. While it might work, it's not working as intended because a part is not 'supposed' to be able to contain more resources (currentAmount) then it can hold (maxAmount). This sort of thing is what causes mod conflicts as other people (including Squad) will assume a part can't hold more resources then maxValue when they are working on their own stuff. D. -
Changing maximum Resource in-flight
Diazo replied to steedcrugeon's topic in KSP1 C# Plugin Development Help and Support
Not sure what you mean by "in stock", you'd have to write a plug-in, but changing the max amount is simply changing the Part.Resources.Get("ElectricCharge").maxAmount value. The only catch is I have done almost nothing with resources and don't know what the persistence of that value is. (If it saves once set, or you'll have to set if every time the part loads.) D. -
Adding to the right-click menu on other craft
Diazo replied to Superfluous J's topic in KSP1 Mod Development
Isn't that just a KSPEvent with guiActiveUnfocused = true? Not sure about the center camera option, but the docking port one is almost certainly that. D. -
The code I used was supposed to (at least as I understand it) make the Altitude Tumblers in a clickable button. So I don't know why only the left half of the tumblers are clickable, or why down in the pressure gauge is also clickable. I spent significant time trying to figure it out and ultimately decided that Squad has done something with invisible objects to make everything work (that tumbler is complicated) and without knowing that I would not be able to figure it out so I went with the best I could manage. As for the text, while GUI space was a concern, the fact that it can be hidden and the fact that I really wanted to have the actual "ASL" or "AGL" text display (and not just a light) drove my decision to show it as I did. D.
-
Version 2.0 Add ability to display and/or lock the current display mode. Download from Github here. New Version 2.0: Mode Display AGL: Altimeter showing distance to ground/object below vessel. ASL: Altimeter showing distance to sea level. Green Text or no text visible: Automatic mode based on Surface or Orbital mode as displayed just above nav-ball. Red Text: Mode locked, will always stay in the displayed mode. Click inside the red box to change mode, this is a game-wide setting. Due to oddities in how the UI works I could not make the entire altimeter clickable, just the left side. (Red box is not visible in-game.) Happy KSPing all. D.
-
Interesting question. Posting my answer before reading the rest of the thread. The interesting part about this is what is false? Take the "Either it was James or none of us did it." If this statement is False, does that mean BOTH James didn't do it and that one of us did it? In solving the puzzle, I took it to mean that both parts of the statement had to be true for it to be true, otherwise it was false. But if you take that statement to be false only if both conditions are false, it changes the reasoning for why it couldn't be James who ate the soup even if it doesn't change the conclusion that it was Dave who did it. D. edit: After reading the thread, it is interesting to see that while I did reach the same conclusion I did it differently in that I went in order every time, while the rest of the thread started with the person making the statement first instead of from the top each time.
- 12 replies
-
- cabbage soup
- question
-
(and 1 more)
Tagged with:
-
I apparently have work on the brain. I read that as MSQLDB and went "of course the forum runs on Microsoft SQL Server Database, why's that a moderator secret?" After a second look I realized it was MQDB instead and now I'm wondering.... Moderators Quietly Drinking Beer? D.
-
Can confirm MM does this. It makes a subfolder named MMCfg and a .cfg file for each part as it loads in the game. D.
-
In direct response to this thread, I wrote up a thread on the absolute basics of writing a plug-in for new modders to get started. It is a very basic overview of KSP modding and covers stuff such as what references are needed in your IDE and what a PartModule is. Could this get a sticky so that new modders have a place to start from that explains the objects and terms used?
-
@Darth Pseudonym I will confirm that ModActions does in fact add the Control From Here option as an action on all command capable parts and docking ports. D.
-
The basics, getting started with writing plug-ins. Welcome to a quickstart guide on how to start writing a code plug-in for Kerbal Space Program. This is a quick guide intended as an overview on getting started and what hooks are available in KSP where you can attach your code. It is not intended as a step-by-step tutorial, rather it is intended to make you aware of your options so you can then investigate in more detail which options you wish to use. IDE Setup The hooks. KSPAddon ScenarioModule VesselModule PartModule Common Methods Common References On-Screen GUI Toolbar button GameEvents System ConfigNode overview Save/Load Data 1) IDE Setup Writing a code plug-in for KSP is done in C# so we need a program (IDE) to write code in that can produce the .dll file from that code that KSP will recognize. Any program that can make .dll files will work, this document uses Microsoft Visual Studio for its examples. Once the IDE program is installed, start a new project and make sure you set the “.Net Version 3.5”. If you do not the project will compile for the most recent version of .Net which is 4.5 and KSP will not handle it correctly and throw errors when it tries to load. We then need to tell the IDE where to find the References to the KSP files. In your project, add a reference to UnityEngine.dll, UnityEngine.UI.dll, Assembly-Csharp.dll, Assembly-Csharp-firstpass.dll. These files are found in the “KSP_Install\KSP_x64_Data\Managed”. Then at the top, add a line below “using System;” that says “using UnityEngine”. Our blank project is now ready to go and we can start coding. To test, copy-paste the following code into your program: using System; using UnityEngine; namespace HelloWorld { [KSPAddon(KSPAddon.Startup.MainMenu, false)] public class Hello : MonoBehaviour { public void Update() { Debug.Log("Hello world! " + Time.realtimeSinceStartup); } } } then compile your .dll file and place it in the KSP_Install\GameData folder. It can be in a sub-folder, typically you will make a sub-folder for your mod in order for the players to keep things straight. When you start KSP and reach the main menu, if everything is setup correctly, the code above will spam "Hello world!" to the console which is toggled on with Alt-F12. It will also append the time since the game was started so you can see the lines of text change. 2) Basic hooks In order to actually do anything, we need to hook into KSP so that our code will run. There are 4 ways to do this, which one you use will depend on what purpose your code has. Note that using multiple methods for different pieces of code is a valid approach. KSPAddon The KSPAddon hook is used when you want to run some code that is attached to a specific scene. Use this when you code runs and affect the Flight scene, the Tracking Station scene, the Editor scene, and so on. KSP will automatically create an instance of a class tagged this way at the start of the scene and destroy it at the end of the scene. Note: There is no integrated save/loading of data in the KSPAddon hook, you must do that manually. Use cases: Permanent changes to how the scene works, either the game-space itself or the UI. As there is no save/loading of data, the changes need to be the same every time. KSPAddon(Scene,Dont_Destroy) Scene: The Scene enumerator, in which scene does an instance of this class get loaded. This takes values from the KSPAddon.Startup enum and multiple values to start in multiple scenes can be selected. Dont_Destroy: Don’t destroy the class when the scene ends. Highly recommended to leave false until you understand how Unity creates/destorys objects in and across different scenes. Is a boolean value. [KSPAddon(KSPAddon.Startup.Flight, false)] public class MyKSPAddon : MonoBehavior { //your code here. } This will tell KSP to spawn an instance of MyKSPAddon when the Flight scene starts and destroy it when the Flight scene ends. It is high recommended that the class inherit from MonoBehavior (or other class that inherits from MonoBehavior) so that the Common Methods are available to you. ScenarioModule The Scenario Module is used for when a mod needs to affect a large part of the game and provides the ability to Save/Load data. One caveat is that different scenes have different objects so make sure to check what scene you are in before referencing objects that exist in multiple scenes. ScenarioModule(ScenarioCreatingOptions, Gamescene) ScenarioCreationOptions: What type of games do we add this to? Take from the ScenarioCreateOptions enum. GameScene: The Scene enumerator, in which scene does an instance of this class get loaded? Takes from the GameScenes enum. [KSPScenario(ScenarioCreationOptions.AddToNewCareerGames | ScenarioCreationOptions.AddToExistingCareerGames, GameScenes.SPACECENTER)] class MyScenario : ScenarioModule { //your code here } This will add you ScenarioModule to all games in career mode and create an instance of this class in the Space Center scene. Note that it must inherit ScenarioModule. VesselModule An single instance of a VesselModule is automatically added to every vessel that exists (can be switched to in the tracking station). Note that VesselModule's will still execute for unloaded vessels which PartModules will not. public class MyVesselModule : VesselModule { //your code here. } A VesselModule must inherit from VesselModule and no Attribute is required on the preceding line. Note that while a VesselModule does save/load data it does not have any provision for transfer of data between two VesselModules, such as when two vessels dock and combine, or an undock happens and a single vessel becomes two. PartModule A PartModule is a class that gets attached to a part. This is done through the use of ModuleManager (another mod) and scripts that control which parts your PartModule gets attached to. These scripts are very flexible and you can attach only to your desired parts and attach multiple instance of your PartModule if you desire. Module Manager download, and instructions on how to use, can be found here. public class MyPartModule : PartModule { //your code here. } A PartModule must inherit from PartModule. 3) Common Methods There are several common methods inside these 4 hooks that KSP will automatically execute for you. (This section assumes KSPAddon inherits from MonoBehavior.) public void Awake() { } KSPAddon, ScenarioModule, VesselModule, PartModule Called once and runs when an instance of the class is first created. Not recommended in most cases as it may not run when you expect as this is not tied to a scene. Not recommended at all in PartModule as KSP uses Awake() in a PartModule for its own purposes. public void Start() { } KSPAddon, ScenarioModule, VesselModule, PartModule Called once and is where any setup or “on-spawn” code should go. This method runs when your class spawns into the correct scene and runs before all other methods (except Awake()). Note that all Start() methods that need to run in a scene run sequentially, if you are trying to reference another object it may not exist yet and could require using a Coroutine to delay running some of your code. public void Update() { } KSPAddon, ScenarioModule, VesselModule, PartModule Called every update frame and is in sync with the actual frame that gets drawn on the monitor. If KSP is running at 60fps, this method will get called 60 times a second, once for each frame on the monitor. Anything code relating to the UI or the player interacts with should go here. public void FixedUpdate() { } KSPAddon, ScenarioModule, VesselModule, PartModule Called every physics frame and anything physics or game related should happen here. Caution: Update and FixedUpdate are NOT synchronized. Depending on current frame rates and demand on the CPU, multiple (or no) Update frames could happen between two FixedUpdate frames, or multiple (or no) FixedUpdate frames could happen between two Update frames. public void OnDisable() { } KSPAddon, ScenarioModule, VesselModule, PartModule Runs when the class is destroyed. Important for unsubscribing from GameEvents and destroying Toolbar buttons. Public void OnSave(ConfigNode node) { } ScenarioModule, VesselModule, PartModule Run when a game save happens. You can add your data to the node object in order to load it later. Note that any KSPFields are automatically save/loaded and do not require using this method. public void OnLoad(ConfigNode node) { } ScenarioModule, VesselModule, PartModule Run when a game load happens. Any data added to the node object in the OnSave method will be available in the node object passed by KSP to this method. Note that any KSPFields are automatically save/loaded and do not require using this method. 4) Common Properties/Objects FlightGlobals.ActiveVessel (Flight): A static that is the vessel that currently has focus. Vessel.Parts (Flight): A list of Parts on the vessel. EditorLogic.sortedShipList (Editor): A list of parts placed in the Editor. Part.Modules (Editor/Flight): A list of PartModules attached to this part. PartModule.vessel(Flight): The vessel containing the part this partModule is attached to. This is different than FlightGlobals.ActiveVessel KSPField Attribute. Tag an object with this inside a PartModule, VesselModule, or ScenarioModule and KSP will automatically save and load it for you. Note that only data types of string, bool, int, float, Vector2, Vector3, Vector4 or Quaternion can be tagged this way. Notably this means that the double data type can not be a KSPField. [KSPField(isPersistant = true, guiActive = false)] public bool savedBoolean; This will cause KSP to automatically save/load whether savedBoolean is true or false and it will not be visible in the GUI. If you set one of the GUI booleans to true, the KSPField will show in that part's right click menu (when in a partModule) so the player can edit the value in-game. KSPEvent Attribute: Only available in a PartModule, this causes a button to show in a Part's right-click menu in editor and flight mode to execute the attached code. [KSPEvent(guiName ="MyEvent")] public void MyEvent() { //code to run on player clicking button in part right-click menu } The guiName variable is the text that will be visible to the player in-game. There are several other values that can be set as well to control visibility of the Event, but there are too many to list here so check the Object Viewer in your IDE for them all. KSPAction Attribute: Only available in a PartModule, this adds an action to the action group list for a part in the editor so the player can add it to an action group. [KSPAction("MyAction")] public void myAction(KSPActionParam param) { //code to run when the player presses the action group key. } The "MyAction" text is what will show in game as the action name. KSPActionParam param is just a fancy boolean passed to the method to indicate if the action group is being activated or deactivated. 5) On-Screen GUI Legacy GUI system (Obsolete). Before KSP 1.0/1.1, what is now referred to at the LegacyGUI system was used. This method used the OnGUI() method to draw 2D UI objects on the screen. It is recommended that you not use this system any more and use the current UI Canvas system. UI Canvas system (Current). Please see this guide: http://forum.kerbalspaceprogram.com/index.php?/topic/151354-unity-ui-creation-tutorial/ UI creation is a complex beast with 3 different ways of doing it and the link covers how to work with it. 6) Toolbar button. Squad has a write-up of how to make a button on the stock toolbar here: http://forum.kerbalspaceprogram.com/index.php?/topic/78231-application-launcher-and-mods/ Blizzy's toolbar is also popular and instructions for using it can be found here: http://forum.kerbalspaceprogram.com/index.php?/topic/54734-120-toolbar-1713-common-api-for-draggableresizable-buttons-toolbar/ 7) GameEvents system. The GameEvents system is how you trigger parts of your code to run when events in the game happen. All the available GameEvents in the stock game can be found in the GameEvents class in the object browser. public void Start() { GameEvents.onPartDie.Add(PartDead); } public void PartDead(Part p) { //add code here to run when a part dies. //Note that this event fires every time a part dies. //You will have to check Part p to see which part died, it is not necessarily the part this piece of code is attached to. } public void OnDisable() { GameEvents.onPartDie.Remove(PartDead); } Here we subscribe to the GameEvent so that the PartDead method will run anytime a part is destroyed. Note this will run anytime a part dies, so in a big crash this method will run many times, once for each part that dies. Note that we unsubscribe in the OnDisable method. This is very important as if you forget this step you will cause Null-Ref errors as anytime a part dies, KSP will still try to call your PartDead method even though it no longer exists. As of KSP 1.2.2, mods can now trigger game events that other mods can subscribe to for inter-mod communication. Further details on this can be found here: http://forum.kerbalspaceprogram.com/index.php?/topic/153112-ksp-122-gameevents-extension/ 8) ConfigNode overview. KSP uses ConfigNodes to save/load data. A configNode has the following structure: NODE { key1 = value1 key2 = value2 SUBNODE1 { key3 = value3 key4 = value4 } } The only valid data type in a ConfigNode is string and is made up of Nodes and Key/Value pairs. The following code makes the above node layout: ConfigNode myNode = new ConfigNode("NODE"); myNode.AddValue("key1","value1") myNode.AddValue("key2","value2") ConfigNode mySubNode1 = new ConfigNode("SUBNODE1") myNode.AddNode(mySubNode1); mySubNode1.AddValue("key3","value3") mySubNode1.AddValue("key3","value3") Then to retrieve values, the following code extracts them from the node: ConfigNode myNode = //load ConfigNode here, see section 9, Save/Load data. string myValue1 = myNode.GetValue("key1"); string myValue2 = myNode.GetValue("key2"); ConfigNode mySubNode1 = myNode.GetNode("SUBNODE1"); string myValue3 = mySubNode1.GetValue("key3"); string myValue4 = mySubNode1.GetValue("key4"); Note that ConfigNodes are very dumb. If you GetValue('Key5") when Key5 doesn't exist, KSP throws a Null Reference Exception and stop running your code. If you AddValue("Key1","Value1") when the node already has a Key1 present it will add a second Key1 value to the node instead of updating the existing value. You can SetValue("Key1","Value1") instead to update an existing Key1 value, but if Key1 doesn't exist, it will Null Reference and stop running your code. When working with ConfigNodes, you can use the "Debug.Log(MyConfigNode.ToString()); command to print the contents of the entire ConfigNode to the log. 9) Save/Load data. The simplest way to save/load data is to use the KSPField attribute as listed in the Common Properties/Objects section and let KSP do all the work for you. If you needs are more complex you can use the OnSave/OnLoad methods to save to the confignode, or you can directly save to a file on disk. OnSave/OnLoad methods: Public void OnSave(ConfigNode node) { node.AddValue("myValue","Hello World!") } Public void OnLoad(ConfigNode node) { string myValue2 = node.GetValue("myValue"); } This will save a key/value pair with a key name of myValue with a value of Hello World! and then when the load happens, myValue2 will have a value of Hello World loaded into it. See the ConfigNode section for working with ConfigNodes. Save/Load directly to disk: ConfigNode myNode = ConfigNode.Load(KSPUtil.ApplicationRootPath + "GameData/MyModFolder/MyMod.settings"); //Loads a file from disk into a ConfigNode for use in code. ConfigNode myNode.Save(KSPUtil.ApplicationRootPath + "GameData/MyModFolder/MyMod.settings"); //Saves a confignode to disk. This will save/load to the MyMod.settings file in the MyModFolder. The file structure is a ConfigNode so see that section on working with them. And those are the absolute basics of how to start modding for KSP. If you spot any discrepancies or basics that were missed that should be mentioned please let me know. Apr 12/17: Update VesselModules now run on unloaded vessels. (New in KSP 1.2)
- 34 replies
-
- 30
-
Of all the stupid things, it turns out that all I have to do is set the .localPostion on the gameObject with the text I'm trying to add to Vector.Zero and everything works. Apparently the defaults are what screw things up, so despite everything looking somewhat in the right place on-screen, the Vector3 positions of the transforms behind the scenes were screwy somehow. So the following works, note I'm using the HundredThousands tumbler (the leftmost 0), not the entire tumbler gameObject as my parent. lhGUIgo = new GameObject("LHGUI"); //lhGUIgo.layer = 5; //not sure this is required anymore lhGUIrect = lhGUIgo.AddComponent<RectTransform>(); lhGUIrect.SetParent(lhGUIgo.transform, false); tumblerASLtext = lhGUIgo.AddComponent<TMPro.TextMeshProUGUI>(); lhGUIgo.transform.SetParent(_tumbler.transform.GetChild(0).gameObject.GetComponent<RectTransform>()); tumblerASLtext.transform.localPosition = new Vector3(.5f,-.7f,0); //CRITICAL, set this because defaults block tumbler number rendering tumblerASLtext.text = "ASL"; tumblerASLtext.color = Color.green; tumblerASLtext.alignment = TMPro.TextAlignmentOptions.Center; tumblerASLtext.fontSize = 14; tumblerASLtext.fontStyle = TMPro.FontStyles.Bold; tumblerASLtext.font = Resources.Load("Fonts/Arial SDF", typeof(TMPro.TMP_FontAsset)) as TMPro.TMP_FontAsset; So a lot of frustration for a simple answer. D.
-
@nightingale Thanks for the info, I'll have to mess with the z-position some more. As this text is attached to altimeter, I need it to move when the altimeter does to show the Recover Vessel button. That means I need to put it on the same canvas. (I think, have not actually confirmed the exact number of the available canvases.) Could I just add my own Canvas? I'm still figuring this new UI out and that might be the simplest option. It is a strange issue though, I didn't notice previously, but both the Altimeter and Stage Count tumblers lose their text when this happens. D.
-
This is turning into a real mess on me here. Fixing up the code to make a new gameObject that I make a child of the Altimeter UI is the farthest I've gotten so far. However, as soon as I attach that new gameObject to the Altimeter UI, the black altimeter numbers still disapear. Oddly enough, the altimeter numbers still disapear when I attach my text to the Atmopheric Pressure Gauge instead. My best guess at the moment is that when I make the new gameObject it gets automatically added to the Flight scene, NOT the UI Canvas and when I try to make a parent/child relationship across those two things it is what is causing my issue. Will keep poking at it, this is something that would really make my life easier if I can figure it out. D.
-
Okay, I'm missing something that I'm pretty sure is obvious. This has nothing to do with my previous question about assetbundles. All I'm trying to do is attach another piece of text to the Altimeter to show which mode it is in. Start() { _tumbler = UnityEngine.Object.FindObjectOfType<KSP.UI.Screens.Flight.AltitudeTumbler>(); tumblerText = _tumbler.AddComponent<TMPro.TextMeshProUGUI>(); tumblerText.text = "ASL"; tumblerText.color = Color.green; tumblerText.alignment = TMPro.TextAlignmentOptions.Center; tumblerText.fontSize = 14; tumblerText.fontStyle = TMPro.FontStyles.Bold; tumblerText.font = Resources.Load("Fonts/Arial SDF", typeof(TMPro.TMP_FontAsset)) as TMPro.TMP_FontAsset; } Update() { tumblerText.rectTransform.anchoredPosition = tumblerText.rectTransform.anchoredPosition + new Vector2(0, -0.1f); } This works and spawns the text "ASL" in the middle of the altimeter in the Start() method and slowly descends the screen in the Update() method. The issue is that the black numbers from the Altimeter come along as well and I don't know why. My first though was that you can't have two TMPro instances on the same game object so: Start() { _tumbler = UnityEngine.Object.FindObjectOfType<KSP.UI.Screens.Flight.AltitudeTumbler>(); GameObject temp = new GameObject(); temp.transform.parent = _tumbler.transform; tumblerText = temp.AddComponent<TMPro.TextMeshProUGUI>(); tumblerText = _tumbler.AddComponent<TMPro.TextMeshProUGUI>(); tumblerText.text = "ASL"; tumblerText.color = Color.green; tumblerText.alignment = TMPro.TextAlignmentOptions.Center; tumblerText.fontSize = 14; tumblerText.fontStyle = TMPro.FontStyles.Bold; tumblerText.font = Resources.Load("Fonts/Arial SDF", typeof(TMPro.TMP_FontAsset)) as TMPro.TMP_FontAsset; } Update() { tumblerText.rectTransform.anchoredPosition = tumblerText.rectTransform.anchoredPosition + new Vector2(0, -0.1f); } This worked to spawn the text "ASL" in the middle of the screen, but the altimiter numbers were just flat out gone. I assume they got shifted off screen somehow, but I don't know where. What am I missing? Just adding a piece of text should be easy but I don't know where I'm going wrong.. D. There is also a .bounds and .textbounds property that looks interesting, but they don't behave as expected. There documentation on this TMPro stuff somehwere?
-
For now, I'm going to stick with a single assembly and making the calls to the asset bundle in code directly. There are only 3 object in this assetbundle so it's simpler to do it that way and it also helps me with learning how to do this at all. Once I move on to replacing the UI in my existing mods, a hybrid linked reference as Maneuver Node Evolved uses will probable be the way I go. Almost everything in my GUI's links to KSP objects somehow so what I could do in a dedicated GUI assembly is actually very limited as that assembly can't refer to KSP's Assembly-Csharp and so would be almost useless to me. However, that brings up the Text Mesh Pro issue, I did see the thread about it in the (now locked) 1.2 pre-release sub-forum, but is there anything more recent (forum thread or example mod code) on how to get that working? D.
-
I have been using DMagic's tutorial and it's the only reason I've gotten as far as I have. However, that tutorial uses the 2 Assemblies method where there's a dedicated GUI assembly where you hook up the methods to the objects in the Unity editor itself, so the tutorial doesn't actually cover hooking up to objects directly via code as you do in GC Monitor. Also, that explains what I was missing, I was changing settings on the Text component itself trying to get this to work, not the GameObject the Text is attached to. Should be straightforward now, thanks for the help Sarbian. D.
-
Alright, I'm taking my first baby steps trying to figure out the new GUI and have what should be a straightforward question. In hooking up to an asset bundle, what does this string do? infoKSP = go.GetComponentInChild<Text>("KSP"); (Example pulled from Sarbian's GC monitor.) I am referring to the "KSP" string here. I think I have the rest of that line of code figured out, in that I can find a valid Text object if I just use .GetComponentInChild<Text>(), but my test GUI only has a single Text object on it and I assume this is how you tell different objects apart. Note I have never used Unity before, I had to download it to make this test GUI assetbundle so it is probably something really simple, I just don't know Unity or where to find it. D.
-
Version 1.9 Download here. Redo ray-cast logic from scratch to clean it up as it had been ages since I'd last done this and was getting "exception spagehtti" all over the place. (Thanks to Stephen Mading for prompting the discussion that got me to do this.) New functionality: Other vessels are now correctly detected as "ground" and the altimeter will display the distance to them if you are coming straight down on them as those are the first things you will hit. @Bit Fiddler This does not do anything about your request for switching modes, I'm actually somewhat at a loss what to do there as this mod simply doesn't have a GUI to interact with. D.
-
Enable/Disable autopilot
Diazo replied to petersohn's topic in KSP1 C# Plugin Development Help and Support
Not sure what exactly those .Enable and Disable methods do. To disable SAS is the following I do the following: FlightGlobals.ActiveVessel.ActionGroups.SetGroup(KSPActionGroup.SAS, false); To set Stability Assist is: pm.vessel.ActionGroups.SetGroup(KSPActionGroup.SAS, true); pm.vessel.Autopilot.SetMode(VesselAutopilot.AutopilotMode.StabilityAssist); if (pm.vessel == FlightGlobals.ActiveVessel) { MonoBehaviorMethods.setSASUI(0); //You have to set the UI icon manually for some reason. } Note that you can only set available modes that have icons visible next to the navball so make sure a high enough level pilot/probe core is along. D. -
Action group - DIsplay tweakable/fuel window
Diazo replied to DD_bwest's topic in KSP1 Suggestions & Development Discussion
@DD_bwest My ModActions mod currently does not support working with fuel flow like that. A bit odd perhaps because that mod came about because of this exact issue, I wanted a "one-button" control of fuel flow in my own craft. Then I dug into it and realized just how complex doing that was and moved on to other (simpler) actions in order to get the mod itself working. It is next up on my mod update cycle, I will poke at the fuel stuff again, now that the framework of the mod itself is working it should be much simpler to implement. As for the popping open the part's window? That is actually a good idea and I don't think it would be too complicated either. @Gianni1122 Thanks for the mention. D. -
Maybe look at the layer the objects are on? (GameObject.layer) Going to poke at this myself, if that question could be answered it would help my Landing Aid mod. D. edit: It appears that everything "ground" is on layer 15, at least the PQS objects and the Launchpad models. Currently testing but it looks like that if the GameObject hit has a Component of Type "PQ", then it's a PQS object, otherwise it's a model of some sort. edit the 2nd: Looking at your post again, the parent/child relationship appears to be through the transform objects. So "MyGameObject.transform.parent.GameObject" is a reference to the parent GameObject. edit the 3rd: So, it's looking pretty solid. LayerMask testMask = 1 << 15; //cast against layer 15 only. if (Physics.Raycast(pRayDown, out pHit, (float)(FlightGlobals.ActiveVessel.mainBody.Radius + FlightGlobals.ActiveVessel.altitude), testMask)) //cast ray { if(pHit.collider.gameObject.GetComponent<PQ>() != null) { //Hit PQS } else { /Hit something else } } } For sure you need to ignore layer 10 (scaled space stuff) and the layer that parts themselves are on. (Forgot to note it, not sure what layer number it is.) The wildcard is the mods that add terrain, I only tested stock against the KSC buildings and the ground (including under the oceans) near it. edit the last: The annoying part is that water seems to have no collider to hit, a raycast with a LayerMask of ~0 (which should hit anything) still hits the PQS terrain on the seabed. Also, parts attached to the current vessel appear to be on layer 0 and I'm not able to determine if seperated parts (another vessel) are also on layer 0 or not. edit the next day: Looks like all actual parts are on layer zero, you have to do a if(!FlightGlobas.ActiveVessel.Parts.Contains(pHit.collider.gameObject.GetComponentUpwards<Part>()) check to see if the part you hit is on the focus vessel or not.
-
Version 2.2 Download here. -Fix Smartpart Radio (OtherVessel class) -Fix Default Action Groups mod compatibilty. -Revise Kerbal boarding methods so hopefully they are not considered sub-vessels any more. Feedback request: KSP 1.2.2 appears to change something in how the stock Action Group Editor panels work in the VAB/SPH. On my machine KSP locks up for 3 to 4 seconds to process the hiding of these panels the first time you do so in a game session. Do other people see this delay as well when they switch to action group editing mode? Is it also only the first time in a game session? @santiagokof This pushes the changes in the .dll file I linked a few days ago to official, no further changes for that issue was needed. @Johnny2000 AGX should now work with the Default Actions Groups mod. @Deimos Rast I've tried another method for the Kerbal reboarding issue, but I've never been able to replicate so I'll have to ask you to see how it goes. Happy KSPing all. D.
- 1,353 replies
-
- 4
-
- edit actions
- actions
-
(and 1 more)
Tagged with: