public void Update() { string errLine = "1"; try { //Debug.Log("vsl nulla"); if (!DataModulePresent(FlightGlobals.ActiveVessel) && curVsl != null) { errLine = "1a"; Debug.Log("vsl null"); curVsl.theLine.SetColors(Color.blue, Color.blue); curVsl = null; curBtnState = 0; } //Debug.Log("vsl nullb"); errLine = "1b"; if (curVsl == null && DataModulePresent(FlightGlobals.ActiveVessel) || curVsl != null && curVsl.vessel.rootPart != FlightGlobals.ActiveVessel.rootPart || curVsl != null && !curVsl.isMasterModule || curVsl != null && !FlightGlobals.ActiveVessel.parts.Contains(curVsl.part)) { //Debug.Log("vsl switch"); try { if (curVsl != null) { //Debug.Log("blue reset"); curVsl.theLine.SetColors(Color.blue, Color.blue); } } catch { //Debug.Log("vsl nullb catch"); } errLine = "3"; //bool mdlFound = false; //foreach (Part p in FlightGlobals.ActiveVessel.parts) //{ // errLine = "4"; List<RCSLandingAidModule> dataModules = new List<RCSLandingAidModule>(); foreach (Part p in FlightGlobals.ActiveVessel.parts) { errLine = "4"; //foreach (TWR1Data td in p.Modules.OfType<TWR1Data>()) //{ dataModules.AddRange(p.Modules.OfType<RCSLandingAidModule>()); //} } errLine = "4a"; if (dataModules.Count == 0) { errLine = "4b"; curVsl = null; } else if (dataModules.Where(pm => pm.isMasterModule == true).Count() > 0) { errLine = "4c"; curVsl = dataModules.Where(pm => pm.isMasterModule == true).First(); } else { errLine = "4d"; curVsl = dataModules.First(); } errLine = "4e"; foreach (RCSLandingAidModule tdata in dataModules) { if (tdata == curVsl) //make sure our master is set { curVsl.isMasterModule = true; } else //all other modules are ignored { tdata.isMasterModule = false; tdata.controlState = 0; } } //foreach (RCSLandingAidModule la in p.Modules.OfType<RCSLandingAidModule>()) //{ // if (!mdlFound) // { // curVsl = la; // mdlFound = true; // la.isMasterModule = true; // curVsl.theLine.SetColors(Color.red, Color.red); // //Debug.Log("td fnd"); // } // else // { // la.isMasterModule = false; // //Debug.Log("td not found"); // } //} //if (!mdlFound) //{ // //Debug.Log("vsl nulld not found"); // curVsl = null; //} //if (p.Modules.Contains("TWR1Data")) //{ // errLine = "5"; //} //errLine = "6"; //goto partFound; } //Debug.Log("vsl nulld"); errLine = "7"; //curVsl = null; errLine = "8"; //curBtnState = 0; // } } catch { print("LandAid hit Update catch" + errLine); curBtnState = 0; if (curVsl != null) { curVsl.theLine.SetColors(Color.blue, Color.blue); } curVsl = null; } errLine = "9"; try { //print("Height " + engageHeight); if (selectingTarget) { RaycastHit pHit; FlightCamera FlightCam = FlightCamera.fetch; LayerMask pRayMask = 33792; //layermask does not ignore layer 0, why? Ray pRay = FlightCam.mainCamera.ScreenPointToRay(Input.mousePosition); //Ray pRayDown = new Ray(FlightCamera. transform.position , FlightGlobals.currentMainBody.position); Vector3 hitLoc = new Vector3(); if (Physics.Raycast(pRay, out pHit, 2000f, pRayMask)) //cast ray { hitLoc = pHit.point; // print(hitLoc); curVsl.theLine.SetWidth(0, 1); curVsl.theLine.SetPosition(0, hitLoc); curVsl.theLine.SetPosition(1, hitLoc + ((hitLoc - FlightGlobals.ActiveVessel.mainBody.position).normalized) * 7); if (!overWindow) { if (Input.GetKeyDown(KeyCode.Mouse0)) { if (checkBlizzyToolbar) { RCSla1Btn.Drawable = null; } else { showLAMenu = false; } selectingTarget = false; curVsl.targetLocation = hitLoc; curVsl.targetSelected = true; } } } } errLine = "10"; //Debug.Log("LA " +curBtnState); if (lastBtnState != curBtnState) { switch (curBtnState) { case 0: if (checkBlizzyToolbar) { //Debug.Log("LA1"); RCSla1Btn.TexturePath = "Diazo/RCSLandAid/iconWhiteB"; } else { //Debug.Log("LA2"); LAButton.SetTexture(btnGray); } break; case 1: if (checkBlizzyToolbar) { //Debug.Log("LA3"); RCSla1Btn.TexturePath = "Diazo/RCSLandAid/iconBlue"; } else { //Debug.Log("LA4"); LAButton.SetTexture(btnBlue); } break; case 2: if (checkBlizzyToolbar) { // Debug.Log("LA5"); RCSla1Btn.TexturePath = "Diazo/RCSLandAid/iconBlueEnabled"; } else { // Debug.Log("LA6"); LAButton.SetTexture(btnBlueEnable); } break; case 3: if (checkBlizzyToolbar) { // Debug.Log("LA7"); RCSla1Btn.TexturePath = "Diazo/RCSLandAid/iconRed"; } else { // Debug.Log("LA8"); LAButton.SetTexture(btnRed); } break; case 4: if (checkBlizzyToolbar) { // Debug.Log("LA9"); RCSla1Btn.TexturePath = "Diazo/RCSLandAid/iconRedEnabled"; } else { // Debug.Log("LA10"); LAButton.SetTexture(btnRedEnable); } break; } lastBtnState = curBtnState; } } catch (Exception e) { Debug.Log("Landing Aid Error " + e); } }
public void Update() { //string errLine = "1"; try { //Debug.Log("vsl nulla"); if (!DataModulePresent(FlightGlobals.ActiveVessel) && curVsl != null) { //errLine = "1a"; //Debug.Log("vsl null"); curVsl.theLine.SetColors(Color.blue, Color.blue); curVsl = null; curBtnState = 0; } //Debug.Log("vsl nullb"); //errLine = "1b"; if (curVsl == null && DataModulePresent(FlightGlobals.ActiveVessel) || curVsl != null && curVsl.vessel.rootPart != FlightGlobals.ActiveVessel.rootPart || curVsl != null && !curVsl.isMasterModule || curVsl != null && !FlightGlobals.ActiveVessel.parts.Contains(curVsl.part)) { //Debug.Log("vsl switch"); try { if (curVsl != null) { //Debug.Log("blue reset"); curVsl.theLine.SetColors(Color.blue, Color.blue); } } catch { //Debug.Log("vsl nullb catch"); } //errLine = "3"; //bool mdlFound = false; //foreach (Part p in FlightGlobals.ActiveVessel.parts) //{ // errLine = "4"; List <RCSLandingAidModule> dataModules = new List <RCSLandingAidModule>(); foreach (Part p in FlightGlobals.ActiveVessel.parts) { //errLine = "4"; //foreach (TWR1Data td in p.Modules.OfType<TWR1Data>()) //{ dataModules.AddRange(p.Modules.OfType <RCSLandingAidModule>()); //} } //errLine = "4a"; if (dataModules.Count == 0) { //errLine = "4b"; curVsl = null; } else if (dataModules.Where(pm => pm.isMasterModule == true).Count() > 0) { //errLine = "4c"; curVsl = dataModules.Where(pm => pm.isMasterModule == true).First(); } else { //errLine = "4d"; curVsl = dataModules.First(); } //errLine = "4e"; foreach (RCSLandingAidModule tdata in dataModules) { if (tdata == curVsl) //make sure our master is set { curVsl.isMasterModule = true; } else //all other modules are ignored { tdata.isMasterModule = false; tdata.controlState = 0; } } //foreach (RCSLandingAidModule la in p.Modules.OfType<RCSLandingAidModule>()) //{ // if (!mdlFound) // { // curVsl = la; // mdlFound = true; // la.isMasterModule = true; // curVsl.theLine.SetColors(Color.red, Color.red); // //Debug.Log("td fnd"); // } // else // { // la.isMasterModule = false; // //Debug.Log("td not found"); // } //} //if (!mdlFound) //{ // //Debug.Log("vsl nulld not found"); // curVsl = null; //} //if (p.Modules.Contains("TWR1Data")) //{ // //errLine = "5"; //} //errLine = "6"; //goto partFound; } //Debug.Log("vsl nulld"); //errLine = "7"; //curVsl = null; //errLine = "8"; //curBtnState = 0; // } } catch { //print("LandAid hit Update catch" + errLine); curBtnState = 0; if (curVsl != null) { curVsl.theLine.SetColors(Color.blue, Color.blue); } curVsl = null; } //errLine = "9"; // Debug.Log("LA " + Krakensbane.GetFrameVelocity().ToString() + "|" + Krakensbane.GetFrameVelocity().magnitude); try { //print("Height " + engageHeight); if (selectingTarget) { RaycastHit pHit; FlightCamera FlightCam = FlightCamera.fetch; //LayerMask pRayMask = 33792; //layermask does not ignore layer 0, why? LayerMask pRayMask = 32768; //hit only layer 15 Ray pRay = FlightCam.mainCamera.ScreenPointToRay(Input.mousePosition); //Ray pRayDown = new Ray(FlightCamera. transform.position , FlightGlobals.currentMainBody.position); Vector3 hitLoc = new Vector3(); if (Physics.Raycast(pRay, out pHit, 2000f, pRayMask)) //cast ray { hitLoc = pHit.point; // print(hitLoc); curVsl.theLine.SetWidth(0, 1); curVsl.theLine.SetPosition(0, hitLoc); curVsl.theLine.SetPosition(1, hitLoc + ((hitLoc - FlightGlobals.ActiveVessel.mainBody.position).normalized) * 7); if (!overWindow) { if (Input.GetKeyDown(KeyCode.Mouse0)) { if (checkBlizzyToolbar) { RCSla1Btn.Drawable = null; } else { showLAMenu = false; } selectingTarget = false; curVsl.targetLocation = hitLoc; curVsl.targetSelected = true; } } } } //errLine = "10"; //Debug.Log("LA " +curBtnState); if (lastBtnState != curBtnState) { switch (curBtnState) { case 0: if (checkBlizzyToolbar) { //Debug.Log("LA1"); RCSla1Btn.TexturePath = "Diazo/RCSLandAid/iconWhiteB"; } else { //Debug.Log("LA2"); LAButton.SetTexture(btnGray); } break; case 1: if (checkBlizzyToolbar) { //Debug.Log("LA3"); RCSla1Btn.TexturePath = "Diazo/RCSLandAid/iconBlue"; } else { //Debug.Log("LA4"); LAButton.SetTexture(btnBlue); } break; case 2: if (checkBlizzyToolbar) { // Debug.Log("LA5"); RCSla1Btn.TexturePath = "Diazo/RCSLandAid/iconBlueEnabled"; } else { // Debug.Log("LA6"); LAButton.SetTexture(btnBlueEnable); } break; case 3: if (checkBlizzyToolbar) { // Debug.Log("LA7"); RCSla1Btn.TexturePath = "Diazo/RCSLandAid/iconRed"; } else { // Debug.Log("LA8"); LAButton.SetTexture(btnRed); } break; case 4: if (checkBlizzyToolbar) { // Debug.Log("LA9"); RCSla1Btn.TexturePath = "Diazo/RCSLandAid/iconRedEnabled"; } else { // Debug.Log("LA10"); LAButton.SetTexture(btnRedEnable); } break; } lastBtnState = curBtnState; } } catch (Exception e) { Debug.Log("Landing Aid Error " + e); } }