private static Texture2D LoadFont(object caller, InternalProp thisProp, string location) { Texture2D font = null; if (!string.IsNullOrEmpty(location)) { try { if (GameDatabase.Instance.ExistsTexture(location.EnforceSlashes())) { font = GameDatabase.Instance.GetTexture(location.EnforceSlashes(), false); JUtil.LogMessage(caller, "Loading font texture from URL \"{0}\"", location); } else { font = (Texture2D)thisProp.FindModelTransform(location).GetComponent <Renderer>().material.mainTexture; JUtil.LogMessage(caller, "Loading font texture from a transform named \"{0}\"", location); } } catch (Exception) { JUtil.LogErrorMessage(caller, "Failed loading font texture \"{0}\" - missing texture?", location); } } return(font); }
private static SmarterButton AttachBehaviour(InternalProp thatProp, InternalModel thatModel, string buttonName) { string[] tokens = buttonName.Split('|'); if (thatModel == null || tokens.Length == 2) { if (tokens.Length == 2) { // First token is the button name, second is the prop ID. int propID; if (int.TryParse(tokens[1], out propID)) { if (propID < thatProp.internalModel.props.Count) { if (propID < 0) { thatModel = thatProp.internalModel; } else { thatProp = thatProp.internalModel.props[propID]; thatModel = null; } buttonName = tokens[0].Trim(); } else { Debug.LogError(string.Format("Could not find a prop with ID {0}", propID)); } } } else { buttonName = buttonName.Trim(); } } try { GameObject buttonObject; buttonObject = thatModel == null?thatProp.FindModelTransform(buttonName).gameObject : thatModel.FindModelTransform(buttonName).gameObject; SmarterButton thatComponent = buttonObject.GetComponent <SmarterButton>() ?? buttonObject.AddComponent <SmarterButton>(); return(thatComponent); } catch { Debug.LogError(string.Format( "Could not register a button on transform named '{0}' in {2} named '{1}'. Check your configuration.", buttonName, thatModel == null ? thatProp.propName : thatModel.name, thatModel == null ? "prop" : "internal model")); } return(null); }
internal MASComponentTextureReplacement(ConfigNode config, InternalProp prop, MASFlightComputer comp) : base(config, prop, comp) { string transform = string.Empty; if (!config.TryGetValue("transform", ref transform)) { throw new ArgumentException("Missing 'transform' in TEXTURE_REPLACEMENT " + name); } string layers = "_MainTex"; config.TryGetValue("layers", ref layers); Transform t = prop.FindModelTransform(transform); Renderer r = t.GetComponent <Renderer>(); localMaterial = r.material; string[] layer = layers.Split(); int layerLength = layer.Length; for (int i = 0; i < layerLength; ++i) { layer[i] = layer[i].Trim(); } string textureName = string.Empty; if (!config.TryGetValue("texture", ref textureName)) { throw new ArgumentException("Unable to find 'texture' in TEXTURE_REPLACEMENT " + name); } Texture2D mainTexture = null; if (textureName == "%FLAG%") { textureName = prop.part.flagURL; } mainTexture = GameDatabase.Instance.GetTexture(textureName, false); if (mainTexture == null) { throw new ArgumentException("Unable to find 'texture' " + textureName + " for TEXTURE_REPLACEMENT " + name); } for (int i = layer.Length - 1; i >= 0; --i) { localMaterial.SetTexture(layer[i], mainTexture); } }
internal MASComponentModelScale(ConfigNode config, InternalProp prop, MASFlightComputer comp) : base(config, prop, comp) { string transform = string.Empty; if (!config.TryGetValue("transform", ref transform)) { throw new ArgumentException("Missing 'transform' in MODEL_SCALE " + name); } this.transform = prop.FindModelTransform(transform.Trim()); if (this.transform == null) { throw new ArgumentException("Unable to find 'transform' " + transform + " for MODEL_SCALE " + name); } Vector3 initialScale = this.transform.localScale; string variableName = string.Empty; if (!config.TryGetValue("variable", ref variableName) || string.IsNullOrEmpty(variableName)) { throw new ArgumentException("Invalid or missing 'variable' in MODEL_SCALE " + name); } if (!config.TryGetValue("startScale", ref startScale)) { throw new ArgumentException("Invalid or missing 'startScale' in MODEL_SCALE " + name); } else { startScale = startScale + initialScale; } if (!config.TryGetValue("endScale", ref endScale)) { throw new ArgumentException("Invalid or missing 'endScale' in MODEL_SCALE " + name); } else { endScale = endScale + initialScale; } blend = false; config.TryGetValue("blend", ref blend); comp.StartCoroutine(DelayedRegistration(variableName)); }
internal MASComponentImage(ConfigNode config, InternalProp prop, MASFlightComputer comp) : base(config, prop, comp) { string textureName = string.Empty; if (!config.TryGetValue("texture", ref textureName)) { throw new ArgumentException("Unable to find 'texture' in IMAGE " + name); } if (textureName == "%FLAG%") { textureName = prop.part.flagURL; } Texture2D mainTexture = GameDatabase.Instance.GetTexture(textureName, false); if (mainTexture == null) { throw new ArgumentException("Unable to find 'texture' " + textureName + " for IMAGE " + name); } string transformName = string.Empty; if (!config.TryGetValue("transform", ref transformName)) { throw new ArgumentException("Missing 'transform' in IMAGE " + name); } Transform transform = prop.FindModelTransform(transformName); if (transform == null) { throw new ArgumentException("Unable to find transform \"" + transformName + "\" for IMAGE " + name); } Renderer renderer = transform.GetComponent <Renderer>(); if (renderer == null) { throw new ArgumentException("No renderer attached to transform \"" + transformName + "\" for IMAGE " + name); } renderer.material.SetTexture("_MainTex", mainTexture); }
private static Texture2D LoadFont(object caller, InternalProp thisProp, string location, bool extra) { Texture2D font = null; if (!string.IsNullOrEmpty(location)) { JUtil.LogMessage(caller, "Trying to locate \"{0}\" in GameDatabase...", location); if (GameDatabase.Instance.ExistsTexture(location.EnforceSlashes())) { font = GameDatabase.Instance.GetTexture(location.EnforceSlashes(), false); JUtil.LogMessage(caller, "Loading{1} font texture from URL, \"{0}\"", location, extra ? " extra" : string.Empty); } else { font = (Texture2D)thisProp.FindModelTransform(location).renderer.material.mainTexture; JUtil.LogMessage(caller, "Loading{1} font texture from a transform named, \"{0}\"", location, extra ? " extra" : string.Empty); } } return(font); }
public static Transform GetTransform(InternalProp prop, ConfigNode configuration, string configKey) { string transformName = ""; bool success = configuration.TryGetValue(configKey, ref transformName); if (!success) { throw new ArgumentException(configKey + " not specified for " + prop.name + " (config node " + configuration.id + ")"); } Transform transform = prop.FindModelTransform(transformName); if (transform == null) { throw new ArgumentException("Transform \"" + transformName + "\" not found for " + prop.name + " (config node " + configuration.id + ")"); } return(transform); }
internal MASComponentColliderAdvanced(ConfigNode config, InternalProp internalProp, MASFlightComputer comp) : base(config, internalProp, comp) { string collider = string.Empty; if (!config.TryGetValue("collider", ref collider)) { throw new ArgumentException("Missing 'collider' in COLLIDER_ADVANCED " + name); } string clickAction = string.Empty; string dragAction = string.Empty; string releaseAction = string.Empty; string monitorID = string.Empty; if (!config.TryGetValue("monitorID", ref monitorID)) { config.TryGetValue("onClick", ref clickAction); config.TryGetValue("onDrag", ref dragAction); config.TryGetValue("onRelease", ref releaseAction); if (string.IsNullOrEmpty(clickAction) && string.IsNullOrEmpty(dragAction) && string.IsNullOrEmpty(releaseAction)) { throw new ArgumentException("Missing 'monitorID', 'onClick', 'onDrag', or 'onRelease' in COLLIDER_ADVANCED " + name); } } string clickX = string.Empty; if (!config.TryGetValue("clickX", ref clickX)) { throw new ArgumentException("Missing 'clickX' in COLLIDER_ADVANCED " + name); } string clickY = string.Empty; if (!config.TryGetValue("clickY", ref clickY)) { throw new ArgumentException("Missing 'clickY' in COLLIDER_ADVANCED " + name); } Transform tr = internalProp.FindModelTransform(collider.Trim()); if (tr == null) { throw new ArgumentException("Unable to find transform '" + collider + "' in prop for COLLIDER_ADVANCED " + name); } float volume = -1.0f; if (config.TryGetValue("volume", ref volume)) { volume = Mathf.Clamp01(volume); } else { volume = -1.0f; } string sound = string.Empty; if (!config.TryGetValue("sound", ref sound) || string.IsNullOrEmpty(sound)) { sound = string.Empty; } AudioClip clip = null; if (string.IsNullOrEmpty(sound) && (volume >= 0.0f)) { throw new ArgumentException("'volume', but no 'sound', found in COLLIDER_ADVANCED " + name); } if (!string.IsNullOrEmpty(sound)) { //Try Load audio clip = GameDatabase.Instance.GetAudioClip(sound); if (clip == null) { throw new ArgumentException("Unable to load 'sound' " + sound + " in COLLIDER_ADVANCED " + name); } if (volume < 0.0f) { volume = 1.0f; } } buttonObject = tr.gameObject.AddComponent <AdvancedButtonObject>(); buttonObject.parent = this; if (string.IsNullOrEmpty(monitorID)) { if (!string.IsNullOrEmpty(clickAction)) { onClick = comp.GetColliderAction(clickAction, 0, "click", internalProp); } if (!string.IsNullOrEmpty(dragAction)) { onDrag = comp.GetColliderAction(dragAction, 0, "drag", internalProp); } if (!string.IsNullOrEmpty(releaseAction)) { onRelease = comp.GetColliderAction(releaseAction, 0, "release", internalProp); } buttonObject.onTouch = (Vector2 hitCoordinate, EventType eventType) => { if (eventType == EventType.MouseDown) { if (onClick != null) { onClick(hitCoordinate); } } else if (eventType == EventType.MouseDrag) { if (onDrag != null) { onDrag(hitCoordinate); } } else if (eventType == EventType.MouseUp) { if (onRelease != null) { onRelease(hitCoordinate); } } }; } else { buttonObject.onTouch = comp.GetHitAction(monitorID, internalProp, comp.HandleTouchEvent); } buttonObject.hitTransformation = comp.GetColliderTransformation(clickX, clickY, name, internalProp); Collider btnCollider = tr.gameObject.GetComponent <Collider>(); if (btnCollider == null) { throw new ArgumentException("Unable to retrieve Collider from GameObject in COLLIDER_ADVANCED " + name); } BoxCollider boxCollider = btnCollider as BoxCollider; if (boxCollider == null) { throw new ArgumentException("Collider for COLLIDER_ADVANCED " + name + " is not a BoxCollider"); } buttonObject.InitBoxCollider(boxCollider); if (!config.TryGetValue("logHits", ref buttonObject.debugEnabled)) { buttonObject.debugEnabled = false; } string variableName = string.Empty; if (config.TryGetValue("variable", ref variableName)) { variableName = variableName.Trim(); buttonObject.colliderEnabled = false; comp.RegisterVariableChangeCallback(variableName, internalProp, VariableCallback); } else { variableEnabled = true; } comp.RegisterVariableChangeCallback("fc.CrewConscious(-1)", internalProp, KerbalCallback); if (clip != null) { AudioSource audioSource = tr.gameObject.AddComponent <AudioSource>(); audioSource.clip = clip; audioSource.Stop(); audioSource.volume = GameSettings.SHIP_VOLUME * volume; audioSource.rolloffMode = AudioRolloffMode.Logarithmic; audioSource.maxDistance = 8.0f; audioSource.minDistance = 2.0f; audioSource.dopplerLevel = 0.0f; audioSource.panStereo = 0.0f; audioSource.playOnAwake = false; audioSource.loop = false; audioSource.pitch = 1.0f; buttonObject.audioSource = audioSource; } }
internal MASComponentInternalText(ConfigNode config, InternalProp prop, MASFlightComputer comp) : base(config, prop, comp) { string transform = string.Empty; if (!config.TryGetValue("transform", ref transform)) { throw new ArgumentException("Missing 'transform' in INTERNAL_TEXT " + name); } string text = string.Empty; if (!config.TryGetValue("text", ref text)) { throw new ArgumentException("Invalid or missing 'text' in INTERNAL_TEXT " + name); } Color passiveColor = Color.white; string passiveColorStr = string.Empty; if (!config.TryGetValue("passiveColor", ref passiveColorStr)) { throw new ArgumentException("Invalid or missing 'passiveColor' in INTERNAL_TEXT " + name); } else { Color32 namedColor; if (comp.TryGetNamedColor(passiveColorStr, out namedColor)) { passiveColor = namedColor; } else { string[] startColors = Utility.SplitVariableList(passiveColorStr); if (startColors.Length < 3 || startColors.Length > 4) { throw new ArgumentException("passiveColor does not contain 3 or 4 values in INTERNAL_TEXT " + name); } float x; if (!float.TryParse(startColors[0], out x)) { throw new ArgumentException("Unable to parse passiveColor red value in INTERNAL_TEXT " + name); } passiveColor.r = Mathf.Clamp01(x * (1.0f / 255.0f)); if (!float.TryParse(startColors[1], out x)) { throw new ArgumentException("Unable to parse passiveColor green value in INTERNAL_TEXT " + name); } passiveColor.g = Mathf.Clamp01(x * (1.0f / 255.0f)); if (!float.TryParse(startColors[2], out x)) { throw new ArgumentException("Unable to parse passiveColor blue value in INTERNAL_TEXT " + name); } passiveColor.b = Mathf.Clamp01(x * (1.0f / 255.0f)); if (startColors.Length == 4) { if (!float.TryParse(startColors[3], out x)) { throw new ArgumentException("Unable to parse passiveColor alpha value in INTERNAL_TEXT " + name); } passiveColor.a = Mathf.Clamp01(x * (1.0f / 255.0f)); } } } text = MdVTextMesh.UnmangleText(text); // See if this is a single-line text, or multi-line. The latter is not supported here. string[] textRows = text.Split(Utility.LineSeparator, StringSplitOptions.RemoveEmptyEntries); if (textRows.Length > 1) { throw new ArgumentException("Multi-line text is not supported in INTERNAL_TEXT " + name); } text = textRows[0]; bool mutable = false; if (text.Contains(MdVTextMesh.VariableListSeparator[0]) || text.Contains(MdVTextMesh.VariableListSeparator[1])) { mutable = true; } Transform textObjTransform = prop.FindModelTransform(transform); // TODO: Allow variable fontSize? float fontSize = 0.15f; textObj = InternalComponents.Instance.CreateText("Arial", fontSize, textObjTransform, (mutable) ? "-" : text, passiveColor, false, "TopLeft"); try { Transform q = textObj.text.transform; q.Translate(0.0f, 0.0048f, 0.0f); } catch (Exception) { } if (mutable) { string[] sections = text.Split(MdVTextMesh.VariableListSeparator, StringSplitOptions.RemoveEmptyEntries); if (sections.Length != 2) { throw new ArgumentException("Error parsing text in INTERNAL_TEXT " + name); } MdVTextMesh.TextRow tr = new MdVTextMesh.TextRow(); tr.formatString = sections[0]; // See if this text contains formatted rich text nudges if (tr.formatString.Contains("[")) { throw new ArgumentException("Formatted rich text is not supported in INTERNAL_TEXT " + name); } string[] variables = sections[1].Split(';'); tr.variable = new Variable[variables.Length]; tr.evals = new object[variables.Length]; tr.callback = (double dontCare) => { tr.rowInvalidated = true; }; for (int var = 0; var < tr.variable.Length; ++var) { try { tr.variable[var] = variableRegistrar.RegisterVariableChangeCallback(variables[var], tr.callback); } catch (Exception e) { Utility.LogError(this, "Variable {0} threw an exception", variables[var]); throw e; } } tr.rowInvalidated = true; tr.EvaluateVariables(); textObj.text.text = tr.formattedData; textRow = tr; coroutineEnabled = true; comp.StartCoroutine(StringUpdateCoroutine()); } }
internal MASComponentColorShift(ConfigNode config, InternalProp prop, MASFlightComputer comp) : base(config, prop, comp) { string transform = string.Empty; if (!config.TryGetValue("transform", ref transform)) { throw new ArgumentException("Missing 'transform' in COLOR_SHIFT " + name); } string[] transforms = transform.Split(','); string colorName = "_EmissiveColor"; config.TryGetValue("colorName", ref colorName); colorIndex = Shader.PropertyToID(colorName.Trim()); localMaterial = new Material[transforms.Length]; for (int i = transforms.Length - 1; i >= 0; --i) { try { Transform t = prop.FindModelTransform(transforms[i].Trim()); Renderer r = t.GetComponent <Renderer>(); localMaterial[i] = r.material; } catch (Exception e) { Utility.LogError(this, "Can't find transform {0} in COLOR_SHIFT {1}", transforms[i].Trim(), name); throw e; } } // activeColor, passiveColor string passiveColorStr = string.Empty; if (!config.TryGetValue("passiveColor", ref passiveColorStr)) { throw new ArgumentException("Invalid or missing 'passiveColor' in COLOR_SHIFT " + name); } string variableName = string.Empty; if (config.TryGetValue("variable", ref variableName)) { variableName = variableName.Trim(); } blend = false; config.TryGetValue("blend", ref blend); if (blend == false && config.TryGetValue("flashRate", ref flashRate) && flashRate > 0.0f) { useFlash = true; comp.RegisterFlashCallback(flashRate, FlashToggle); } Color32 namedColor; if (comp.TryGetNamedColor(passiveColorStr, out namedColor)) { passiveColor = namedColor; } else { string[] startColors = Utility.SplitVariableList(passiveColorStr); if (startColors.Length < 3 || startColors.Length > 4) { throw new ArgumentException("passiveColor does not contain 3 or 4 values in COLOR_SHIFT " + name); } variableRegistrar.RegisterVariableChangeCallback(startColors[0], (double newValue) => { passiveColor.r = Mathf.Clamp01((float)newValue * (1.0f / 255.0f)); if (blend) { UpdateBlendColor(); } else { UpdateBooleanColor(); } }); variableRegistrar.RegisterVariableChangeCallback(startColors[1], (double newValue) => { passiveColor.g = Mathf.Clamp01((float)newValue * (1.0f / 255.0f)); if (blend) { UpdateBlendColor(); } else { UpdateBooleanColor(); } }); variableRegistrar.RegisterVariableChangeCallback(startColors[2], (double newValue) => { passiveColor.b = Mathf.Clamp01((float)newValue * (1.0f / 255.0f)); if (blend) { UpdateBlendColor(); } else { UpdateBooleanColor(); } }); if (startColors.Length == 4) { variableRegistrar.RegisterVariableChangeCallback(startColors[3], (double newValue) => { passiveColor.a = Mathf.Clamp01((float)newValue * (1.0f / 255.0f)); if (blend) { UpdateBlendColor(); } else { UpdateBooleanColor(); } }); } } // Final validations if (blend || useFlash || !string.IsNullOrEmpty(variableName)) { string activeColorStr = string.Empty; if (string.IsNullOrEmpty(variableName)) { throw new ArgumentException("Invalid or missing 'variable' in COLOR_SHIFT " + name); } else if (config.TryGetValue("activeColor", ref activeColorStr)) { if (comp.TryGetNamedColor(activeColorStr, out namedColor)) { activeColor = namedColor; } else { string[] startColors = Utility.SplitVariableList(activeColorStr); if (startColors.Length < 3 || startColors.Length > 4) { throw new ArgumentException("activeColor does not contain 3 or 4 values in COLOR_SHIFT " + name); } variableRegistrar.RegisterVariableChangeCallback(startColors[0], (double newValue) => { activeColor.r = Mathf.Clamp01((float)newValue * (1.0f / 255.0f)); if (blend) { UpdateBlendColor(); } else { UpdateBooleanColor(); } }); variableRegistrar.RegisterVariableChangeCallback(startColors[1], (double newValue) => { activeColor.g = Mathf.Clamp01((float)newValue * (1.0f / 255.0f)); if (blend) { UpdateBlendColor(); } else { UpdateBooleanColor(); } }); variableRegistrar.RegisterVariableChangeCallback(startColors[2], (double newValue) => { activeColor.b = Mathf.Clamp01((float)newValue * (1.0f / 255.0f)); if (blend) { UpdateBlendColor(); } else { UpdateBooleanColor(); } }); if (startColors.Length == 4) { variableRegistrar.RegisterVariableChangeCallback(startColors[3], (double newValue) => { activeColor.a = Mathf.Clamp01((float)newValue * (1.0f / 255.0f)); if (blend) { UpdateBlendColor(); } else { UpdateBooleanColor(); } }); } } } else { throw new ArgumentException("Invalid or missing 'activeColor' in COLOR_SHIFT " + name); } } // Make everything a known value before the callback fires. for (int i = localMaterial.Length - 1; i >= 0; --i) { localMaterial[i].SetColor(colorIndex, passiveColor); } if (!string.IsNullOrEmpty(variableName)) { variableRegistrar.RegisterVariableChangeCallback(variableName, VariableCallback); } }
public VariableAnimationSet(ConfigNode node, InternalProp thisProp) { part = thisProp.part; if (!node.HasData) { throw new ArgumentException("No data?!"); } comp = RasterPropMonitorComputer.Instantiate(thisProp); string[] tokens = { }; if (node.HasValue("scale")) { tokens = node.GetValue("scale").Split(','); } if (tokens.Length != 2) { throw new ArgumentException("Could not parse 'scale' parameter."); } if (node.HasValue("variableName")) { string variableName; variableName = node.GetValue("variableName").Trim(); scaleEnds[2] = new VariableOrNumber(variableName, this); } else if (node.HasValue("stateMethod")) { Func<bool> stateFunction = (Func<bool>)comp.GetMethod(node.GetValue("stateMethod").Trim(), thisProp, typeof(Func<bool>)); if (stateFunction != null) { scaleEnds[2] = new VariableOrNumber(stateFunction, this); } else { throw new ArgumentException("Unrecognized stateMethod"); } } else { throw new ArgumentException("Missing variable name."); } scaleEnds[0] = new VariableOrNumber(tokens[0], this); scaleEnds[1] = new VariableOrNumber(tokens[1], this); // That takes care of the scale, now what to do about that scale: if (node.HasValue("reverse")) { if (!bool.TryParse(node.GetValue("reverse"), out reverse)) { throw new ArgumentException("So is 'reverse' true or false?"); } } if (node.HasValue("animationName")) { animationName = node.GetValue("animationName"); if (node.HasValue("animationSpeed")) { animationSpeed = float.Parse(node.GetValue("animationSpeed")); if (reverse) { animationSpeed = -animationSpeed; } } else { animationSpeed = 0.0f; } Animation[] anims = node.HasValue("animateExterior") ? thisProp.part.FindModelAnimators(animationName) : thisProp.FindModelAnimators(animationName); if (anims.Length > 0) { onAnim = anims[0]; onAnim.enabled = true; onAnim[animationName].speed = 0; onAnim[animationName].normalizedTime = reverse ? 1f : 0f; looping = node.HasValue("loopingAnimation"); if (looping) { onAnim[animationName].wrapMode = WrapMode.Loop; onAnim.wrapMode = WrapMode.Loop; onAnim[animationName].speed = animationSpeed; mode = Mode.LoopingAnimation; } else { onAnim[animationName].wrapMode = WrapMode.Once; mode = Mode.Animation; } onAnim.Play(); alwaysActive = node.HasValue("animateExterior"); } else { throw new ArgumentException("Animation could not be found."); } if (node.HasValue("stopAnimationName")) { stopAnimationName = node.GetValue("stopAnimationName"); anims = node.HasValue("animateExterior") ? thisProp.part.FindModelAnimators(stopAnimationName) : thisProp.FindModelAnimators(stopAnimationName); if (anims.Length > 0) { offAnim = anims[0]; offAnim.enabled = true; offAnim[stopAnimationName].speed = 0; offAnim[stopAnimationName].normalizedTime = reverse ? 1f : 0f; if (looping) { offAnim[stopAnimationName].wrapMode = WrapMode.Loop; offAnim.wrapMode = WrapMode.Loop; offAnim[stopAnimationName].speed = animationSpeed; mode = Mode.LoopingAnimation; } else { offAnim[stopAnimationName].wrapMode = WrapMode.Once; mode = Mode.Animation; } } } } else if (node.HasValue("activeColor") && node.HasValue("passiveColor") && node.HasValue("coloredObject")) { if (node.HasValue("colorName")) colorName = node.GetValue("colorName"); passiveColor = ConfigNode.ParseColor32(node.GetValue("passiveColor")); activeColor = ConfigNode.ParseColor32(node.GetValue("activeColor")); colorShiftRenderer = thisProp.FindModelComponent<Renderer>(node.GetValue("coloredObject")); colorShiftRenderer.material.SetColor(colorName, reverse ? activeColor : passiveColor); mode = Mode.Color; } else if (node.HasValue("controlledTransform") && node.HasValue("localRotationStart") && node.HasValue("localRotationEnd")) { controlledTransform = thisProp.FindModelTransform(node.GetValue("controlledTransform").Trim()); initialRotation = controlledTransform.localRotation; if (node.HasValue("longPath")) { longPath = true; vectorStart = ConfigNode.ParseVector3(node.GetValue("localRotationStart")); vectorEnd = ConfigNode.ParseVector3(node.GetValue("localRotationEnd")); } else { rotationStart = Quaternion.Euler(ConfigNode.ParseVector3(node.GetValue("localRotationStart"))); rotationEnd = Quaternion.Euler(ConfigNode.ParseVector3(node.GetValue("localRotationEnd"))); } mode = Mode.Rotation; } else if (node.HasValue("controlledTransform") && node.HasValue("localTranslationStart") && node.HasValue("localTranslationEnd")) { controlledTransform = thisProp.FindModelTransform(node.GetValue("controlledTransform").Trim()); initialPosition = controlledTransform.localPosition; vectorStart = ConfigNode.ParseVector3(node.GetValue("localTranslationStart")); vectorEnd = ConfigNode.ParseVector3(node.GetValue("localTranslationEnd")); mode = Mode.Translation; } else if (node.HasValue("controlledTransform") && node.HasValue("localScaleStart") && node.HasValue("localScaleEnd")) { controlledTransform = thisProp.FindModelTransform(node.GetValue("controlledTransform").Trim()); initialScale = controlledTransform.localScale; vectorStart = ConfigNode.ParseVector3(node.GetValue("localScaleStart")); vectorEnd = ConfigNode.ParseVector3(node.GetValue("localScaleEnd")); mode = Mode.Scale; } else if (node.HasValue("controlledTransform") && node.HasValue("textureLayers") && node.HasValue("textureShiftStart") && node.HasValue("textureShiftEnd")) { affectedMaterial = thisProp.FindModelTransform(node.GetValue("controlledTransform").Trim()).renderer.material; textureLayer = node.GetValue("textureLayers"); textureShiftStart = ConfigNode.ParseVector2(node.GetValue("textureShiftStart")); textureShiftEnd = ConfigNode.ParseVector2(node.GetValue("textureShiftEnd")); mode = Mode.TextureShift; } else if (node.HasValue("controlledTransform") && node.HasValue("textureLayers") && node.HasValue("textureScaleStart") && node.HasValue("textureScaleEnd")) { affectedMaterial = thisProp.FindModelTransform(node.GetValue("controlledTransform").Trim()).renderer.material; textureLayer = node.GetValue("textureLayers"); textureScaleStart = ConfigNode.ParseVector2(node.GetValue("textureScaleStart")); textureScaleEnd = ConfigNode.ParseVector2(node.GetValue("textureScaleEnd")); mode = Mode.TextureScale; } else { throw new ArgumentException("Cannot initiate any of the possible action modes."); } if (node.HasValue("threshold")) { threshold = ConfigNode.ParseVector2(node.GetValue("threshold")); } resourceAmount = 0.0f; if (threshold != Vector2.zero) { thresholdMode = true; float min = Mathf.Min(threshold.x, threshold.y); float max = Mathf.Max(threshold.x, threshold.y); threshold.x = min; threshold.y = max; if (node.HasValue("flashingDelay")) { flashingDelay = double.Parse(node.GetValue("flashingDelay")); } if (node.HasValue("alarmSound")) { alarmSoundVolume = 0.5f; if (node.HasValue("alarmSoundVolume")) alarmSoundVolume = float.Parse(node.GetValue("alarmSoundVolume")); audioOutput = JUtil.SetupIVASound(thisProp, node.GetValue("alarmSound"), alarmSoundVolume, false); if (node.HasValue("alarmMustPlayOnce")) { if (!bool.TryParse(node.GetValue("alarmMustPlayOnce"), out alarmMustPlayOnce)) throw new ArgumentException("So is 'alarmMustPlayOnce' true or false?"); } if (node.HasValue("alarmShutdownButton")) SmarterButton.CreateButton(thisProp, node.GetValue("alarmShutdownButton"), AlarmShutdown); if (node.HasValue("alarmSoundLooping")) { if (!bool.TryParse(node.GetValue("alarmSoundLooping"), out alarmSoundLooping)) throw new ArgumentException("So is 'alarmSoundLooping' true or false?"); audioOutput.audio.loop = alarmSoundLooping; } } if (node.HasValue("resourceAmount")) { resourceAmount = float.Parse(node.GetValue("resourceAmount")); } TurnOff(); } }
public VariableAnimationSet(ConfigNode node, InternalProp thisProp) { part = thisProp.part; if (!node.HasData) { throw new ArgumentException("No data?!"); } string[] tokens = { }; if (node.HasValue("scale")) { tokens = node.GetValue("scale").Split(','); } if (tokens.Length != 2) { throw new ArgumentException("Could not parse 'scale' parameter."); } if (node.HasValue("variableName")) { string variableName; variableName = node.GetValue("variableName").Trim(); scaleEnds[2] = new VariableOrNumber(variableName, this); } else if (node.HasValue("stateMethod")) { RPMVesselComputer comp = RPMVesselComputer.Instance(part.vessel); Func <bool> stateFunction = (Func <bool>)comp.GetMethod(node.GetValue("stateMethod").Trim(), thisProp, typeof(Func <bool>)); if (stateFunction != null) { scaleEnds[2] = new VariableOrNumber(stateFunction, this); } else { throw new ArgumentException("Unrecognized stateMethod"); } } else { throw new ArgumentException("Missing variable name."); } scaleEnds[0] = new VariableOrNumber(tokens[0], this); scaleEnds[1] = new VariableOrNumber(tokens[1], this); // That takes care of the scale, now what to do about that scale: if (node.HasValue("reverse")) { if (!bool.TryParse(node.GetValue("reverse"), out reverse)) { throw new ArgumentException("So is 'reverse' true or false?"); } } if (node.HasValue("animationName")) { animationName = node.GetValue("animationName"); if (node.HasValue("animationSpeed")) { animationSpeed = float.Parse(node.GetValue("animationSpeed")); if (reverse) { animationSpeed = -animationSpeed; } } else { animationSpeed = 0.0f; } Animation[] anims = node.HasValue("animateExterior") ? thisProp.part.FindModelAnimators(animationName) : thisProp.FindModelAnimators(animationName); if (anims.Length > 0) { onAnim = anims[0]; onAnim.enabled = true; onAnim[animationName].speed = 0; onAnim[animationName].normalizedTime = reverse ? 1f : 0f; looping = node.HasValue("loopingAnimation"); if (looping) { onAnim[animationName].wrapMode = WrapMode.Loop; onAnim.wrapMode = WrapMode.Loop; onAnim[animationName].speed = animationSpeed; mode = Mode.LoopingAnimation; } else { onAnim[animationName].wrapMode = WrapMode.Once; mode = Mode.Animation; } onAnim.Play(); alwaysActive = node.HasValue("animateExterior"); } else { throw new ArgumentException("Animation could not be found."); } if (node.HasValue("stopAnimationName")) { stopAnimationName = node.GetValue("stopAnimationName"); anims = node.HasValue("animateExterior") ? thisProp.part.FindModelAnimators(stopAnimationName) : thisProp.FindModelAnimators(stopAnimationName); if (anims.Length > 0) { offAnim = anims[0]; offAnim.enabled = true; offAnim[stopAnimationName].speed = 0; offAnim[stopAnimationName].normalizedTime = reverse ? 1f : 0f; if (looping) { offAnim[stopAnimationName].wrapMode = WrapMode.Loop; offAnim.wrapMode = WrapMode.Loop; offAnim[stopAnimationName].speed = animationSpeed; mode = Mode.LoopingAnimation; } else { offAnim[stopAnimationName].wrapMode = WrapMode.Once; mode = Mode.Animation; } } } } else if (node.HasValue("activeColor") && node.HasValue("passiveColor") && node.HasValue("coloredObject")) { if (node.HasValue("colorName")) { colorName = node.GetValue("colorName"); } passiveColor = ConfigNode.ParseColor32(node.GetValue("passiveColor")); activeColor = ConfigNode.ParseColor32(node.GetValue("activeColor")); colorShiftRenderer = thisProp.FindModelComponent <Renderer>(node.GetValue("coloredObject")); colorShiftRenderer.material.SetColor(colorName, reverse ? activeColor : passiveColor); mode = Mode.Color; } else if (node.HasValue("controlledTransform") && node.HasValue("localRotationStart") && node.HasValue("localRotationEnd")) { controlledTransform = thisProp.FindModelTransform(node.GetValue("controlledTransform").Trim()); initialRotation = controlledTransform.localRotation; if (node.HasValue("longPath")) { longPath = true; vectorStart = ConfigNode.ParseVector3(node.GetValue("localRotationStart")); vectorEnd = ConfigNode.ParseVector3(node.GetValue("localRotationEnd")); } else { rotationStart = Quaternion.Euler(ConfigNode.ParseVector3(node.GetValue("localRotationStart"))); rotationEnd = Quaternion.Euler(ConfigNode.ParseVector3(node.GetValue("localRotationEnd"))); } mode = Mode.Rotation; } else if (node.HasValue("controlledTransform") && node.HasValue("localTranslationStart") && node.HasValue("localTranslationEnd")) { controlledTransform = thisProp.FindModelTransform(node.GetValue("controlledTransform").Trim()); initialPosition = controlledTransform.localPosition; vectorStart = ConfigNode.ParseVector3(node.GetValue("localTranslationStart")); vectorEnd = ConfigNode.ParseVector3(node.GetValue("localTranslationEnd")); mode = Mode.Translation; } else if (node.HasValue("controlledTransform") && node.HasValue("localScaleStart") && node.HasValue("localScaleEnd")) { controlledTransform = thisProp.FindModelTransform(node.GetValue("controlledTransform").Trim()); initialScale = controlledTransform.localScale; vectorStart = ConfigNode.ParseVector3(node.GetValue("localScaleStart")); vectorEnd = ConfigNode.ParseVector3(node.GetValue("localScaleEnd")); mode = Mode.Scale; } else if (node.HasValue("controlledTransform") && node.HasValue("textureLayers") && node.HasValue("textureShiftStart") && node.HasValue("textureShiftEnd")) { affectedMaterial = thisProp.FindModelTransform(node.GetValue("controlledTransform").Trim()).renderer.material; textureLayer = node.GetValue("textureLayers"); textureShiftStart = ConfigNode.ParseVector2(node.GetValue("textureShiftStart")); textureShiftEnd = ConfigNode.ParseVector2(node.GetValue("textureShiftEnd")); mode = Mode.TextureShift; } else if (node.HasValue("controlledTransform") && node.HasValue("textureLayers") && node.HasValue("textureScaleStart") && node.HasValue("textureScaleEnd")) { affectedMaterial = thisProp.FindModelTransform(node.GetValue("controlledTransform").Trim()).renderer.material; textureLayer = node.GetValue("textureLayers"); textureScaleStart = ConfigNode.ParseVector2(node.GetValue("textureScaleStart")); textureScaleEnd = ConfigNode.ParseVector2(node.GetValue("textureScaleEnd")); mode = Mode.TextureScale; } else { throw new ArgumentException("Cannot initiate any of the possible action modes."); } if (node.HasValue("threshold")) { threshold = ConfigNode.ParseVector2(node.GetValue("threshold")); } resourceAmount = 0.0f; if (threshold != Vector2.zero) { thresholdMode = true; float min = Mathf.Min(threshold.x, threshold.y); float max = Mathf.Max(threshold.x, threshold.y); threshold.x = min; threshold.y = max; if (node.HasValue("flashingDelay")) { flashingDelay = double.Parse(node.GetValue("flashingDelay")); } if (node.HasValue("alarmSound")) { alarmSoundVolume = 0.5f; if (node.HasValue("alarmSoundVolume")) { alarmSoundVolume = float.Parse(node.GetValue("alarmSoundVolume")); } audioOutput = JUtil.SetupIVASound(thisProp, node.GetValue("alarmSound"), alarmSoundVolume, false); if (node.HasValue("alarmMustPlayOnce")) { if (!bool.TryParse(node.GetValue("alarmMustPlayOnce"), out alarmMustPlayOnce)) { throw new ArgumentException("So is 'alarmMustPlayOnce' true or false?"); } } if (node.HasValue("alarmShutdownButton")) { SmarterButton.CreateButton(thisProp, node.GetValue("alarmShutdownButton"), AlarmShutdown); } if (node.HasValue("alarmSoundLooping")) { if (!bool.TryParse(node.GetValue("alarmSoundLooping"), out alarmSoundLooping)) { throw new ArgumentException("So is 'alarmSoundLooping' true or false?"); } audioOutput.audio.loop = alarmSoundLooping; } } if (node.HasValue("resourceAmount")) { resourceAmount = float.Parse(node.GetValue("resourceAmount")); } TurnOff(); } }
/// <summary> /// Initialize and configure the callback handler. /// </summary> /// <param name="node"></param> /// <param name="variableName"></param> /// <param name="thisProp"></param> public CallbackAnimationSet(ConfigNode node, string variableName, InternalProp thisProp) { currentState = false; if (!node.HasData) { throw new ArgumentException("No data?!"); } string[] tokens = { }; if (node.HasValue("scale")) { tokens = node.GetValue("scale").Split(','); } if (tokens.Length != 2) { throw new ArgumentException("Could not parse 'scale' parameter."); } RasterPropMonitorComputer rpmComp = RasterPropMonitorComputer.Instantiate(thisProp, true); variable = new VariableOrNumberRange(rpmComp, variableName, tokens[0], tokens[1]); // That takes care of the scale, now what to do about that scale: if (node.HasValue("reverse")) { if (!bool.TryParse(node.GetValue("reverse"), out reverse)) { throw new ArgumentException("So is 'reverse' true or false?"); } } if (node.HasValue("flash")) { if(!bool.TryParse(node.GetValue("flash"), out flash)) { throw new ArgumentException("So is 'reverse' true or false?"); } } else { flash = false; } if (node.HasValue("alarmSound")) { alarmSoundVolume = 0.5f; if (node.HasValue("alarmSoundVolume")) { alarmSoundVolume = float.Parse(node.GetValue("alarmSoundVolume")); } audioOutput = JUtil.SetupIVASound(thisProp, node.GetValue("alarmSound"), alarmSoundVolume, false); if (node.HasValue("alarmMustPlayOnce")) { if (!bool.TryParse(node.GetValue("alarmMustPlayOnce"), out alarmMustPlayOnce)) { throw new ArgumentException("So is 'alarmMustPlayOnce' true or false?"); } } if (node.HasValue("alarmShutdownButton")) { SmarterButton.CreateButton(thisProp, node.GetValue("alarmShutdownButton"), AlarmShutdown); } if (node.HasValue("alarmSoundLooping")) { if (!bool.TryParse(node.GetValue("alarmSoundLooping"), out alarmSoundLooping)) { throw new ArgumentException("So is 'alarmSoundLooping' true or false?"); } audioOutput.audio.loop = alarmSoundLooping; } inIVA = (CameraManager.Instance.currentCameraMode == CameraManager.CameraMode.IVA); GameEvents.OnCameraChange.Add(CameraChangeCallback); } if (node.HasValue("animationName")) { animationName = node.GetValue("animationName"); if (node.HasValue("animationSpeed")) { animationSpeed = float.Parse(node.GetValue("animationSpeed")); if (reverse) { animationSpeed = -animationSpeed; } } else { animationSpeed = 0.0f; } Animation[] anims = node.HasValue("animateExterior") ? thisProp.part.FindModelAnimators(animationName) : thisProp.FindModelAnimators(animationName); if (anims.Length > 0) { onAnim = anims[0]; onAnim.enabled = true; onAnim[animationName].speed = 0; onAnim[animationName].normalizedTime = reverse ? 1f : 0f; looping = node.HasValue("loopingAnimation"); if (looping) { onAnim[animationName].wrapMode = WrapMode.Loop; onAnim.wrapMode = WrapMode.Loop; onAnim[animationName].speed = animationSpeed; mode = Mode.LoopingAnimation; } else { onAnim[animationName].wrapMode = WrapMode.Once; mode = Mode.Animation; } onAnim.Play(); //alwaysActive = node.HasValue("animateExterior"); } else { throw new ArgumentException("Animation "+ animationName +" could not be found."); } if (node.HasValue("stopAnimationName")) { stopAnimationName = node.GetValue("stopAnimationName"); anims = node.HasValue("animateExterior") ? thisProp.part.FindModelAnimators(stopAnimationName) : thisProp.FindModelAnimators(stopAnimationName); if (anims.Length > 0) { offAnim = anims[0]; offAnim.enabled = true; offAnim[stopAnimationName].speed = 0; offAnim[stopAnimationName].normalizedTime = reverse ? 1f : 0f; if (looping) { offAnim[stopAnimationName].wrapMode = WrapMode.Loop; offAnim.wrapMode = WrapMode.Loop; offAnim[stopAnimationName].speed = animationSpeed; mode = Mode.LoopingAnimation; } else { offAnim[stopAnimationName].wrapMode = WrapMode.Once; mode = Mode.Animation; } } } } else if (node.HasValue("activeColor") && node.HasValue("passiveColor") && node.HasValue("coloredObject")) { string colorNameString = "_EmissiveColor"; if (node.HasValue("colorName")) { colorNameString = node.GetValue("colorName"); } colorName = Shader.PropertyToID(colorNameString); if (reverse) { activeColor = JUtil.ParseColor32(node.GetValue("passiveColor"), thisProp.part, ref rpmComp); passiveColor = JUtil.ParseColor32(node.GetValue("activeColor"), thisProp.part, ref rpmComp); } else { passiveColor = JUtil.ParseColor32(node.GetValue("passiveColor"), thisProp.part, ref rpmComp); activeColor = JUtil.ParseColor32(node.GetValue("activeColor"), thisProp.part, ref rpmComp); } Renderer colorShiftRenderer = thisProp.FindModelComponent<Renderer>(node.GetValue("coloredObject")); affectedMaterial = colorShiftRenderer.material; affectedMaterial.SetColor(colorName, passiveColor); mode = Mode.Color; } else if (node.HasValue("controlledTransform") && node.HasValue("localRotationStart") && node.HasValue("localRotationEnd")) { controlledTransform = thisProp.FindModelTransform(node.GetValue("controlledTransform").Trim()); initialRotation = controlledTransform.localRotation; if (node.HasValue("longPath")) { longPath = true; if (reverse) { vectorEnd = ConfigNode.ParseVector3(node.GetValue("localRotationStart")); vectorStart = ConfigNode.ParseVector3(node.GetValue("localRotationEnd")); } else { vectorStart = ConfigNode.ParseVector3(node.GetValue("localRotationStart")); vectorEnd = ConfigNode.ParseVector3(node.GetValue("localRotationEnd")); } } else { if (reverse) { rotationEnd = Quaternion.Euler(ConfigNode.ParseVector3(node.GetValue("localRotationStart"))); rotationStart = Quaternion.Euler(ConfigNode.ParseVector3(node.GetValue("localRotationEnd"))); } else { rotationStart = Quaternion.Euler(ConfigNode.ParseVector3(node.GetValue("localRotationStart"))); rotationEnd = Quaternion.Euler(ConfigNode.ParseVector3(node.GetValue("localRotationEnd"))); } } mode = Mode.Rotation; } else if (node.HasValue("controlledTransform") && node.HasValue("localTranslationStart") && node.HasValue("localTranslationEnd")) { controlledTransform = thisProp.FindModelTransform(node.GetValue("controlledTransform").Trim()); initialPosition = controlledTransform.localPosition; if (reverse) { vectorEnd = ConfigNode.ParseVector3(node.GetValue("localTranslationStart")); vectorStart = ConfigNode.ParseVector3(node.GetValue("localTranslationEnd")); } else { vectorStart = ConfigNode.ParseVector3(node.GetValue("localTranslationStart")); vectorEnd = ConfigNode.ParseVector3(node.GetValue("localTranslationEnd")); } mode = Mode.Translation; } else if (node.HasValue("controlledTransform") && node.HasValue("localScaleStart") && node.HasValue("localScaleEnd")) { controlledTransform = thisProp.FindModelTransform(node.GetValue("controlledTransform").Trim()); initialScale = controlledTransform.localScale; if (reverse) { vectorEnd = ConfigNode.ParseVector3(node.GetValue("localScaleStart")); vectorStart = ConfigNode.ParseVector3(node.GetValue("localScaleEnd")); } else { vectorStart = ConfigNode.ParseVector3(node.GetValue("localScaleStart")); vectorEnd = ConfigNode.ParseVector3(node.GetValue("localScaleEnd")); } mode = Mode.Scale; } else if (node.HasValue("controlledTransform") && node.HasValue("textureLayers") && node.HasValue("textureShiftStart") && node.HasValue("textureShiftEnd")) { affectedMaterial = thisProp.FindModelTransform(node.GetValue("controlledTransform").Trim()).GetComponent<Renderer>().material; var textureLayers = node.GetValue("textureLayers").Split(','); for (int i = 0; i < textureLayers.Length; ++i) { textureLayer.Add(textureLayers[i].Trim()); } if (reverse) { textureShiftEnd = ConfigNode.ParseVector2(node.GetValue("textureShiftStart")); textureShiftStart = ConfigNode.ParseVector2(node.GetValue("textureShiftEnd")); } else { textureShiftStart = ConfigNode.ParseVector2(node.GetValue("textureShiftStart")); textureShiftEnd = ConfigNode.ParseVector2(node.GetValue("textureShiftEnd")); } mode = Mode.TextureShift; } else if (node.HasValue("controlledTransform") && node.HasValue("textureLayers") && node.HasValue("textureScaleStart") && node.HasValue("textureScaleEnd")) { affectedMaterial = thisProp.FindModelTransform(node.GetValue("controlledTransform").Trim()).GetComponent<Renderer>().material; var textureLayers = node.GetValue("textureLayers").Split(','); for (int i = 0; i < textureLayers.Length; ++i) { textureLayer.Add(textureLayers[i].Trim()); } if (reverse) { textureScaleEnd = ConfigNode.ParseVector2(node.GetValue("textureScaleStart")); textureScaleStart = ConfigNode.ParseVector2(node.GetValue("textureScaleEnd")); } else { textureScaleStart = ConfigNode.ParseVector2(node.GetValue("textureScaleStart")); textureScaleEnd = ConfigNode.ParseVector2(node.GetValue("textureScaleEnd")); } mode = Mode.TextureScale; } else { throw new ArgumentException("Cannot initiate any of the possible action modes."); } TurnOff(); }
private static SmarterButton AttachBehaviour(InternalProp thatProp, InternalModel thatModel, string buttonName) { if (thatModel == null) { string[] tokens = buttonName.Split('|'); if (tokens.Length == 2) { // First token is the button name, second is the prop ID. int propID; if (int.TryParse(tokens[1], out propID)) { if (propID < thatProp.internalModel.props.Count) { if (propID < 0) { thatModel = thatProp.internalModel; } else { thatProp = thatProp.internalModel.props[propID]; } buttonName = tokens[0].Trim(); } else { Debug.LogError(string.Format("Could not find a prop with ID {0}", propID)); } } } else { buttonName = buttonName.Trim(); } } try { GameObject buttonObject; buttonObject = thatModel == null ? thatProp.FindModelTransform(buttonName).gameObject : thatModel.FindModelTransform(buttonName).gameObject; SmarterButton thatComponent = buttonObject.GetComponent<SmarterButton>() ?? buttonObject.AddComponent<SmarterButton>(); return thatComponent; } catch { Debug.LogError(string.Format( "Could not register a button on transform named '{0}' in {2} named '{1}'. Check your configuration.", buttonName, thatModel == null ? thatProp.propName : thatModel.name, thatModel == null ? "prop" : "internal model")); } return null; }
private static Texture2D LoadFont(object caller, InternalProp thisProp, string location, bool extra) { Texture2D font = null; if (!string.IsNullOrEmpty(location)) { JUtil.LogMessage(caller, "Trying to locate \"{0}\" in GameDatabase...", location); if (GameDatabase.Instance.ExistsTexture(location.EnforceSlashes())) { font = GameDatabase.Instance.GetTexture(location.EnforceSlashes(), false); JUtil.LogMessage(caller, "Loading{1} font texture from URL, \"{0}\"", location, extra ? " extra" : string.Empty); } else { font = (Texture2D)thisProp.FindModelTransform(location).renderer.material.mainTexture; JUtil.LogMessage(caller, "Loading{1} font texture from a transform named, \"{0}\"", location, extra ? " extra" : string.Empty); } } return font; }
internal MASComponentRotation(ConfigNode config, InternalProp prop, MASFlightComputer comp) : base(config, prop, comp) { string transform = string.Empty; if (!config.TryGetValue("transform", ref transform)) { throw new ArgumentException("Missing 'transform' in ROTATION " + name); } this.transform = prop.FindModelTransform(transform); string variableName = string.Empty; if (config.TryGetValue("variable", ref variableName)) { variableName = variableName.Trim(); } Vector3 startRotation = Vector3.zero; if (!config.TryGetValue("startRotation", ref startRotation)) { throw new ArgumentException("Missing 'startRotation' in ROTATION " + name); } Vector3 endRotation = Vector3.zero; bool hasRotationEnd = config.TryGetValue("endRotation", ref endRotation); if (!hasRotationEnd) { endRotation = Vector3.zero; } string range = string.Empty; useLongPath = false; useVeryLongPath = false; if (config.TryGetValue("range", ref range)) { string[] ranges = Utility.SplitVariableList(range); if (ranges.Length != 2) { throw new ArgumentException("Incorrect number of values in 'range' in ROTATION " + name); } variableRegistrar.RegisterVariableChangeCallback(ranges[0], (double newValue) => range1 = (float)newValue); variableRegistrar.RegisterVariableChangeCallback(ranges[1], (double newValue) => range2 = (float)newValue); rangeMode = true; blend = false; config.TryGetValue("blend", ref blend); if (blend) { config.TryGetValue("longPath", ref useLongPath); float modulo = 0.0f; if (config.TryGetValue("modulo", ref modulo) && modulo > 0.0f) { this.modulo = true; this.moduloValue = modulo; } else { this.modulo = false; } float speed = 0.0f; if (config.TryGetValue("speed", ref speed) && speed > 0.0f) { this.comp = comp; this.rateLimited = true; this.speed = speed; } } } else { blend = false; rangeMode = false; } // Final validations if (rangeMode || hasRotationEnd) { if (string.IsNullOrEmpty(variableName)) { throw new ArgumentException("Invalid or missing 'variable' in ROTATION " + name); } } else if (!string.IsNullOrEmpty(variableName)) { if (!hasRotationEnd) { throw new ArgumentException("Missing 'endRotation' in ROTATION " + name); } } // Determine the rotations. this.startRotation = this.transform.localRotation * Quaternion.Euler(startRotation); if (useLongPath) { // Due to the nature of Quaternions, any SLerp we do will always // select the shortest route between two Quaternions. This is great for // rotations that are < 180 degrees, but it's a problem if the rotation is // intended to be > 180 degrees. // As long as the total rotation is < 360, we can get away with a single // midpoint Quaternion and interpolate the result between the two // piece-wise rotations. However, for a full 360* rotation, we have to have // a third point so we can encode a sense of direction. // And, if the configuration requested long path, but our read of the rotation // says it's less than 180 degrees (and thus a candidate for short path), we // quietly 'downgrade' to the slightly cheaper to compute short path. Quaternion mid = Quaternion.Euler(Vector3.Lerp(startRotation, endRotation, 0.5f)); float midAngle = Quaternion.Angle(Quaternion.Euler(startRotation), mid); if (midAngle >= 179.0f) { useVeryLongPath = true; this.midRotation = this.transform.localRotation * Quaternion.Euler(Vector3.Lerp(startRotation, endRotation, 1.0f / 3.0f)); this.mid2Rotation = this.transform.localRotation * Quaternion.Euler(Vector3.Lerp(startRotation, endRotation, 2.0f / 3.0f)); } else if (midAngle >= 89.0f) { this.midRotation = this.transform.localRotation * mid; } else { useLongPath = false; } } this.endRotation = this.transform.localRotation * Quaternion.Euler(endRotation); // Make everything a known value before the callback fires. this.transform.localRotation = this.startRotation; if (string.IsNullOrEmpty(variableName)) { Utility.LogMessage(this, "ROTATION {0} configured as static rotation, with no variable defined", name); } else { variableRegistrar.RegisterVariableChangeCallback(variableName, VariableCallback); } }
private static Texture2D LoadFont(object caller, InternalProp thisProp, string location) { Texture2D font = null; if (!string.IsNullOrEmpty(location)) { if (GameDatabase.Instance.ExistsTexture(location.EnforceSlashes())) { font = GameDatabase.Instance.GetTexture(location.EnforceSlashes(), false); JUtil.LogMessage(caller, "Loading font texture from URL \"{0}\"", location); } else { font = (Texture2D)thisProp.FindModelTransform(location).GetComponent<Renderer>().material.mainTexture; JUtil.LogMessage(caller, "Loading font texture from a transform named \"{0}\"", location); } } return font; }
internal MASComponentTextLabel(ConfigNode config, InternalProp prop, MASFlightComputer comp) : base(config, prop, comp) { string transform = string.Empty; if (!config.TryGetValue("transform", ref transform)) { throw new ArgumentException("Missing 'transform' in TEXT_LABEL " + name); } string fontName = string.Empty; if (!config.TryGetValue("font", ref fontName)) { throw new ArgumentException("Invalid or missing 'font' in TEXT_LABEL " + name); } string styleStr = string.Empty; FontStyle style = FontStyle.Normal; if (config.TryGetValue("style", ref styleStr)) { style = MdVTextMesh.FontStyle(styleStr); } string text = string.Empty; if (!config.TryGetValue("text", ref text)) { throw new ArgumentException("Invalid or missing 'text' in TEXT_LABEL " + name); } if (!config.TryGetValue("fontSize", ref fontSize)) { throw new ArgumentException("Invalid or missing 'fontSize' in TEXT_LABEL " + name); } Vector2 transformOffset = Vector2.zero; if (!config.TryGetValue("transformOffset", ref transformOffset)) { transformOffset = Vector2.zero; } Transform textObjTransform = prop.FindModelTransform(transform); Vector3 localScale = prop.transform.localScale; Transform offsetTransform = new GameObject().transform; offsetTransform.gameObject.name = Utility.ComposeObjectName(this.GetType().Name, name, prop.propID); offsetTransform.gameObject.layer = textObjTransform.gameObject.layer; offsetTransform.SetParent(textObjTransform, false); offsetTransform.Translate(transformOffset.x * localScale.x, transformOffset.y * localScale.y, 0.0f); textObj = offsetTransform.gameObject.AddComponent <MdVTextMesh>(); Font font = MASLoader.GetFont(fontName.Trim()); if (font == null) { throw new ArgumentNullException("Unable to load font " + fontName + " in TEXT_LABEL " + name); } float lineSpacing = 1.0f; if (!config.TryGetValue("lineSpacing", ref lineSpacing)) { lineSpacing = 1.0f; } float sizeScalar = 32.0f / (float)font.fontSize; textObj.SetFont(font, font.fontSize, fontSize * 0.00005f * sizeScalar); textObj.SetLineSpacing(lineSpacing); textObj.fontStyle = style; string passiveColorStr = string.Empty; if (!config.TryGetValue("passiveColor", ref passiveColorStr)) { throw new ArgumentException("Invalid or missing 'passiveColor' in TEXT_LABEL " + name); } else { Color32 namedColor; if (comp.TryGetNamedColor(passiveColorStr, out namedColor)) { passiveColor = namedColor; } else { string[] startColors = Utility.SplitVariableList(passiveColorStr); if (startColors.Length < 3 || startColors.Length > 4) { throw new ArgumentException("passiveColor does not contain 3 or 4 values in TEXT_LABEL " + name); } variableRegistrar.RegisterVariableChangeCallback(startColors[0], (double newValue) => { passiveColor.r = Mathf.Clamp01((float)newValue * (1.0f / 255.0f)); if (blend) { UpdateBlendColor(); } else { UpdateBooleanColor(); } }); variableRegistrar.RegisterVariableChangeCallback(startColors[1], (double newValue) => { passiveColor.g = Mathf.Clamp01((float)newValue * (1.0f / 255.0f)); if (blend) { UpdateBlendColor(); } else { UpdateBooleanColor(); } }); variableRegistrar.RegisterVariableChangeCallback(startColors[2], (double newValue) => { passiveColor.b = Mathf.Clamp01((float)newValue * (1.0f / 255.0f)); if (blend) { UpdateBlendColor(); } else { UpdateBooleanColor(); } }); if (startColors.Length == 4) { variableRegistrar.RegisterVariableChangeCallback(startColors[3], (double newValue) => { passiveColor.a = Mathf.Clamp01((float)newValue * (1.0f / 255.0f)); if (blend) { UpdateBlendColor(); } else { UpdateBooleanColor(); } }); } } } // Final validations bool usesMulticolor = false; string activeColorStr = string.Empty; if (config.TryGetValue("activeColor", ref activeColorStr)) { usesMulticolor = true; Color32 namedColor; if (comp.TryGetNamedColor(activeColorStr, out namedColor)) { activeColor = namedColor; } else { string[] startColors = Utility.SplitVariableList(activeColorStr); if (startColors.Length < 3 || startColors.Length > 4) { throw new ArgumentException("activeColor does not contain 3 or 4 values in TEXT_LABEL " + name); } variableRegistrar.RegisterVariableChangeCallback(startColors[0], (double newValue) => { activeColor.r = Mathf.Clamp01((float)newValue * (1.0f / 255.0f)); if (blend) { UpdateBlendColor(); } else { UpdateBooleanColor(); } }); variableRegistrar.RegisterVariableChangeCallback(startColors[1], (double newValue) => { activeColor.g = Mathf.Clamp01((float)newValue * (1.0f / 255.0f)); if (blend) { UpdateBlendColor(); } else { UpdateBooleanColor(); } }); variableRegistrar.RegisterVariableChangeCallback(startColors[2], (double newValue) => { activeColor.b = Mathf.Clamp01((float)newValue * (1.0f / 255.0f)); if (blend) { UpdateBlendColor(); } else { UpdateBooleanColor(); } }); if (startColors.Length == 4) { variableRegistrar.RegisterVariableChangeCallback(startColors[3], (double newValue) => { activeColor.a = Mathf.Clamp01((float)newValue * (1.0f / 255.0f)); if (blend) { UpdateBlendColor(); } else { UpdateBooleanColor(); } }); } } } string anchor = string.Empty; if (!config.TryGetValue("anchor", ref anchor)) { anchor = string.Empty; } if (!string.IsNullOrEmpty(anchor)) { if (anchor == TextAnchor.LowerCenter.ToString()) { textObj.anchor = TextAnchor.LowerCenter; } else if (anchor == TextAnchor.LowerLeft.ToString()) { textObj.anchor = TextAnchor.LowerLeft; } else if (anchor == TextAnchor.LowerRight.ToString()) { textObj.anchor = TextAnchor.LowerRight; } else if (anchor == TextAnchor.MiddleCenter.ToString()) { textObj.anchor = TextAnchor.MiddleCenter; } else if (anchor == TextAnchor.MiddleLeft.ToString()) { textObj.anchor = TextAnchor.MiddleLeft; } else if (anchor == TextAnchor.MiddleRight.ToString()) { textObj.anchor = TextAnchor.MiddleRight; } else if (anchor == TextAnchor.UpperCenter.ToString()) { textObj.anchor = TextAnchor.UpperCenter; } else if (anchor == TextAnchor.UpperLeft.ToString()) { textObj.anchor = TextAnchor.UpperLeft; } else if (anchor == TextAnchor.UpperRight.ToString()) { textObj.anchor = TextAnchor.UpperRight; } else { Utility.LogError(this, "Unrecognized anchor '{0}' in config for {1} ({2})", anchor, prop.propID, prop.propName); } } string alignment = string.Empty; if (!config.TryGetValue("alignment", ref alignment)) { alignment = string.Empty; } if (!string.IsNullOrEmpty(alignment)) { if (alignment == TextAlignment.Center.ToString()) { textObj.alignment = TextAlignment.Center; } else if (alignment == TextAlignment.Left.ToString()) { textObj.alignment = TextAlignment.Left; } else if (alignment == TextAlignment.Right.ToString()) { textObj.alignment = TextAlignment.Right; } else { Utility.LogError(this, "Unrecognized alignment '{0}' in config for {1} ({2})", alignment, prop.propID, prop.propName); } } string emissive = string.Empty; config.TryGetValue("emissive", ref emissive); if (string.IsNullOrEmpty(emissive)) { if (usesMulticolor) { emissiveMode = EmissiveMode.active; } else { emissiveMode = EmissiveMode.always; } } else if (emissive.ToLower() == EmissiveMode.always.ToString()) { emissiveMode = EmissiveMode.always; } else if (emissive.ToLower() == EmissiveMode.never.ToString()) { emissiveMode = EmissiveMode.never; } else if (emissive.ToLower() == EmissiveMode.active.ToString()) { emissiveMode = EmissiveMode.active; } else if (emissive.ToLower() == EmissiveMode.passive.ToString()) { emissiveMode = EmissiveMode.passive; } else if (emissive.ToLower() == EmissiveMode.flash.ToString()) { emissiveMode = EmissiveMode.flash; } else { Utility.LogError(this, "Unrecognized emissive mode '{0}' in config for {1} ({2})", emissive, prop.propID, prop.propName); emissiveMode = EmissiveMode.always; } string variableName = string.Empty; if (!config.TryGetValue("variable", ref variableName) || string.IsNullOrEmpty(variableName)) { if (usesMulticolor) { throw new ArgumentException("Invalid or missing 'variable' in TEXT_LABEL " + name); } } else if (!usesMulticolor) { throw new ArgumentException("Invalid or missing 'activeColor' in TEXT_LABEL " + name); } config.TryGetValue("blend", ref blend); if (emissiveMode == EmissiveMode.flash) { if (blend == false && config.TryGetValue("flashRate", ref flashRate) && flashRate > 0.0f) { this.comp = comp; comp.RegisterFlashCallback(flashRate, FlashToggle); } else { emissiveMode = EmissiveMode.active; } } bool immutable = false; if (!config.TryGetValue("oneshot", ref immutable)) { immutable = false; } textObj.SetColor(passiveColor); textObj.SetText(text, immutable, false, comp, prop); UpdateShader(); if (!string.IsNullOrEmpty(variableName)) { variableRegistrar.RegisterVariableChangeCallback(variableName, VariableCallback); } }
internal MASComponentColliderEvent(ConfigNode config, InternalProp internalProp, MASFlightComputer comp) : base(config, internalProp, comp) { string collider = string.Empty; if (!config.TryGetValue("collider", ref collider)) { throw new ArgumentException("Missing 'collider' in COLLIDER_EVENT " + name); } string clickEvent = string.Empty, releaseEvent = string.Empty, dragEventX = string.Empty, dragEventY = string.Empty; config.TryGetValue("onClick", ref clickEvent); config.TryGetValue("onRelease", ref releaseEvent); config.TryGetValue("onDragX", ref dragEventX); config.TryGetValue("onDragY", ref dragEventY); if (string.IsNullOrEmpty(clickEvent) && string.IsNullOrEmpty(releaseEvent) && string.IsNullOrEmpty(dragEventX) && string.IsNullOrEmpty(dragEventY)) { throw new ArgumentException("None of 'onClick', 'onRelease', 'onDragX', nor 'onDragY' found in COLLIDER_EVENT " + name); } Transform tr = internalProp.FindModelTransform(collider.Trim()); if (tr == null) { throw new ArgumentException("Unable to find transform '" + collider + "' in prop for COLLIDER_EVENT " + name); } float autoRepeat = 0.0f; if (!config.TryGetValue("autoRepeat", ref autoRepeat)) { autoRepeat = 0.0f; } float volume = -1.0f; if (config.TryGetValue("volume", ref volume)) { volume = Mathf.Clamp01(volume); } else { volume = -1.0f; } string sound = string.Empty; if (!config.TryGetValue("sound", ref sound) || string.IsNullOrEmpty(sound)) { sound = string.Empty; } AudioClip clip = null; if (string.IsNullOrEmpty(sound) == (volume >= 0.0f)) { throw new ArgumentException("Only one of 'sound' or 'volume' found in COLLIDER_EVENT " + name); } if (volume >= 0.0f) { //Try Load audio clip = GameDatabase.Instance.GetAudioClip(sound); if (clip == null) { throw new ArgumentException("Unable to load 'sound' " + sound + " in COLLIDER_EVENT " + name); } } buttonObject = tr.gameObject.AddComponent <ButtonObject>(); buttonObject.parent = this; buttonObject.autoRepeat = (autoRepeat > 0.0f); buttonObject.repeatRate = autoRepeat; string variableName = string.Empty; if (config.TryGetValue("variable", ref variableName)) { variableName = variableName.Trim(); buttonObject.colliderEnabled = false; comp.RegisterVariableChangeCallback(variableName, internalProp, VariableCallback); } if (clip != null) { AudioSource audioSource = tr.gameObject.AddComponent <AudioSource>(); audioSource.clip = clip; audioSource.Stop(); audioSource.volume = GameSettings.SHIP_VOLUME * volume; audioSource.rolloffMode = AudioRolloffMode.Logarithmic; audioSource.maxDistance = 8.0f; audioSource.minDistance = 2.0f; audioSource.dopplerLevel = 0.0f; audioSource.panStereo = 0.0f; audioSource.playOnAwake = false; audioSource.loop = false; audioSource.pitch = 1.0f; buttonObject.audioSource = audioSource; } if (!string.IsNullOrEmpty(clickEvent)) { buttonObject.onClick = comp.GetAction(clickEvent, internalProp); } if (!string.IsNullOrEmpty(releaseEvent)) { buttonObject.onRelease = comp.GetAction(releaseEvent, internalProp); } if (!string.IsNullOrEmpty(dragEventX)) { buttonObject.onDragX = comp.GetDragAction(dragEventX, name, internalProp); if (buttonObject.onDragX != null) { buttonObject.drag = true; float dragSensitivity = 1.0f; if (!config.TryGetValue("dragSensitivity", ref dragSensitivity)) { dragSensitivity = 1.0f; } buttonObject.normalizationScalar = 0.01f * dragSensitivity; } else { throw new ArgumentException("Unable to create 'onDragX' event for COLLIDER_EVENT " + name); } } if (!string.IsNullOrEmpty(dragEventY)) { buttonObject.onDragY = comp.GetDragAction(dragEventY, name, internalProp); if (buttonObject.onDragY != null) { buttonObject.drag = true; float dragSensitivity = 1.0f; if (!config.TryGetValue("dragSensitivity", ref dragSensitivity)) { dragSensitivity = 1.0f; } buttonObject.normalizationScalar = 0.01f * dragSensitivity; } else { throw new ArgumentException("Unable to create 'onDragY' event for COLLIDER_EVENT " + name); } } if (buttonObject.onDragX != null && buttonObject.onDragY != null) { config.TryGetValue("singleAxisDrag", ref buttonObject.singleAxisDrag); } }
internal MASComponentTranslation(ConfigNode config, InternalProp prop, MASFlightComputer comp) : base(config, prop, comp) { string transform = string.Empty; if (!config.TryGetValue("transform", ref transform)) { throw new ArgumentException("Missing 'transform' in TRANSLATION " + name); } this.transform = prop.FindModelTransform(transform); string variableName = string.Empty; if (config.TryGetValue("variable", ref variableName)) { variableName = variableName.Trim(); } startTranslation = Vector3.zero; if (!config.TryGetValue("startTranslation", ref startTranslation)) { throw new ArgumentException("Missing 'startTranslation' in TRANSLATION " + name); } endTranslation = Vector3.zero; bool hasTranslationEnd = config.TryGetValue("endTranslation", ref endTranslation); if (!hasTranslationEnd) { endTranslation = Vector3.zero; } config.TryGetValue("blend", ref blend); if (blend) { float speed = 0.0f; if (config.TryGetValue("speed", ref speed) && speed > 0.0f) { this.comp = comp; this.rateLimited = true; this.speed = speed; } } // Final validations if (blend || hasTranslationEnd) { if (string.IsNullOrEmpty(variableName)) { throw new ArgumentException("Invalid or missing 'variable' in TRANSLATION " + name); } } else if (!string.IsNullOrEmpty(variableName)) { if (!hasTranslationEnd) { throw new ArgumentException("Missing 'endTranslation' in TRANSLATION " + name); } } // Make everything a known value before the callback fires. startTranslation = this.transform.localPosition + startTranslation; endTranslation = this.transform.localPosition + endTranslation; this.transform.localPosition = startTranslation; if (string.IsNullOrEmpty(variableName)) { Utility.LogMessage(this, "TRANSLATION {0} configured as static translation, with no variable defined", name); } else { variableRegistrar.RegisterVariableChangeCallback(variableName, VariableCallback); } }
public CallbackAnimationSet(ConfigNode node, string variableName, InternalProp thisProp) { currentState = false; if (!node.HasData) { throw new ArgumentException("No data?!"); } string[] tokens = { }; if (node.HasValue("scale")) { tokens = node.GetValue("scale").Split(','); } if (tokens.Length != 2) { throw new ArgumentException("Could not parse 'scale' parameter."); } variable = new VariableOrNumberRange(variableName, tokens[0], tokens[1]); // That takes care of the scale, now what to do about that scale: if (node.HasValue("reverse")) { if (!bool.TryParse(node.GetValue("reverse"), out reverse)) { throw new ArgumentException("So is 'reverse' true or false?"); } } if (node.HasValue("animationName")) { animationName = node.GetValue("animationName"); if (node.HasValue("animationSpeed")) { animationSpeed = float.Parse(node.GetValue("animationSpeed")); if (reverse) { animationSpeed = -animationSpeed; } } else { animationSpeed = 0.0f; } Animation[] anims = node.HasValue("animateExterior") ? thisProp.part.FindModelAnimators(animationName) : thisProp.FindModelAnimators(animationName); if (anims.Length > 0) { onAnim = anims[0]; onAnim.enabled = true; onAnim[animationName].speed = 0; onAnim[animationName].normalizedTime = reverse ? 1f : 0f; looping = node.HasValue("loopingAnimation"); if (looping) { onAnim[animationName].wrapMode = WrapMode.Loop; onAnim.wrapMode = WrapMode.Loop; onAnim[animationName].speed = animationSpeed; mode = Mode.LoopingAnimation; } else { onAnim[animationName].wrapMode = WrapMode.Once; mode = Mode.Animation; } onAnim.Play(); //alwaysActive = node.HasValue("animateExterior"); } else { throw new ArgumentException("Animation could not be found."); } if (node.HasValue("stopAnimationName")) { stopAnimationName = node.GetValue("stopAnimationName"); anims = node.HasValue("animateExterior") ? thisProp.part.FindModelAnimators(stopAnimationName) : thisProp.FindModelAnimators(stopAnimationName); if (anims.Length > 0) { offAnim = anims[0]; offAnim.enabled = true; offAnim[stopAnimationName].speed = 0; offAnim[stopAnimationName].normalizedTime = reverse ? 1f : 0f; if (looping) { offAnim[stopAnimationName].wrapMode = WrapMode.Loop; offAnim.wrapMode = WrapMode.Loop; offAnim[stopAnimationName].speed = animationSpeed; mode = Mode.LoopingAnimation; } else { offAnim[stopAnimationName].wrapMode = WrapMode.Once; mode = Mode.Animation; } } } } else if (node.HasValue("activeColor") && node.HasValue("passiveColor") && node.HasValue("coloredObject")) { if (node.HasValue("colorName")) { colorName = node.GetValue("colorName"); } if (reverse) { activeColor = ConfigNode.ParseColor32(node.GetValue("passiveColor")); passiveColor = ConfigNode.ParseColor32(node.GetValue("activeColor")); } else { passiveColor = ConfigNode.ParseColor32(node.GetValue("passiveColor")); activeColor = ConfigNode.ParseColor32(node.GetValue("activeColor")); } Renderer colorShiftRenderer = thisProp.FindModelComponent <Renderer>(node.GetValue("coloredObject")); affectedMaterial = colorShiftRenderer.material; affectedMaterial.SetColor(colorName, passiveColor); mode = Mode.Color; } else if (node.HasValue("controlledTransform") && node.HasValue("localRotationStart") && node.HasValue("localRotationEnd")) { controlledTransform = thisProp.FindModelTransform(node.GetValue("controlledTransform").Trim()); initialRotation = controlledTransform.localRotation; if (node.HasValue("longPath")) { longPath = true; if (reverse) { vectorEnd = ConfigNode.ParseVector3(node.GetValue("localRotationStart")); vectorStart = ConfigNode.ParseVector3(node.GetValue("localRotationEnd")); } else { vectorStart = ConfigNode.ParseVector3(node.GetValue("localRotationStart")); vectorEnd = ConfigNode.ParseVector3(node.GetValue("localRotationEnd")); } } else { if (reverse) { rotationEnd = Quaternion.Euler(ConfigNode.ParseVector3(node.GetValue("localRotationStart"))); rotationStart = Quaternion.Euler(ConfigNode.ParseVector3(node.GetValue("localRotationEnd"))); } else { rotationStart = Quaternion.Euler(ConfigNode.ParseVector3(node.GetValue("localRotationStart"))); rotationEnd = Quaternion.Euler(ConfigNode.ParseVector3(node.GetValue("localRotationEnd"))); } } mode = Mode.Rotation; } else if (node.HasValue("controlledTransform") && node.HasValue("localTranslationStart") && node.HasValue("localTranslationEnd")) { controlledTransform = thisProp.FindModelTransform(node.GetValue("controlledTransform").Trim()); initialPosition = controlledTransform.localPosition; if (reverse) { vectorEnd = ConfigNode.ParseVector3(node.GetValue("localTranslationStart")); vectorStart = ConfigNode.ParseVector3(node.GetValue("localTranslationEnd")); } else { vectorStart = ConfigNode.ParseVector3(node.GetValue("localTranslationStart")); vectorEnd = ConfigNode.ParseVector3(node.GetValue("localTranslationEnd")); } mode = Mode.Translation; } else if (node.HasValue("controlledTransform") && node.HasValue("localScaleStart") && node.HasValue("localScaleEnd")) { controlledTransform = thisProp.FindModelTransform(node.GetValue("controlledTransform").Trim()); initialScale = controlledTransform.localScale; if (reverse) { vectorEnd = ConfigNode.ParseVector3(node.GetValue("localScaleStart")); vectorStart = ConfigNode.ParseVector3(node.GetValue("localScaleEnd")); } else { vectorStart = ConfigNode.ParseVector3(node.GetValue("localScaleStart")); vectorEnd = ConfigNode.ParseVector3(node.GetValue("localScaleEnd")); } mode = Mode.Scale; } else if (node.HasValue("controlledTransform") && node.HasValue("textureLayers") && node.HasValue("textureShiftStart") && node.HasValue("textureShiftEnd")) { affectedMaterial = thisProp.FindModelTransform(node.GetValue("controlledTransform").Trim()).GetComponent <Renderer>().material; var textureLayers = node.GetValue("textureLayers").Split(','); for (int i = 0; i < textureLayers.Length; ++i) { textureLayer.Add(textureLayers[i].Trim()); } if (reverse) { textureShiftEnd = ConfigNode.ParseVector2(node.GetValue("textureShiftStart")); textureShiftStart = ConfigNode.ParseVector2(node.GetValue("textureShiftEnd")); } else { textureShiftStart = ConfigNode.ParseVector2(node.GetValue("textureShiftStart")); textureShiftEnd = ConfigNode.ParseVector2(node.GetValue("textureShiftEnd")); } mode = Mode.TextureShift; } else if (node.HasValue("controlledTransform") && node.HasValue("textureLayers") && node.HasValue("textureScaleStart") && node.HasValue("textureScaleEnd")) { affectedMaterial = thisProp.FindModelTransform(node.GetValue("controlledTransform").Trim()).GetComponent <Renderer>().material; var textureLayers = node.GetValue("textureLayers").Split(','); for (int i = 0; i < textureLayers.Length; ++i) { textureLayer.Add(textureLayers[i].Trim()); } if (reverse) { textureScaleEnd = ConfigNode.ParseVector2(node.GetValue("textureScaleStart")); textureScaleStart = ConfigNode.ParseVector2(node.GetValue("textureScaleEnd")); } else { textureScaleStart = ConfigNode.ParseVector2(node.GetValue("textureScaleStart")); textureScaleEnd = ConfigNode.ParseVector2(node.GetValue("textureScaleEnd")); } mode = Mode.TextureScale; } else { throw new ArgumentException("Cannot initiate any of the possible action modes."); } TurnOff(); }
internal MASComponentTextureShift(ConfigNode config, InternalProp prop, MASFlightComputer comp) : base(config, prop, comp) { string transform = string.Empty; if (!config.TryGetValue("transform", ref transform)) { throw new ArgumentException("Missing 'transform' in TEXTURE_SHIFT " + name); } string layers = "_MainTex"; config.TryGetValue("layers", ref layers); string variableName = string.Empty; if (config.TryGetValue("variable", ref variableName)) { variableName = variableName.Trim(); } config.TryGetValue("blend", ref blend); Transform t = prop.FindModelTransform(transform); Renderer r = t.GetComponent <Renderer>(); localMaterial = r.material; layer = layers.Split(); int layerLength = layer.Length; baseUV = new Vector2[layerLength]; for (int i = 0; i < layerLength; ++i) { layer[i] = layer[i].Trim(); baseUV[i] = localMaterial.GetTextureOffset(layer[i]); } string startUVstring = string.Empty; if (!config.TryGetValue("startUV", ref startUVstring)) { throw new ArgumentException("Missing or invalid 'startUV' in TEXTURE_SHIFT " + name); } else { string[] uvs = Utility.SplitVariableList(startUVstring); if (uvs.Length != 2) { throw new ArgumentException("Incorrect number of values in 'startUV' in TEXTURE_SHIFT " + name); } variableRegistrar.RegisterVariableChangeCallback(uvs[0], (double newValue) => { startUV.x = (float)newValue; UpdateUVs(); }); variableRegistrar.RegisterVariableChangeCallback(uvs[1], (double newValue) => { startUV.y = (float)newValue; UpdateUVs(); }); } // Final validations if (!string.IsNullOrEmpty(variableName)) { string endUVstring = string.Empty; if (string.IsNullOrEmpty(variableName)) { throw new ArgumentException("Invalid or missing 'variable' in TEXTURE_SHIFT " + name); } else if (!config.TryGetValue("endUV", ref endUVstring)) { throw new ArgumentException("Invalid or missing 'endUV' in TEXTURE_SHIFT " + name); } else { string[] uvs = Utility.SplitVariableList(endUVstring); if (uvs.Length != 2) { throw new ArgumentException("Incorrect number of values in 'endUV' in TEXTURE_SHIFT " + name); } variableRegistrar.RegisterVariableChangeCallback(uvs[0], (double newValue) => { endUV.x = (float)newValue; UpdateUVs(); }); variableRegistrar.RegisterVariableChangeCallback(uvs[1], (double newValue) => { endUV.y = (float)newValue; UpdateUVs(); }); } } if (!string.IsNullOrEmpty(variableName)) { variableRegistrar.RegisterVariableChangeCallback(variableName, VariableCallback); } }
public VariableAnimationSet(ConfigNode node, InternalProp thisProp, RasterPropMonitorComputer rpmComp, JSIVariableAnimator parent) { varAnim = parent; onChangeDelegate = (Action<float>)Delegate.CreateDelegate(typeof(Action<float>), this, "OnChange"); part = thisProp.part; if (!node.HasData) { throw new ArgumentException("No data?!"); } string[] tokens = { }; if (node.HasValue("scale")) { tokens = node.GetValue("scale").Split(','); } if (tokens.Length != 2) { throw new ArgumentException("Could not parse 'scale' parameter."); } string variableName = string.Empty; if (node.HasValue("variableName")) { variableName = node.GetValue("variableName").Trim(); } else if (node.HasValue("stateMethod")) { string stateMethod = node.GetValue("stateMethod").Trim(); // Verify the state method actually exists Func<bool> stateFunction = (Func<bool>)rpmComp.GetMethod(stateMethod, thisProp, typeof(Func<bool>)); if (stateFunction != null) { variableName = "PLUGIN_" + stateMethod; } else { throw new ArgumentException("Unrecognized stateMethod"); } } else { throw new ArgumentException("Missing variable name."); } if (node.HasValue("modulo")) { variable = new VariableOrNumberRange(rpmComp, variableName, tokens[0], tokens[1], node.GetValue("modulo")); usesModulo = true; } else { variable = new VariableOrNumberRange(rpmComp, variableName, tokens[0], tokens[1]); usesModulo = false; } // That takes care of the scale, now what to do about that scale: if (node.HasValue("reverse")) { if (!bool.TryParse(node.GetValue("reverse"), out reverse)) { throw new ArgumentException("So is 'reverse' true or false?"); } } if (node.HasValue("animationName")) { animationName = node.GetValue("animationName"); if (node.HasValue("animationSpeed")) { animationSpeed = float.Parse(node.GetValue("animationSpeed")); if (reverse) { animationSpeed = -animationSpeed; } } else { animationSpeed = 0.0f; } Animation[] anims = node.HasValue("animateExterior") ? thisProp.part.FindModelAnimators(animationName) : thisProp.FindModelAnimators(animationName); if (anims.Length > 0) { onAnim = anims[0]; onAnim.enabled = true; onAnim[animationName].speed = 0; onAnim[animationName].normalizedTime = reverse ? 1f : 0f; looping = node.HasValue("loopingAnimation"); if (looping) { onAnim[animationName].wrapMode = WrapMode.Loop; onAnim.wrapMode = WrapMode.Loop; onAnim[animationName].speed = animationSpeed; mode = Mode.LoopingAnimation; } else { onAnim[animationName].wrapMode = WrapMode.Once; mode = Mode.Animation; } onAnim.Play(); alwaysActive = node.HasValue("animateExterior"); } else { throw new ArgumentException("Animation could not be found."); } if (node.HasValue("stopAnimationName")) { stopAnimationName = node.GetValue("stopAnimationName"); anims = node.HasValue("animateExterior") ? thisProp.part.FindModelAnimators(stopAnimationName) : thisProp.FindModelAnimators(stopAnimationName); if (anims.Length > 0) { offAnim = anims[0]; offAnim.enabled = true; offAnim[stopAnimationName].speed = 0; offAnim[stopAnimationName].normalizedTime = reverse ? 1f : 0f; if (looping) { offAnim[stopAnimationName].wrapMode = WrapMode.Loop; offAnim.wrapMode = WrapMode.Loop; offAnim[stopAnimationName].speed = animationSpeed; mode = Mode.LoopingAnimation; } else { offAnim[stopAnimationName].wrapMode = WrapMode.Once; mode = Mode.Animation; } } } } else if (node.HasValue("activeColor") && node.HasValue("passiveColor") && node.HasValue("coloredObject")) { string colorNameString = "_EmissiveColor"; if (node.HasValue("colorName")) { colorNameString = node.GetValue("colorName"); } colorName = Shader.PropertyToID(colorNameString); if (reverse) { activeColor = JUtil.ParseColor32(node.GetValue("passiveColor"), thisProp.part, ref rpmComp); passiveColor = JUtil.ParseColor32(node.GetValue("activeColor"), thisProp.part, ref rpmComp); } else { passiveColor = JUtil.ParseColor32(node.GetValue("passiveColor"), thisProp.part, ref rpmComp); activeColor = JUtil.ParseColor32(node.GetValue("activeColor"), thisProp.part, ref rpmComp); } Renderer colorShiftRenderer = thisProp.FindModelComponent<Renderer>(node.GetValue("coloredObject")); affectedMaterial = colorShiftRenderer.material; affectedMaterial.SetColor(colorName, passiveColor); mode = Mode.Color; } else if (node.HasValue("controlledTransform") && node.HasValue("localRotationStart") && node.HasValue("localRotationEnd")) { controlledTransform = thisProp.FindModelTransform(node.GetValue("controlledTransform").Trim()); initialRotation = controlledTransform.localRotation; if (node.HasValue("longPath")) { longPath = true; if (reverse) { vectorEnd = ConfigNode.ParseVector3(node.GetValue("localRotationStart")); vectorStart = ConfigNode.ParseVector3(node.GetValue("localRotationEnd")); } else { vectorStart = ConfigNode.ParseVector3(node.GetValue("localRotationStart")); vectorEnd = ConfigNode.ParseVector3(node.GetValue("localRotationEnd")); } } else { if (reverse) { rotationEnd = Quaternion.Euler(ConfigNode.ParseVector3(node.GetValue("localRotationStart"))); rotationStart = Quaternion.Euler(ConfigNode.ParseVector3(node.GetValue("localRotationEnd"))); } else { rotationStart = Quaternion.Euler(ConfigNode.ParseVector3(node.GetValue("localRotationStart"))); rotationEnd = Quaternion.Euler(ConfigNode.ParseVector3(node.GetValue("localRotationEnd"))); } } mode = Mode.Rotation; } else if (node.HasValue("controlledTransform") && node.HasValue("localTranslationStart") && node.HasValue("localTranslationEnd")) { controlledTransform = thisProp.FindModelTransform(node.GetValue("controlledTransform").Trim()); initialPosition = controlledTransform.localPosition; if (reverse) { vectorEnd = ConfigNode.ParseVector3(node.GetValue("localTranslationStart")); vectorStart = ConfigNode.ParseVector3(node.GetValue("localTranslationEnd")); } else { vectorStart = ConfigNode.ParseVector3(node.GetValue("localTranslationStart")); vectorEnd = ConfigNode.ParseVector3(node.GetValue("localTranslationEnd")); } mode = Mode.Translation; } else if (node.HasValue("controlledTransform") && node.HasValue("localScaleStart") && node.HasValue("localScaleEnd")) { controlledTransform = thisProp.FindModelTransform(node.GetValue("controlledTransform").Trim()); initialScale = controlledTransform.localScale; if (reverse) { vectorEnd = ConfigNode.ParseVector3(node.GetValue("localScaleStart")); vectorStart = ConfigNode.ParseVector3(node.GetValue("localScaleEnd")); } else { vectorStart = ConfigNode.ParseVector3(node.GetValue("localScaleStart")); vectorEnd = ConfigNode.ParseVector3(node.GetValue("localScaleEnd")); } mode = Mode.Scale; } else if (node.HasValue("controlledTransform") && node.HasValue("textureLayers") && node.HasValue("textureShiftStart") && node.HasValue("textureShiftEnd")) { affectedMaterial = thisProp.FindModelTransform(node.GetValue("controlledTransform").Trim()).GetComponent<Renderer>().material; var textureLayers = node.GetValue("textureLayers").Split(','); for (int i = 0; i < textureLayers.Length; ++i) { textureLayer.Add(textureLayers[i].Trim()); } if (reverse) { textureShiftEnd = ConfigNode.ParseVector2(node.GetValue("textureShiftStart")); textureShiftStart = ConfigNode.ParseVector2(node.GetValue("textureShiftEnd")); } else { textureShiftStart = ConfigNode.ParseVector2(node.GetValue("textureShiftStart")); textureShiftEnd = ConfigNode.ParseVector2(node.GetValue("textureShiftEnd")); } mode = Mode.TextureShift; } else if (node.HasValue("controlledTransform") && node.HasValue("textureLayers") && node.HasValue("textureScaleStart") && node.HasValue("textureScaleEnd")) { affectedMaterial = thisProp.FindModelTransform(node.GetValue("controlledTransform").Trim()).GetComponent<Renderer>().material; var textureLayers = node.GetValue("textureLayers").Split(','); for (int i = 0; i < textureLayers.Length; ++i) { textureLayer.Add(textureLayers[i].Trim()); } if (reverse) { textureScaleEnd = ConfigNode.ParseVector2(node.GetValue("textureScaleStart")); textureScaleStart = ConfigNode.ParseVector2(node.GetValue("textureScaleEnd")); } else { textureScaleStart = ConfigNode.ParseVector2(node.GetValue("textureScaleStart")); textureScaleEnd = ConfigNode.ParseVector2(node.GetValue("textureScaleEnd")); } mode = Mode.TextureScale; } else { throw new ArgumentException("Cannot initiate any of the possible action modes."); } if (!(node.HasValue("maxRateChange") && float.TryParse(node.GetValue("maxRateChange"), out maxRateChange))) { maxRateChange = 0.0f; } if (maxRateChange >= 60.0f) { // Animation rate is too fast to even notice @60Hz maxRateChange = 0.0f; } else { lastAnimUpdate = Planetarium.GetUniversalTime(); } if (node.HasValue("threshold")) { threshold = ConfigNode.ParseVector2(node.GetValue("threshold")); } resourceAmount = 0.0f; if (threshold != Vector2.zero) { thresholdMode = true; float min = Mathf.Min(threshold.x, threshold.y); float max = Mathf.Max(threshold.x, threshold.y); threshold.x = min; threshold.y = max; if (node.HasValue("flashingDelay")) { flashingDelay = double.Parse(node.GetValue("flashingDelay")); } if (node.HasValue("alarmSound")) { alarmSoundVolume = 0.5f; if (node.HasValue("alarmSoundVolume")) { alarmSoundVolume = float.Parse(node.GetValue("alarmSoundVolume")); } audioOutput = JUtil.SetupIVASound(thisProp, node.GetValue("alarmSound"), alarmSoundVolume, false); if (node.HasValue("alarmMustPlayOnce")) { if (!bool.TryParse(node.GetValue("alarmMustPlayOnce"), out alarmMustPlayOnce)) { throw new ArgumentException("So is 'alarmMustPlayOnce' true or false?"); } } if (node.HasValue("alarmShutdownButton")) { SmarterButton.CreateButton(thisProp, node.GetValue("alarmShutdownButton"), AlarmShutdown); } if (node.HasValue("alarmSoundLooping")) { if (!bool.TryParse(node.GetValue("alarmSoundLooping"), out alarmSoundLooping)) { throw new ArgumentException("So is 'alarmSoundLooping' true or false?"); } audioOutput.audio.loop = alarmSoundLooping; } inIVA = (CameraManager.Instance.currentCameraMode == CameraManager.CameraMode.IVA); GameEvents.OnCameraChange.Add(OnCameraChange); } if (node.HasValue("resourceAmount")) { resourceAmount = float.Parse(node.GetValue("resourceAmount")); if (node.HasValue("resourceName")) { resourceName = node.GetValue("resourceName"); } else { resourceName = "ElectricCharge"; } } TurnOff(Planetarium.GetUniversalTime()); } rpmComp.RegisterVariableCallback(variable.variableName, onChangeDelegate); }
/// <summary> /// Initialize and configure the callback handler. /// </summary> /// <param name="node"></param> /// <param name="variableName"></param> /// <param name="thisProp"></param> public CallbackAnimationSet(ConfigNode node, string variableName, InternalProp thisProp) { currentState = false; if (!node.HasData) { throw new ArgumentException("No data?!"); } string[] tokens = { }; if (node.HasValue("scale")) { tokens = node.GetValue("scale").Split(','); } if (tokens.Length != 2) { throw new ArgumentException("Could not parse 'scale' parameter."); } RasterPropMonitorComputer rpmComp = RasterPropMonitorComputer.Instantiate(thisProp, true); variable = new VariableOrNumberRange(rpmComp, variableName, tokens[0], tokens[1]); // That takes care of the scale, now what to do about that scale: if (node.HasValue("reverse")) { if (!bool.TryParse(node.GetValue("reverse"), out reverse)) { throw new ArgumentException("So is 'reverse' true or false?"); } } if (node.HasValue("flash")) { if (!bool.TryParse(node.GetValue("flash"), out flash)) { throw new ArgumentException("So is 'reverse' true or false?"); } } else { flash = false; } if (node.HasValue("alarmSound")) { alarmSoundVolume = 0.5f; if (node.HasValue("alarmSoundVolume")) { alarmSoundVolume = float.Parse(node.GetValue("alarmSoundVolume")); } audioOutput = JUtil.SetupIVASound(thisProp, node.GetValue("alarmSound"), alarmSoundVolume, false); if (node.HasValue("alarmMustPlayOnce")) { if (!bool.TryParse(node.GetValue("alarmMustPlayOnce"), out alarmMustPlayOnce)) { throw new ArgumentException("So is 'alarmMustPlayOnce' true or false?"); } } if (node.HasValue("alarmShutdownButton")) { SmarterButton.CreateButton(thisProp, node.GetValue("alarmShutdownButton"), AlarmShutdown); } if (node.HasValue("alarmSoundLooping")) { if (!bool.TryParse(node.GetValue("alarmSoundLooping"), out alarmSoundLooping)) { throw new ArgumentException("So is 'alarmSoundLooping' true or false?"); } audioOutput.audio.loop = alarmSoundLooping; } inIVA = (CameraManager.Instance.currentCameraMode == CameraManager.CameraMode.IVA); GameEvents.OnCameraChange.Add(CameraChangeCallback); } if (node.HasValue("animationName")) { animationName = node.GetValue("animationName"); if (node.HasValue("animationSpeed")) { animationSpeed = float.Parse(node.GetValue("animationSpeed")); if (reverse) { animationSpeed = -animationSpeed; } } else { animationSpeed = 0.0f; } Animation[] anims = node.HasValue("animateExterior") ? thisProp.part.FindModelAnimators(animationName) : thisProp.FindModelAnimators(animationName); if (anims.Length > 0) { onAnim = anims[0]; onAnim.enabled = true; onAnim[animationName].speed = 0; onAnim[animationName].normalizedTime = reverse ? 1f : 0f; looping = node.HasValue("loopingAnimation"); if (looping) { onAnim[animationName].wrapMode = WrapMode.Loop; onAnim.wrapMode = WrapMode.Loop; onAnim[animationName].speed = animationSpeed; mode = Mode.LoopingAnimation; } else { onAnim[animationName].wrapMode = WrapMode.Once; mode = Mode.Animation; } onAnim.Play(); //alwaysActive = node.HasValue("animateExterior"); } else { throw new ArgumentException("Animation " + animationName + " could not be found."); } if (node.HasValue("stopAnimationName")) { stopAnimationName = node.GetValue("stopAnimationName"); anims = node.HasValue("animateExterior") ? thisProp.part.FindModelAnimators(stopAnimationName) : thisProp.FindModelAnimators(stopAnimationName); if (anims.Length > 0) { offAnim = anims[0]; offAnim.enabled = true; offAnim[stopAnimationName].speed = 0; offAnim[stopAnimationName].normalizedTime = reverse ? 1f : 0f; if (looping) { offAnim[stopAnimationName].wrapMode = WrapMode.Loop; offAnim.wrapMode = WrapMode.Loop; offAnim[stopAnimationName].speed = animationSpeed; mode = Mode.LoopingAnimation; } else { offAnim[stopAnimationName].wrapMode = WrapMode.Once; mode = Mode.Animation; } } } } else if (node.HasValue("activeColor") && node.HasValue("passiveColor") && node.HasValue("coloredObject")) { string colorNameString = "_EmissiveColor"; if (node.HasValue("colorName")) { colorNameString = node.GetValue("colorName"); } colorName = Shader.PropertyToID(colorNameString); if (reverse) { activeColor = JUtil.ParseColor32(node.GetValue("passiveColor"), thisProp.part, ref rpmComp); passiveColor = JUtil.ParseColor32(node.GetValue("activeColor"), thisProp.part, ref rpmComp); } else { passiveColor = JUtil.ParseColor32(node.GetValue("passiveColor"), thisProp.part, ref rpmComp); activeColor = JUtil.ParseColor32(node.GetValue("activeColor"), thisProp.part, ref rpmComp); } Renderer colorShiftRenderer = thisProp.FindModelComponent <Renderer>(node.GetValue("coloredObject")); affectedMaterial = colorShiftRenderer.material; affectedMaterial.SetColor(colorName, passiveColor); mode = Mode.Color; } else if (node.HasValue("controlledTransform") && node.HasValue("localRotationStart") && node.HasValue("localRotationEnd")) { controlledTransform = thisProp.FindModelTransform(node.GetValue("controlledTransform").Trim()); initialRotation = controlledTransform.localRotation; if (node.HasValue("longPath")) { longPath = true; if (reverse) { vectorEnd = ConfigNode.ParseVector3(node.GetValue("localRotationStart")); vectorStart = ConfigNode.ParseVector3(node.GetValue("localRotationEnd")); } else { vectorStart = ConfigNode.ParseVector3(node.GetValue("localRotationStart")); vectorEnd = ConfigNode.ParseVector3(node.GetValue("localRotationEnd")); } } else { if (reverse) { rotationEnd = Quaternion.Euler(ConfigNode.ParseVector3(node.GetValue("localRotationStart"))); rotationStart = Quaternion.Euler(ConfigNode.ParseVector3(node.GetValue("localRotationEnd"))); } else { rotationStart = Quaternion.Euler(ConfigNode.ParseVector3(node.GetValue("localRotationStart"))); rotationEnd = Quaternion.Euler(ConfigNode.ParseVector3(node.GetValue("localRotationEnd"))); } } mode = Mode.Rotation; } else if (node.HasValue("controlledTransform") && node.HasValue("localTranslationStart") && node.HasValue("localTranslationEnd")) { controlledTransform = thisProp.FindModelTransform(node.GetValue("controlledTransform").Trim()); initialPosition = controlledTransform.localPosition; if (reverse) { vectorEnd = ConfigNode.ParseVector3(node.GetValue("localTranslationStart")); vectorStart = ConfigNode.ParseVector3(node.GetValue("localTranslationEnd")); } else { vectorStart = ConfigNode.ParseVector3(node.GetValue("localTranslationStart")); vectorEnd = ConfigNode.ParseVector3(node.GetValue("localTranslationEnd")); } mode = Mode.Translation; } else if (node.HasValue("controlledTransform") && node.HasValue("localScaleStart") && node.HasValue("localScaleEnd")) { controlledTransform = thisProp.FindModelTransform(node.GetValue("controlledTransform").Trim()); initialScale = controlledTransform.localScale; if (reverse) { vectorEnd = ConfigNode.ParseVector3(node.GetValue("localScaleStart")); vectorStart = ConfigNode.ParseVector3(node.GetValue("localScaleEnd")); } else { vectorStart = ConfigNode.ParseVector3(node.GetValue("localScaleStart")); vectorEnd = ConfigNode.ParseVector3(node.GetValue("localScaleEnd")); } mode = Mode.Scale; } else if (node.HasValue("controlledTransform") && node.HasValue("textureLayers") && node.HasValue("textureShiftStart") && node.HasValue("textureShiftEnd")) { affectedMaterial = thisProp.FindModelTransform(node.GetValue("controlledTransform").Trim()).GetComponent <Renderer>().material; var textureLayers = node.GetValue("textureLayers").Split(','); for (int i = 0; i < textureLayers.Length; ++i) { textureLayer.Add(textureLayers[i].Trim()); } if (reverse) { textureShiftEnd = ConfigNode.ParseVector2(node.GetValue("textureShiftStart")); textureShiftStart = ConfigNode.ParseVector2(node.GetValue("textureShiftEnd")); } else { textureShiftStart = ConfigNode.ParseVector2(node.GetValue("textureShiftStart")); textureShiftEnd = ConfigNode.ParseVector2(node.GetValue("textureShiftEnd")); } mode = Mode.TextureShift; } else if (node.HasValue("controlledTransform") && node.HasValue("textureLayers") && node.HasValue("textureScaleStart") && node.HasValue("textureScaleEnd")) { affectedMaterial = thisProp.FindModelTransform(node.GetValue("controlledTransform").Trim()).GetComponent <Renderer>().material; var textureLayers = node.GetValue("textureLayers").Split(','); for (int i = 0; i < textureLayers.Length; ++i) { textureLayer.Add(textureLayers[i].Trim()); } if (reverse) { textureScaleEnd = ConfigNode.ParseVector2(node.GetValue("textureScaleStart")); textureScaleStart = ConfigNode.ParseVector2(node.GetValue("textureScaleEnd")); } else { textureScaleStart = ConfigNode.ParseVector2(node.GetValue("textureScaleStart")); textureScaleEnd = ConfigNode.ParseVector2(node.GetValue("textureScaleEnd")); } mode = Mode.TextureScale; } else { throw new ArgumentException("Cannot initiate any of the possible action modes."); } TurnOff(); }