//构造函数 public static InfoGauge ReadNode(ConfigNode node) { InfoGauge gauge = new InfoGauge(); gauge.Texture = node.GetValue("Texture"); gauge.Position = ConfigNode.ParseVector4(node.GetValue("Position")); gauge.Limit = ConfigNode.ParseVector2(node.GetValue("Limit")); gauge.TextureLimit = ConfigNode.ParseVector2(node.GetValue("TextureLimit")); gauge.TextureSize = float.Parse(node.GetValue("TextureSize")); gauge.Variable = node.GetValue("Variable"); gauge.VerticalMovement = bool.Parse(node.GetValue("VerticalMovement")); gauge.UseLog10 = bool.Parse(node.GetValue("UseLog10")); gauge.Use360Horizon = bool.Parse(node.GetValue("Use360horizon")); gauge.RotateWithVessel = bool.Parse(node.GetValue("RotateWithVessel")); return(gauge); }
public void Start() { if (HighLogic.LoadedSceneIsEditor) { return; } try { backgroundColorValue = ConfigNode.ParseColor32(backgroundColor); foreach (ConfigNode propNode in GameDatabase.Instance.GetConfigNodes("PROP")) { ConfigNode[] moduleNodes = propNode.GetNodes("MODULE"); foreach (ConfigNode moduleNode in moduleNodes) { ConfigNode[] pageNodes = moduleNode.GetNodes("PAGE"); foreach (ConfigNode pagenode in pageNodes) { ConfigNode[] bghandlerNodes = pagenode.GetNodes("BACKGROUNDHANDLER"); foreach (ConfigNode bghandlerNode in bghandlerNodes) { ConfigNode[] gaugeNodes = bghandlerNode.GetNodes("GAUGE"); foreach (ConfigNode node in gaugeNodes) { InfoGauge gauge = new InfoGauge(); JUtil.LogErrorMessage(this, "one item created"); gauge.Texture = node.GetValue("Texture"); JUtil.LogErrorMessage(this, "texture obtained"); gauge.Position = ConfigNode.ParseVector4(node.GetValue("Position")); JUtil.LogErrorMessage(this, "position obtained"); gauge.Limit = ConfigNode.ParseVector2(node.GetValue("Limit")); JUtil.LogErrorMessage(this, "limit obtained"); gauge.TextureLimit = ConfigNode.ParseVector4(node.GetValue("TextureLimit")); JUtil.LogErrorMessage(this, "texlim obtained"); gauge.TextureSize = float.Parse(node.GetValue("TextureSize")); JUtil.LogErrorMessage(this, "texsiz obtained"); gauge.VerticalMovement = bool.Parse(node.GetValue("VerticalMovement")); JUtil.LogErrorMessage(this, "vertmov obtained"); gauge.UseLog10 = bool.Parse(node.GetValue("UseLog10")); JUtil.LogErrorMessage(this, "uselog obtained"); gauge.Use360Horizon = bool.Parse(node.GetValue("Use360Horizon")); JUtil.LogErrorMessage(this, "360 obtained"); gauge.RotateWithVessel = bool.Parse(node.GetValue("RotateWithVessel")); JUtil.LogErrorMessage(this, "rotate obtained"); gauge.Variable = node.GetValue("Variable"); JUtil.LogErrorMessage(this, "variable obtained"); gaugeList.Add(gauge); JUtil.LogErrorMessage(this, "one item added"); } } } } } Shader unlit = Shader.Find("Hidden/Internal-GUITexture"); foreach (InfoGauge gauge in gaugeList) { if (!String.IsNullOrEmpty(gauge.Texture)) { gauge.Material = new Material(unlit); gauge.Material.color = new Color(0.0f, 0.0f, 0.0f, 0.0f); gauge.Material.mainTexture = GameDatabase.Instance.GetTexture(gauge.Texture.EnforceSlashes(), false); } if (gauge.Material.mainTexture != null) { float height = (float)gauge.Material.mainTexture.height; float width = (float)gauge.Material.mainTexture.width; gauge.TextureLimit.x = 1.0f - (gauge.TextureLimit.x / width); gauge.TextureLimit.y = 1.0f - (gauge.TextureLimit.y / width); gauge.TextureLimit.z = 1.0f - (gauge.TextureLimit.z / height); gauge.TextureLimit.w = 1.0f - (gauge.TextureLimit.w / height); gauge.TextureSize = 0.5f * (gauge.TextureSize / height);//实际调用的时候用的是宽和高的一半。 if (gauge.Use360Horizon) { gauge.Material.mainTexture.wrapMode = TextureWrapMode.Repeat; } else { gauge.Material.mainTexture.wrapMode = TextureWrapMode.Clamp; } } if (gauge.UseLog10) { gauge.Limit.x = JUtil.PseudoLog10(gauge.Limit.x); gauge.Limit.y = JUtil.PseudoLog10(gauge.Limit.y); } } JUtil.LogMessage(this, "material read"); comp = RasterPropMonitorComputer.Instantiate(internalProp); startupComplete = true; } catch { JUtil.AnnoyUser(this); throw; } }