public void CalcPos(PosMode mode) { if(riverZPos == float.MinValue) { riverZPos = Random.Range(-posRange, posRange); } if(mode == PosMode.RANDOM) { transform.position = new Vector3(Random.Range(-posRange, posRange), Random.Range(-posRange, posRange), Random.Range(-posRange, posRange)); } else if(mode == PosMode.RIVER) { float avg = 0; foreach(int i in connsFromStart) { avg += i; } avg = avg / connsFromStart.Count; transform.position = new Vector3(avg * streamStretch, 0, riverZPos); } }
// Use this for initialization protected void BaseGUI(GUIDel action) { GUILayout.BeginVertical(); GUILayout.Space(5); //Source sprite for platforms baseSprite = (Sprite)EditorGUILayout.ObjectField("Source sprite", baseSprite, typeof(Sprite), false); orderInLayer = EditorGUILayout.IntField("Sorting order", orderInLayer); GUILayout.Space(10); //Position mode and parent field for the created object position posMode = (PosMode)EditorGUILayout.EnumPopup("Position mode:", posMode, GUILayout.MaxWidth(250)); if (posMode == PosMode.local) { parent = (Transform)EditorGUILayout.ObjectField("Parent", parent, typeof(Transform), true); } startPos = EditorGUILayout.Vector2Field("Position ", startPos, GUILayout.MaxWidth(250)); if (action != null) { action(); } GUILayout.Space(2.5f); startScale = EditorGUILayout.Vector2Field("Scale ", startScale, GUILayout.MaxWidth(250)); }
// // private methods // private void checkStates() { // docking override? if (command == Command.DOCK) { attMode = AttMode.IDLE; rateMode = RateMode.IDLE; posMode = PosMode.IDLE; } // no target vessel? if (flightData.targetVessel == null) { // disable invalid att hold modes if (command == Command.ATT && (attMode == AttMode.RPP || attMode == AttMode.RPN || attMode == AttMode.RVP || attMode == AttMode.RVN)) { requestAttMode (AttMode.IDLE); } } // no target vessel or target changed? if (flightData.targetVessel == null || flightData.targetChanged) { // disable position modes if (posMode != PosMode.IDLE) { requestPosMode (PosMode.IDLE); } } // no target vessel or docking ports? if (flightData.targetVessel == null || flightData.targetPart == null || flightData.vesselPart == null || flightData.targetChanged) { // disable dock master mode if(command == Command.DOCK) { requestCommand(Command.OFF); } } }
public void restoreConfiguration(GNCconfig config) { // should be good, might need to add some checks command = config.command; rateMode = config.rateMode; attMode = config.attMode; eacMode = config.eacMode; posMode = config.posMode; dockMode = config.dockMode; dockState = config.dockState; dockAbort = config.dockAbort; userRateSetting = config.userRateSetting.toVector3 (); userAttSetting = config.userAttSetting.toVector3 (); userAttUpSetting = config.userAttUpSetting.toVector3 (); userPosSetting = config.userPosSetting.toVector3 (); Kp_AngVel = config.Kp_AngVel; Kp_AngAcc = config.Kp_AngAcc; Kp_Vel = config.Kp_Vel; Kp_Acc = config.Kp_Acc; eacPulseLength = config.eacPulseLength; eacPulseLevel = config.eacPulseLevel; eacRate = config.eacRate; dockRollAdjust = config.dockRollAdjust; networkPropulsion = config.networkPropulsion; // ... if (command == Command.EAC && eacMode == EACMode.RATE_ATT) { eacAttInvalid = true; } }
public void requestPosMode(PosMode m) { if(command == Command.DOCK) return; if(posMode == m) posMode = PosMode.IDLE; else posMode = m; if(posMode == PosMode.HOLD) userPosHoldRequest = true; }
public void requestCommand(Command c) { command = c; rateMode = RateMode.IDLE; attMode = AttMode.IDLE; eacMode = EACMode.IDLE; dockMode = DockMode.IDLE; dockState = DockState.IDLE; if (command != Command.RATE && command != Command.ATT && command != Command.EAC) posMode = PosMode.IDLE; if (command == Command.DOCK) { if (flightData.targetVessel == null) { command = Command.OFF; } } }
public void getStates(out Command outCommand, out RateMode outRateMode, out AttMode outAttMode, out EACMode outEacMode, out PosMode outPosMode, out DockMode outDockMode) { outCommand = command; outRateMode = rateMode; outAttMode = attMode; outEacMode = eacMode; outPosMode = posMode; outDockMode = dockMode; }
private void positionLogic() { // process hold request if (userPosHoldRequest) { userPosHoldRequest = false; userPosSetting = flightData.targetRelPosition; } if (posMode == PosMode.ZERO) { rvelActive = true; rvelCommand = Vector3.zero; } else if (posMode == PosMode.HOLD) { rposActive = true; rposCommand = userPosSetting; } else if (posMode == PosMode.VN) { rposActive = true; rposCommand = Util.reorder (flightData.targetVessel.orbit.vel, 132).normalized * positionModeDistance; } else if (posMode == PosMode.RN) { rposActive = true; rposCommand = Util.reorder (flightData.targetVessel.orbit.pos, 132).normalized * positionModeDistance; } else if (posMode == PosMode.RETREAT) { rvelActive = true; rvelCommand = flightData.targetRelPositionShip.normalized * 1.0f; if (flightData.targetRelPosition.magnitude > 50) { posMode = PosMode.ZERO; } } if (rposActive) { // limit to save some rcs fuel rvelLimitMax = true; float dist = rposError.magnitude; if (dist < 100) { rvelLimit = 1.0f; } else { rvelLimit = 2.5f; } } }