/// <summary> /// Return a value in the range of 0 to 1 representing where the current variable /// evaluates within its range. /// </summary> /// <returns></returns> public float InverseLerp() { float value = sourceValue.AsFloat(); float low = lowerBound.AsFloat(); float high = upperBound.AsFloat(); if (modulo != null) { float mod = modulo.AsFloat(); float scaledValue = Mathf.InverseLerp(low, high, value); float range = Mathf.Abs(high - low); if (range > 0.0f) { float modDivRange = mod / range; scaledValue = (scaledValue % (modDivRange)) / modDivRange; } return(scaledValue); } else { return(Mathf.InverseLerp(low, high, value)); } }
internal void Update() { if (enablingVariable != null) { if (!enablingVariable.IsInRange()) { return; } } float value = variable.AsFloat(); if (useLog10) { value = JUtil.PseudoLog10(value); } float xOffset = JUtil.DualLerp(textureLimit, scale, value); MeshFilter meshFilter = barObject.GetComponent <MeshFilter>(); meshFilter.mesh.uv = new[] { new Vector2(xOffset - textureSize, 0.0f), new Vector2(xOffset + textureSize, 0.0f), new Vector2(xOffset - textureSize, 1.0f), new Vector2(xOffset + textureSize, 1.0f) }; JUtil.ShowHide(true, barObject); }
public object Evaluate() { float lerp = sourceVariable.InverseLerp(); float extent1 = mappedExtent1.AsFloat(); float extent2 = mappedExtent2.AsFloat(); return(Mathf.Lerp(extent1, extent2, lerp)); }
public void Start() { if (HighLogic.LoadedSceneIsEditor) { return; } try { rpmComp = RasterPropMonitorComputer.Instantiate(internalProp, true); if (string.IsNullOrEmpty(perPodPersistenceName)) { JUtil.LogErrorMessage(this, "perPodPersistenceName must be defined"); return; } if (string.IsNullOrEmpty(defaultValue)) { JUtil.LogErrorMessage(this, "defaultValue must be defined"); return; } if (stepSize < 0.0f) { stepSize = 0.0f; } //JUtil.LogMessage(this, "Start(): {0}, {1}, {2}, {3}, {4}", perPodPersistenceName, defaultValue, minValue, maxValue, stepSize); if (!string.IsNullOrEmpty(minValue)) { minRange = rpmComp.InstantiateVariableOrNumber(minValue); //JUtil.LogMessage(this, "Created lower bound variable"); } if (!string.IsNullOrEmpty(maxValue)) { maxRange = rpmComp.InstantiateVariableOrNumber(maxValue); //JUtil.LogMessage(this, "Created upper bound variable"); } if ((minRange == null || maxRange == null) && loopInput == true) { JUtil.LogErrorMessage(this, "Overriding loopInput - minValue or maxValue is missing"); loopInput = false; } if (!rpmComp.HasPersistentVariable(perPodPersistenceName, perPodPersistenceIsGlobal)) { //JUtil.LogMessage(this, "Initializing per pod persistence value {0}", perPodPersistenceName); VariableOrNumber von = rpmComp.InstantiateVariableOrNumber(defaultValue); float value = von.AsFloat(); if (stepSize > 0.0f) { float remainder = value % stepSize; value -= remainder; } rpmComp.SetPersistentVariable(perPodPersistenceName, value, perPodPersistenceIsGlobal); } ConfigNode moduleConfig = null; foreach (ConfigNode node in GameDatabase.Instance.GetConfigNodes("PROP")) { if (node.GetValue("name") == internalProp.propName) { moduleConfig = node.GetNodes("MODULE")[moduleID]; ConfigNode[] inputNodes = moduleConfig.GetNodes("USERINPUTSET"); for (int i = 0; i < inputNodes.Length; i++) { try { numericInputs.Add(new NumericInput(inputNodes[i], internalProp)); //JUtil.LogMessage(this, "Added USERINPUTSET {0}", inputNodes[i].GetValue("switchTransform")); } catch (ArgumentException e) { JUtil.LogErrorMessage(this, "Error in building prop number {1} - {0}", e.Message, internalProp.propID); } } break; } } enabled = true; } catch { JUtil.AnnoyUser(this); enabled = false; throw; } }
public void Click() { bool switchEnabled = true; if (!forcedShutdown) { if (perPodMasterSwitchValid) { switchEnabled = rpmComp.GetPersistentVariable(perPodMasterSwitchName, false, false); } if (masterVariable != null) { switchEnabled = masterVariable.IsInRange(); } } if (!switchEnabled) { // If the master switch is 'off' and we're not here because // of a forced shutdown, don't allow this switch to work. // early return return; } if (isCustomAction) { if (switchGroupIdentifier >= 0) { if (!forcedShutdown && !customGroupState) { customGroupState = true; if (persistentVarValid) { rpmComp.SetPersistentVariable(persistentVarName, switchGroupIdentifier, perPodPersistenceIsGlobal); } } // else: can't turn off a radio group switch. } else if (customAction == CustomActions.Plugin && stateVariable != null) { int ivalue = stateVariable.AsInt(); customGroupState = (ivalue < 1) && !forcedShutdown; } else { customGroupState = !customGroupState; if (persistentVarValid) { rpmComp.SetPersistentVariable(persistentVarName, customGroupState, perPodPersistenceIsGlobal); } } } else { vessel.ActionGroups.ToggleGroup(kspAction); } // Now we do extra things that with regular actions can't happen. switch (customAction) { case CustomActions.IntLight: SetInternalLights(customGroupState); break; case CustomActions.Plugin: actionHandler(customGroupState); break; case CustomActions.Stage: if (InputLockManager.IsUnlocked(ControlTypes.STAGING)) { StageManager.ActivateNextStage(); } break; case CustomActions.TransferToPersistent: if (stateVariable != null) { // stateVariable can disable the button functionality. int ivalue = stateVariable.AsInt(); if (ivalue < 1) { return; // early - button disabled } } float getValue = transferGetter.AsFloat(); rpmComp.SetPersistentVariable(transferPersistentName, getValue, false); break; case CustomActions.TransferFromPersistent: if (stateVariable != null) { // stateVariable can disable the button functionality. int ivalue = stateVariable.AsInt(); if (ivalue < 1) { return; // early - button disabled } } if (rpmComp.HasPersistentVariable(transferPersistentName, false)) { transferSetter(rpmComp.GetPersistentVariable(transferPersistentName, 0.0, false).MassageToDouble()); } break; case CustomActions.TransferFromVariable: if (stateVariable != null) { // stateVariable can disable the button functionality. int ivalue = stateVariable.AsInt(); if (ivalue < 1) { return; // early - button disabled } } double xferValue = transferGetter.AsDouble(); transferSetter(xferValue); break; } }