public void Update() { if (!FlightGlobals.ready || PauseMenu.isOpen) { return; } try { angle += 0.1; #region Update selected kerbals foreach (EvaContainer eva in EvaController.instance.collection) { if (!eva.Loaded) { continue; } if (eva.Selected) { UpdateSelectionLine(eva); } } #endregion if (!FlightGlobals.ActiveVessel.Landed && FlightGlobals.ActiveVessel.GetHeightFromSurface() > 25) { DisableCursor(); return; } if (HighLogic.LoadedScene != GameScenes.FLIGHT || MapView.MapIsEnabled) { return; } //add here something to change the selection ui in space. #region Handle Cursor... if (showCursor) { if (!_animatedCursor) { //ray every time ? if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out _cursorHit)) { _cursorPosition = _cursorHit.point; _cursorRotation = FlightGlobals.ActiveVessel.transform.rotation; } } SetCursorProperties(); } #endregion #region Select Multiple Kerbals if (Input.GetMouseButtonDown(EvaSettings.selectMouseButton) || Input.GetKeyDown(EvaSettings.selectKeyButton)) { _startClick = Input.mousePosition; } else if (Input.GetMouseButtonUp(EvaSettings.selectMouseButton) || Input.GetKeyUp(EvaSettings.selectKeyButton)) { if (_selection.width < 0) { _selection.x += _selection.width; _selection.width = -_selection.width; } if (_selection.height < 0) { _selection.y += _selection.height; _selection.height = -_selection.height; } _startClick = -Vector3.one; } if (Input.GetMouseButton(EvaSettings.selectMouseButton) || Input.GetKey(EvaSettings.selectKeyButton)) { _selection = new Rect(_startClick.x, InvertY(_startClick.y), Input.mousePosition.x - _startClick.x, InvertY(Input.mousePosition.y) - InvertY(_startClick.y)); } if (Input.GetMouseButton(EvaSettings.selectMouseButton) || Input.GetKey(EvaSettings.selectKeyButton)) { if (_selection.width != 0 && _selection.height != 0) { Rect _temp = new Rect(_selection.x, _selection.y, _selection.width, _selection.height); if (_temp.width < 0) { _temp.x += _temp.width; _temp.width = -_temp.width; } if (_selection.height < 0) { _temp.y += _temp.height; _temp.height = -_temp.height; } //get the kerbals in the selection. foreach (EvaContainer container in EvaController.instance.collection) { if (!container.Loaded) { //Can't select what isn't there. continue; } Vector3 camPos = Camera.main.WorldToScreenPoint(container.EVA.transform.position); camPos.y = InvertY(camPos.y); if (_temp.Contains(camPos)) { SelectEva(container); } else { if (container.Selected) { DeselectEva(container); } } } } #region targetVesselBySelection if (EvaSettings.targetVesselBySelection) { if (_selection.width != 0 && _selection.height != 0) { Vessel target = null; float longest = 0; //Scan a targetable vessel is avaible. foreach (Vessel vessel in FlightGlobals.Vessels) { if (!vessel.loaded) { return; } var camera = GetComponent <Camera>(); //Calculate distance. var distance = Mathf.Abs( Vector3.Distance(vessel.GetWorldPos3D(), camera.transform.position)); if (target == null) { longest = distance; target = vessel; } else { if (distance > longest) { longest = distance; target = vessel; } } } if (target != null) { Vector3 camPos = Camera.main.WorldToScreenPoint(target.transform.position); camPos.y = InvertY(camPos.y); if (_selection.Contains(camPos)) { //target the vessel. FlightGlobals.fetch.SetVesselTarget(target); } } } } #endregion } #endregion #region Select Single Kerbal bool leftButton = Input.GetMouseButtonDown(EvaSettings.selectMouseButton) || Input.GetKeyDown(EvaSettings.selectKeyButton); bool rightButton = Input.GetMouseButtonDown(EvaSettings.dispatchMouseButton) || Input.GetKeyDown(EvaSettings.dispatchKeyButton); if (leftButton == false && rightButton == false) { return; } RaycastHit hitInfo = new RaycastHit(); bool hit = Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hitInfo); if (!hit) { DisableCursor(); return; //nothing to check. } var evaCollision = hitInfo.transform.gameObject.GetComponent <KerbalEVA>(); if (leftButton) { DeselectAllKerbals(); if (evaCollision != null) { EvaContainer eva = EvaController.instance.GetEva(evaCollision.vessel.id); if (!eva.Loaded) { throw new Exception("[EFX] Impossibre!"); } SelectEva(eva); } else { DisableCursor(); } } #endregion #region Handle Mouse Controls if (rightButton) //Middle button. { var offset = (FlightGlobals.ActiveVessel).GetWorldPos3D(); var position = (Vector3d)hitInfo.point; foreach (var item in EvaController.instance.collection.ToArray()) { if (!item.Loaded) { return; } if (item.Selected) { //Remove current mode. if (item.mode == Mode.Patrol) { item.EndPatrol(); } if (EvaSettings.displayDebugLines) { setLine(position, offset); } EvaDebug.DebugLog(string.Format("Target: {0}", position)); item.Order(position, offset); item.Selected = false; item.mode = Mode.Order; _animatedCursor = true; //destroy circle line DestroyLine(item.flightID); } } } #endregion #region Cursor Visible... //Show the cursor if more than one kerbal is selected. if (selectedKerbals > 0) { ShowCursor(); } else { DisableCursor(); } #endregion } catch (Exception exp) { EvaDebug.DebugWarning("[EFX] EvaOrderController: " + exp.Message); } }
public void Load(Vessel vessel) { if (!vessel.isEVA) { EvaDebug.DebugWarning("Tried loading a non eva."); return; } KerbalEVA currentEVA = vessel.GetComponent<KerbalEVA>(); if (!Contains(vessel.id)) { EvaContainer container = new EvaContainer(vessel.id); //load the vessel here. container.Load(currentEVA); EvaSettings.LoadEva(container); collection.Add(container); } else { //Reload EvaContainer container = GetEva(vessel.id); container.Load(currentEVA); EvaSettings.LoadEva(container); } }
/// <summary> /// Select an EVA, and add the selection to the line collection. /// </summary> /// <param name="_eva"></param> private void SelectEva(EvaContainer container) { if (!container.EVA.vessel.LandedOrSplashed) { return; } ++selectedKerbals; container.Selected = true; //create circle line CreateLine(container); }
/// <summary> /// Deselect an EVA, and remove the selection from the line collection. /// </summary> /// <param name="_eva"></param> private void DeselectEva(EvaContainer _eva) { --selectedKerbals; _eva.Selected = false; //create circle line DestroyLine(_eva.flightID); }
/// <summary> /// Update the selection model position. /// </summary> /// <param name="eva"></param> public void UpdateSelectionLine(EvaContainer container) { if (!selectionLines.ContainsKey(container.flightID)) { CreateLine(container); } var lineRenderer = selectionLines[container.flightID]; SetSelectionLineProperties(container.EVA, lineRenderer); }
/// <summary> /// Create a selection model for a specific kerbal. /// </summary> /// <param name="eva"></param> private void CreateLine(EvaContainer container) { if (selectionLines.ContainsKey(container.flightID)) { return; } LineRenderer lineRenderer = new GameObject().AddComponent<LineRenderer>(); lineRenderer.useWorldSpace = false; lineRenderer.material = new Material(Shader.Find("Particles/Additive")); lineRenderer.SetWidth(0.05f, 0.05f); lineRenderer.SetColors(Color.green, Color.red); Renderer _renderer = null; lineRenderer.GetComponentCached<Renderer> (ref _renderer); if (_renderer != null) { _renderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off; _renderer.receiveShadows = false; } int segments = 32; lineRenderer.SetVertexCount(segments); CreateCircle(lineRenderer, segments, 0.25); //set properties SetSelectionLineProperties(container.EVA, lineRenderer); selectionLines.Add(container.flightID, lineRenderer); }
public void FromSave(string formation) { try { //EvaDebug.DebugWarning("Formation.FromSave()"); formation = formation.Remove(0, 7); //Leader: if (formation != "null") { Guid flightID = new Guid(formation); EvaContainer container = EvaController.instance.GetEva(flightID); if (container != null) { leader = container; } } } catch { throw new Exception("[EFX] Formation.FromSave Failed."); } }
public void SetLeader(EvaContainer leader) { this.leader = leader; }
public static void SaveEva(EvaContainer container){ EvaDebug.DebugWarning("EvaSettings.SaveEva(" + container.Name + ")"); if (container.status == Status.Removed) { if (collection.ContainsKey(container.flightID)) { collection.Remove(container.flightID); } } else { //The eva was already has a old save. if (collection.ContainsKey(container.flightID)) { //Replace the old save. collection[container.flightID] = container.ToSave(); } else { //No save yet. Add it now. collection.Add(container.flightID, container.ToSave()); } } }
public static void LoadEva(EvaContainer container) { EvaDebug.DebugWarning("EvaSettings.LoadEva(" + container.Name + ")"); //The eva was already has a old save. //Load it. if (collection.ContainsKey(container.flightID)) { //string evaString = collection[container.flightID]; //EvaDebug.DebugWarning(evaString); container.FromSave(collection[container.flightID]); } else { //No save yet. } }