Jump to content

neitsa

Members
  • Posts

    59
  • Joined

Everything posted by neitsa

  1. Thank you @udk_lethal_d0se for your help. Tried your snippet (inverting position and parent) but still no luck . I'll check the code of RoverScience on GitHub, maybe I'll be able to transpose it to my code or at least get an idea... I'm still not giving up
  2. Hi guys ! Thanks for your answers. Tried you suggestions but none of them seem to make the sphere appear around the selected vessel. removed layer (commented the line) localScale set to: Vector3.one * 1500f; (instead of 5000.0) Using a shader as material (note that I used the materiel as the renderer material): var renderer = m_SphereObj.GetComponent<Renderer>(); Material material = new Material(Shader.Find("KSP/Diffuse")); renderer.material = material; renderer.material.color = Color.red; I tried a lot of things but I can't get even one to work though... I'm really short on ideas. Maybe I should try with a mesh instead, but that seems quite crazy to not being able to display a simple primitive in game. If you guys have other ideas I'll be glad to test them Thanks a lot !
  3. Hi! I'm trying to display a simple sphere primitive (from GameObject.CreatePrimitive(PrimitiveType.Sphere) ) centered around a vessel in the tracking station, but to no avail... No fancy stuff, for a start I'd like the sphere to be a simple solid color. Problem is I even don't know if the sphere is displayed somewhere but can't be seen or if it's not displayed at all. Below is a minimal repro code for this problem: using System; using System.Collections.Generic; using UnityEngine; namespace TestPrimitive { [KSPAddon(KSPAddon.Startup.TrackingStation, false)] public class TestPrimitive : MonoBehaviour { GameObject m_SphereObj; List<Vessel> m_vesselList; bool m_inTrackingStation; bool m_isVesselFecthed; Vessel m_currentVessel; void Start() { // we want to do something only in the tracking station if (HighLogic.LoadedScene != GameScenes.TRACKSTATION) return; // Create a sphere object m_SphereObj = GameObject.CreatePrimitive(PrimitiveType.Sphere); m_SphereObj.layer = 10; // disable collider for the sphere var collider = m_SphereObj.GetComponent<Collider>(); collider.enabled = false; //Destroy(collider); // should the collider be destroyed? // get object renderer and apply attributes var renderer = m_SphereObj.GetComponent<Renderer>(); renderer.material.color = Color.red; renderer.receiveShadows = false; renderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off; // enable the renderer later renderer.enabled = false; } void Update() { // we want to do something only in the tracking station if (HighLogic.LoadedScene != GameScenes.TRACKSTATION) { m_inTrackingStation = false; return; } // check mapview and its camera if (!MapView.MapIsEnabled || MapView.MapCamera == null) { m_inTrackingStation = false; return; } m_inTrackingStation = true; if (!m_isVesselFecthed) { FetchVessels(); m_isVesselFecthed = true; } if (m_currentVessel != null) { // sphere parent tranform is the vessel transform m_SphereObj.transform.parent = m_currentVessel.transform; // not sure about this one... m_SphereObj.transform.position = ScaledSpace.LocalToScaledSpace(m_currentVessel.GetWorldPos3D()); // is it big enough? m_SphereObj.transform.localScale = Vector3.one * 5000f; m_SphereObj.transform.localPosition = Vector3.zero; m_SphereObj.transform.localRotation = Quaternion.identity; // enable renderer var renderer = m_SphereObj.GetComponent<Renderer>(); renderer.enabled = true; //m_SphereObj.SetActive(true); } else { var renderer = m_SphereObj.GetComponent<Renderer>(); renderer.enabled = false; //m_SphereObj.SetActive(false); } } void onVesselIconClicked(Vessel vessel) { // check vessel instance if (vessel == null) { return; } // must be in tracking station if (!m_inTrackingStation) { return; } // get currently selected vessel m_currentVessel = vessel; } void FetchVessels() { if (m_vesselList == null) { m_vesselList = new List<Vessel>(); } for (int i = 0; i < FlightGlobals.Vessels.Count; ++i) { Vessel vessel = FlightGlobals.Vessels[i]; // check that the vessel is known if (vessel.DiscoveryInfo.HaveKnowledgeAbout(DiscoveryLevels.StateVectors)) { m_vesselList.Add(vessel); } // callback called when vessel icon is clicked vessel.orbitRenderer.onVesselIconClicked.Add(new EventData<Vessel>.OnEvent(onVesselIconClicked)); } } } } Setting debug logs around all code parts I can see that all the code is executed though, which makes me wonder what is wrong. Thanks a lot for reading!
  4. Ah exactly, that explains the differences in the output Neat idea! As of now I'm just trying to check if the vessel being built matches some part requirements (sort of a part check list before launch). Thanks again for your feedback!
  5. I couldn't find them either, even by using some google dorks, which means they have probably entirely disappeared from the forum. I resorted using the wayback machine [ https://web.archive.org ] (please note that all links below are external to this forum and go to web.archive.org) : (Also note that you might have to click the "latest" button once on web archive) An Adventure in Plugin Coding An Adventure in Plugin Coding - 2. Building Blocks An Adventure in Plugin Coding - 3. A Fast Dev Environment... I hope An Adventure in Plugin Coding - 4. A Post with Class An Adventure in Plugin Coding - 5. A Window of Opportunity An Adventure in Plugin Coding - 6. Lay some skin on me An Adventure in Plugin Coding - 7. Thanks for the Persistence An Adventure in Plugin Coding - 8. Revisiting the Scene of the Crime
  6. Problem solved, finally I'm not sure this is a good solution, but it works as intended. What's clicked in my head was this log line (produced by KSP itself): Before this line, all calls to get user available parts (in the Update() function) returned `true` for all parts, but I could see that the parts were actually filtered after the above log message was displayed (which indicates that the VAB / SPH is fully loaded and the GUI is ready). So I decided to wait for the GUI to be loaded, something along those lines: internal void Start() { Debug.Log("[Test] Start"); if (PartLoader.LoadedPartsList == null) { UnityEngine.Debug.LogError("[Test]: No LoadedPartsList; Game not entirely loaded?"); canRun = false; return; } else { canRun = true; } // callback fired when a level is loaded and the GUI is ready GameEvents.onLevelWasLoadedGUIReady.Add(new EventData<GameScenes>.OnEvent(OnSceneLoadedGUIReady)); // snip } The callback looks like this : private void OnSceneLoadedGUIReady(GameScenes scene) { Debug.Log("[Test] OnSceneLoadedGUIReady enter."); // loading scene: not interesting if (scene == GameScenes.LOADING) return; // check that the editor is loaded and ready if (scene == GameScenes.EDITOR) { Debug.Log("Editor ok"); EditorLoaded = true; } Debug.Log("[Test] OnSceneLoadedGUIReady leave."); } and then in the Update() function: internal void Update() { Debug.Log("[Test] Update() : entering"); if (EditorLoaded & !ListPartObtained) { // get all parts available to the player depending on his/her tech tree var purchased = PartLoader.LoadedPartsList.Where(p => ResearchAndDevelopment.PartModelPurchased(p)); Debug.Log(string.Format("Available parts: [{0}]", callNum)); callNum++; foreach (var p in purchased) { Debug.Log($"Name: {p.name}, title: {p.title}, category: {p.category}"); } // we got the list ListPartObtained = true; } updateDone = true; Debug.Log("[Test] Update() : leaving"); } It might also be a good option to refresh the list each time the player enters the VAB / SPH. Probably not a perfect solution, but it does the job Thanks a lot for your help!
  7. Hi guys! Oh, btw I'm testing against KSP 1.1.3.1289 Sorry for the late reply and thank you @Aelfhe1m and @Crzyrndm very much for your answers! @Aelfhe1m I tried your code both in Start() and Update() functions. At first I tried once in the Update() function, so I didn't have to execute the code each time the function is called. I simply put a boolean and once the function was executed, changed the boolean so I knew I had the whole list part. I removed that boolean and am executing the code on each call to Update(). I'm still getting the whole list of parts until the user starts to search for a part: at that point the list seems to be filtered and I'm getting the right list of parts! (that is, the part that are only available to the player depending on his tech tree). Executing the code on Start() or Update() without player interaction still gives me the whole part list (without any filtering). Do you have the same behavior? Do you know if it's possible to get the list of parts (depending on the player tech tree) without the player using the search box? Thanks a lot!
  8. Hi @Aelfhe1m , thank you for your answer ! Unfortunately, this doesn't work... They both (PartModelPurchased() and PartTechAvailable() function return value) are set to true for all parts, even if the tech is not available. I tested it in both Science and Carrer mode, and it works the same in both modes (all part set to True for purchased and Techavailable). Here is a screenshot of a science mode play: http://imgur.com/yYmBp3Q For example, the Cupola isn't available in the "pods" category (on the above screenshot), but the code still returns True. Below is a snippet of the output from the plug-in (with techAvailable and purchased, which are the return value of respectively PartTechAvailable() and PartModelPurchased()) : [LOG 18:31:43.105] Name: cupola ; Title: PPD-12 Cupola Module; Category: Pods; techAvailable: True; purchased: True [LOG 18:31:43.106] Resource name: Electric Charge [LOG 18:31:43.107] Resource name: Mono Propellant [LOG 18:31:43.108] Name: seatExternalCmd ; Title: EAS-1 External Command Seat; Category: Pods; techAvailable: True; purchased: True [LOG 18:31:43.110] Name: crewCabin ; Title: PPD-10 Hitchhiker Storage Container; Category: Utility; techAvailable: True; purchased: True [LOG 18:31:43.111] Name: advSasModule ; Title: Advanced Inline Stabilizer; Category: Control; techAvailable: True; purchased: True [LOG 18:31:43.112] Name: sasModule ; Title: Small Inline Reaction Wheel; Category: Control; techAvailable: True; purchased: True [LOG 18:31:43.113] Name: Mark1-2Pod ; Title: Mk1-2 Command Pod; Category: Pods; techAvailable: True; purchased: True [LOG 18:31:43.115] Resource name: Electric Charge [LOG 18:31:43.116] Resource name: Mono Propellant Still wondering what is wrong or what I should do... Anyway, thanks a lot for taking time to help me!
  9. Hello ! I'm trying to wrap my head around how it is possible to get the list of all parts available to the user in the VAB / SPH, especially in career mode (not on a ship/rocket/plane, but available to build one). When you start a new career, you are limited to the number of parts available. You can unlock more parts by spending Science points in the R&D center, which then unlock new parts in the VAB / SPH depending on the chosen branches in the Tech tree. While in the VAB / SPH I'm able to access all the parts loaded by the game: internal void Start() { Debug.Log("[TestPlug] Start"); if (PartLoader.LoadedPartsList == null) { UnityEngine.Debug.LogError("[TestPlug]: No LoadedPartsList; Game not entirely loaded?"); canRun = false; return; } else { canRun = true; } foreach (AvailablePart part in PartLoader.LoadedPartsList) { var logpart = string.Format("Name: {0} ; Title: {1}; Category: {2}", part.name, part.title, part.category); Debug.Log(logpart); foreach(AvailablePart.ResourceInfo resInfo in part.resourceInfos) { Debug.Log(string.Format(" Resource name: {0}", resInfo.resourceName)); } } // [snip] Output example : [LOG 17:40:08.557] Name: noseCone ; Title: Aerodynamic Nose Cone; Category: Aero [LOG 17:40:08.558] Name: airbrake1 ; Title: A.I.R.B.R.A.K.E.S; Category: Aero [LOG 17:40:08.559] Name: airScoop ; Title: XM-G50 Radial Air Intake; Category: Aero [LOG 17:40:08.561] Resource name: Intake Air [LOG 17:40:08.562] Name: airlinerCtrlSrf ; Title: FAT-455 Aeroplane Control Surface; Category: Aero [LOG 17:40:08.563] Name: airlinerMainWing ; Title: FAT-455 Aeroplane Main Wing; Category: Aero [LOG 17:40:08.564] Resource name: Liquid Fuel [LOG 17:40:08.565] Name: airlinerTailFin ; Title: FAT-455 Aeroplane Tail Fin; Category: Aero [LOG 17:40:08.567] Name: AdvancedCanard ; Title: Advanced Canard; Category: Aero [LOG 17:40:08.568] Name: CanardController ; Title: Standard Canard; Category: Aero [snip] What I'd like is to access the list of all the parts available or shown in the VAB / SPH, depending on the tech tree of the player. I have tried many things to actually get only the parts available / shown to the player in the VAB, but I haven't succeeded... (like using the ResearchAndDevelopment.PartModelPurchased() and other functions, but all my attempts failed). I guess I should try something around "EditorPartListFilter<AvailablePart>" but I don't know which filter I should use... What do I need to do exactly? Thank you !
×
×
  • Create New...