public void Start()
        {
            if (HighLogic.LoadedSceneIsEditor)
            {
                return;
            }

            if (string.IsNullOrEmpty(cameraTransform))
            {
                // Nothing to do if there're no camera transforms.
                return;
            }

            string[] cameraTransformList = cameraTransform.Split('|');

            // I'm sure this and the loop can be done a little differently to
            // make it clearer, but this works.
            string[] fovLimitsList   = (string.IsNullOrEmpty(fovLimits)) ? null : fovLimits.Split('|');
            string[] yawLimitsList   = (string.IsNullOrEmpty(yawLimits)) ? null : yawLimits.Split('|');
            string[] pitchLimitsList = (string.IsNullOrEmpty(pitchLimits)) ? null : pitchLimits.Split('|');
            string[] zoomRateList    = (string.IsNullOrEmpty(zoomRate)) ? null : zoomRate.Split('|');
            string[] yawRateList     = (string.IsNullOrEmpty(yawRate)) ? null : yawRate.Split('|');
            string[] pitchRateList   = (string.IsNullOrEmpty(pitchRate)) ? null : pitchRate.Split('|');

            // cameraTransformList controls the number of cameras instantiated.
            // Every other value has a default, so if it's not specified, we
            // will use that default.
            for (int i = 0; i < cameraTransformList.Length; ++i)
            {
                Vector2 thisFovLimit   = (fovLimitsList != null && i < fovLimitsList.Length) ? (Vector2)ConfigNode.ParseVector2(fovLimitsList[i]) : defaultFovLimits;
                Vector2 thisYawLimit   = (yawLimitsList != null && i < yawLimitsList.Length) ? (Vector2)ConfigNode.ParseVector2(yawLimitsList[i]) : defaultYawLimits;
                Vector2 thisPitchLimit = (pitchLimitsList != null && i < pitchLimitsList.Length) ? (Vector2)ConfigNode.ParseVector2(pitchLimitsList[i]) : defaultPitchLimits;
                float   thisZoomRate   = (zoomRateList != null && i < zoomRateList.Length) ? JUtil.GetFloat(zoomRateList[i]) ?? 0.0f : 0.0f;
                float   thisYawRate    = (yawRateList != null && i < yawRateList.Length) ? JUtil.GetFloat(yawRateList[i]) ?? 0.0f : 0.0f;
                float   thisPitchRate  = (pitchRateList != null && i < pitchRateList.Length) ? JUtil.GetFloat(pitchRateList[i]) ?? 0.0f : 0.0f;

                var thatCamera = new SteerableCameraParameters(cameraTransformList[i],
                                                               thisFovLimit, thisYawLimit, thisPitchLimit,
                                                               thisZoomRate, thisYawRate, thisPitchRate);
                cameras.Add(thatCamera);
            }

            gizmoTexture = JUtil.GetGizmoTexture();

            iconMaterial = new Material(Shader.Find("KSP/Alpha/Unlit Transparent"));

            // MOARdV: The maneuver gizmo texture is white. Unity's DrawTexture
            // expects a (0.5, 0.5, 0.5, 0.5) texture to be neutral for coloring
            // purposes.  Multiplying the desired alpha by 1/2 gets around the
            // gizmo texture's color, and gets correct alpha effects.
            Color32 iconColor = ConfigNode.ParseColor32(targetIconColor);

            iconColor.a       /= 2;
            iconMaterial.color = iconColor;

            homeCrosshairMaterial       = new Material(Shader.Find("KSP/Alpha/Unlit Transparent"));
            homeCrosshairMaterial.color = ConfigNode.ParseColor32(homeCrosshairColor);
        }
        public void Start()
        {
            if (HighLogic.LoadedSceneIsEditor)
            {
                return;
            }

            try {
                // Parse bloody KSPField colors.
                if (!string.IsNullOrEmpty(backgroundColor))
                {
                    backgroundColorValue = ConfigNode.ParseColor32(backgroundColor);
                }
                if (!string.IsNullOrEmpty(ballColor))
                {
                    ballColorValue = ConfigNode.ParseColor32(ballColor);
                }
                if (!string.IsNullOrEmpty(progradeColor))
                {
                    progradeColorValue = ConfigNode.ParseColor32(progradeColor);
                }
                if (!string.IsNullOrEmpty(maneuverColor))
                {
                    maneuverColorValue = ConfigNode.ParseColor32(maneuverColor);
                }
                if (!string.IsNullOrEmpty(targetColor))
                {
                    targetColorValue = ConfigNode.ParseColor32(targetColor);
                }
                if (!string.IsNullOrEmpty(normalColor))
                {
                    normalColorValue = ConfigNode.ParseColor32(normalColor);
                }
                if (!string.IsNullOrEmpty(radialColor))
                {
                    radialColorValue = ConfigNode.ParseColor32(radialColor);
                }
                if (!string.IsNullOrEmpty(dockingColor))
                {
                    dockingColorValue = ConfigNode.ParseColor32(dockingColor);
                }

                Shader unlit = Shader.Find("KSP/Alpha/Unlit Transparent");
                overlayMaterial             = new Material(unlit);
                overlayMaterial.mainTexture = GameDatabase.Instance.GetTexture(staticOverlay.EnforceSlashes(), false);

                if (!string.IsNullOrEmpty(headingBar))
                {
                    headingMaterial             = new Material(unlit);
                    headingMaterial.mainTexture = GameDatabase.Instance.GetTexture(headingBar.EnforceSlashes(), false);
                }
                horizonTex = GameDatabase.Instance.GetTexture(horizonTexture.EnforceSlashes(), false);

                gizmoTexture = JUtil.GetGizmoTexture();

                // Ahaha, that's clever, does it work?
                stockNavBall = GameObject.Find("NavBall").GetComponent <NavBall>();
                // ...well, it does, but the result is bizarre,
                // apparently, because the stock BALL ITSELF IS MIRRORED.

                navBall = GameDatabase.Instance.GetModel(navBallModel.EnforceSlashes());
                Destroy(navBall.collider);
                navBall.name  = "RPMNB" + navBall.GetInstanceID();
                navBall.layer = drawingLayer;
                navBall.transform.position      = Vector3.zero;
                navBall.transform.rotation      = Quaternion.identity;
                navBall.transform.localRotation = Quaternion.identity;

                if (ballIsEmissive)
                {
                    navBall.renderer.material.shader = Shader.Find("KSP/Emissive/Diffuse");
                    navBall.renderer.material.SetTexture("_MainTex", horizonTex);
                    navBall.renderer.material.SetTextureOffset("_Emissive", navBall.renderer.material.GetTextureOffset("_MainTex"));
                    navBall.renderer.material.SetTexture("_Emissive", horizonTex);
                    navBall.renderer.material.SetColor("_EmissiveColor", ballColorValue);
                }
                else
                {
                    navBall.renderer.material.shader      = Shader.Find("KSP/Unlit");
                    navBall.renderer.material.mainTexture = horizonTex;
                    navBall.renderer.material.color       = ballColorValue;
                }
                navBall.renderer.material.SetFloat("_Opacity", ballOpacity);

                markerPrograde      = BuildMarker(0, 2, progradeColorValue);
                markerRetrograde    = BuildMarker(1, 2, progradeColorValue);
                markerManeuver      = BuildMarker(2, 0, maneuverColorValue);
                markerManeuverMinus = BuildMarker(1, 2, maneuverColorValue);
                markerTarget        = BuildMarker(2, 1, targetColorValue);
                markerTargetMinus   = BuildMarker(2, 2, targetColorValue);
                markerNormal        = BuildMarker(0, 0, normalColorValue);
                markerNormalMinus   = BuildMarker(1, 0, normalColorValue);
                markerRadial        = BuildMarker(1, 1, radialColorValue);
                markerRadialMinus   = BuildMarker(0, 1, radialColorValue);

                markerDockingAlignment = BuildMarker(0, 2, dockingColorValue);

                // Non-moving parts...
                cameraBody                  = new GameObject();
                cameraBody.name             = "RPMPFD" + cameraBody.GetInstanceID();
                cameraBody.layer            = drawingLayer;
                ballCamera                  = cameraBody.AddComponent <Camera>();
                ballCamera.enabled          = false;
                ballCamera.orthographic     = true;
                ballCamera.clearFlags       = CameraClearFlags.Nothing;
                ballCamera.eventMask        = 0;
                ballCamera.farClipPlane     = 3f;
                ballCamera.orthographicSize = cameraSpan;
                ballCamera.cullingMask      = 1 << drawingLayer;
                ballCamera.clearFlags       = CameraClearFlags.Depth;
                // -2,0,0 seems to get the orientation exactly as the ship.
                // But logically, forward is Z+, right?
                // Which means that
                ballCamera.transform.position = new Vector3(0, 0, 2);
                ballCamera.transform.LookAt(Vector3.zero, Vector3.up);
                ballCamera.transform.position = new Vector3(cameraShift.x, cameraShift.y, 2);

                overlay       = CreateSimplePlane("RPMPFDOverlay" + internalProp.propID, 1f, drawingLayer);
                overlay.layer = drawingLayer;
                overlay.transform.position = new Vector3(0, 0, 1.5f);
                overlay.renderer.material  = overlayMaterial;
                overlay.transform.parent   = cameraBody.transform;
                FaceCamera(overlay);

                if (headingMaterial != null)
                {
                    heading       = CreateSimplePlane("RPMPFDHeading" + internalProp.propID, 1f, drawingLayer);
                    heading.layer = drawingLayer;
                    heading.transform.position   = new Vector3(headingBarPosition.x, headingBarPosition.y, headingAboveOverlay ? 1.55f : 1.45f);
                    heading.transform.parent     = cameraBody.transform;
                    heading.transform.localScale = new Vector3(headingBarPosition.z, 0, headingBarPosition.w);
                    heading.renderer.material    = headingMaterial;
                    heading.renderer.material.SetTextureScale("_MainTex", new Vector2(headingSpan, 1f));
                    FaceCamera(heading);
                }

                ShowHide(false, navBall, cameraBody, overlay, heading);
                startupComplete = true;
            } catch {
                JUtil.AnnoyUser(this);
                throw;
            }
        }
Пример #3
0
        /// <summary>
        /// Initialize the renderable game objects for the HUD.
        /// </summary>
        /// <param name="screenWidth"></param>
        /// <param name="screenHeight"></param>
        void InitializeRenderables(RenderTexture screen)
        {
            float screenWidth  = (float)screen.width;
            float screenHeight = (float)screen.height;

            Shader displayShader = JUtil.LoadInternalShader("RPM-DisplayShader");

            if (!string.IsNullOrEmpty(cameraTransform))
            {
                cameraObject = new FlyingCamera(part, screen, hudCamera.aspect);
                cameraObject.PointCamera(cameraTransform, hudFov);
            }

            if (!string.IsNullOrEmpty(staticOverlay))
            {
                Material overlayMaterial = new Material(displayShader);
                overlayMaterial.color = Color.white;
                Texture overlayTexture = GameDatabase.Instance.GetTexture(staticOverlay.EnforceSlashes(), false);
                overlayMaterial.mainTexture = overlayTexture;

                overlayMesh = JUtil.CreateSimplePlane("JSIHeadsUpDisplayOverlay" + hudCamera.GetInstanceID(), screenWidth * 0.5f, drawingLayer);
                overlayMesh.transform.position = new Vector3(0, 0, 1.0f);
                overlayMesh.GetComponent <Renderer>().material = overlayMaterial;
                overlayMesh.transform.parent = cameraBody.transform;

                JUtil.ShowHide(false, overlayMesh);
            }

            if (!string.IsNullOrEmpty(horizonTexture))
            {
                Shader   ladderShader   = JUtil.LoadInternalShader("RPM-CroppedDisplayShader");
                Material ladderMaterial = new Material(ladderShader);

                // _CropBound is in device normalized coordinates (-1 - +1)
                Vector4 cropBound = new Vector4(-horizonSize.x / screenWidth, -horizonSize.y / screenHeight, horizonSize.x / screenWidth, horizonSize.y / screenHeight);
                ladderMaterial.SetVector("_CropBound", cropBound);
                ladderMaterial.color       = Color.white;
                ladderMaterial.mainTexture = GameDatabase.Instance.GetTexture(horizonTexture.EnforceSlashes(), false);
                if (ladderMaterial.mainTexture != null)
                {
                    float   diagonal        = horizonSize.magnitude / Mathf.Min(horizonSize.x, horizonSize.y) * 0.5f;
                    Vector2 horizonDrawSize = diagonal * horizonSize;
                    horizonTextureSize.x = 0.5f * (horizonTextureSize.x / ladderMaterial.mainTexture.width);
                    horizonTextureSize.y = 0.5f * (horizonTextureSize.y / ladderMaterial.mainTexture.height);

                    ladderMaterial.mainTexture.wrapMode = TextureWrapMode.Clamp;

                    ladderMesh = JUtil.CreateSimplePlane("JSIHeadsUpDisplayLadder" + hudCamera.GetInstanceID(), horizonDrawSize, new Rect(0.0f, 0.0f, 1.0f, 1.0f), drawingLayer);
                    ladderMesh.transform.position = new Vector3(0, 0, 1.45f);
                    ladderMesh.GetComponent <Renderer>().material = ladderMaterial;
                    ladderMesh.transform.parent = cameraBody.transform;

                    JUtil.ShowHide(false, ladderMesh);

                    if (progradeColorValue.a > 0.0f && showLadderPrograde)
                    {
                        Material progradeIconMaterial = new Material(displayShader);
                        progradeIconMaterial.color = Color.white;
                        Rect texCoord;
                        if (string.IsNullOrEmpty(ladderProgradeTexture))
                        {
                            progradeIconMaterial.mainTexture = JUtil.GetGizmoTexture();
                            texCoord = GizmoIcons.GetIconLocation(GizmoIcons.IconType.PROGRADE);
                        }
                        else
                        {
                            Texture2D progradeTexture = GameDatabase.Instance.GetTexture(ladderProgradeTexture.EnforceSlashes(), false);
                            if (progradeTexture == null)
                            {
                                JUtil.LogErrorMessage(this, "Failed to find ladder prograde texture \"{0}\".", ladderProgradeTexture);
                            }
                            progradeIconMaterial.mainTexture = progradeTexture;
                            texCoord = new Rect(0.0f, 0.0f, 1.0f, 1.0f);
                        }
                        progradeIconMaterial.SetVector("_Color", progradeColorValue);

                        progradeLadderIcon = JUtil.CreateSimplePlane("JSIHeadsUpDisplayLadderProgradeIcon" + hudCamera.GetInstanceID(), new Vector2(iconPixelSize * 0.5f, iconPixelSize * 0.5f), texCoord, drawingLayer);
                        progradeLadderIcon.transform.position = new Vector3(0.0f, 0.0f, 1.41f);
                        progradeLadderIcon.GetComponent <Renderer>().material = progradeIconMaterial;
                        progradeLadderIcon.transform.parent = cameraBody.transform;
                    }
                }
            }

            if (!string.IsNullOrEmpty(headingBar))
            {
                Material headingMaterial = new Material(displayShader);
                headingMaterial.color       = Color.white;
                headingMaterial.mainTexture = GameDatabase.Instance.GetTexture(headingBar.EnforceSlashes(), false);
                if (headingMaterial.mainTexture != null)
                {
                    headingBarTextureWidth = 0.5f * (headingBarWidth / (float)headingMaterial.mainTexture.width);

                    headingMaterial.mainTexture.wrapMode = TextureWrapMode.Repeat;

                    headingMesh = JUtil.CreateSimplePlane("JSIHeadsUpDisplayHeading" + hudCamera.GetInstanceID(), new Vector2(headingBarPosition.z * 0.5f, headingBarPosition.w * 0.5f), new Rect(0.0f, 0.0f, 1.0f, 1.0f), drawingLayer);
                    headingMesh.transform.position = new Vector3(headingBarPosition.x + 0.5f * (headingBarPosition.z - screenWidth), 0.5f * (screenHeight - headingBarPosition.w) - headingBarPosition.y, 1.4f);
                    headingMesh.GetComponent <Renderer>().material = headingMaterial;
                    headingMesh.transform.parent = cameraBody.transform;

                    JUtil.ShowHide(false, headingMesh);

                    if (progradeColorValue.a > 0.0f && showHeadingBarPrograde)
                    {
                        Material progradeIconMaterial = new Material(displayShader);
                        progradeIconMaterial.color = Color.white;
                        Rect texCoord;
                        if (string.IsNullOrEmpty(headingBarProgradeTexture))
                        {
                            progradeIconMaterial.mainTexture = JUtil.GetGizmoTexture();
                            texCoord = GizmoIcons.GetIconLocation(GizmoIcons.IconType.PROGRADE);
                        }
                        else
                        {
                            Texture2D progradeTexture = GameDatabase.Instance.GetTexture(headingBarProgradeTexture.EnforceSlashes(), false);
                            if (progradeTexture == null)
                            {
                                JUtil.LogErrorMessage(this, "Failed to find heading bar prograde texture \"{0}\".", headingBarProgradeTexture);
                            }
                            progradeIconMaterial.mainTexture = progradeTexture;
                            texCoord = new Rect(0.0f, 0.0f, 1.0f, 1.0f);
                        }
                        progradeIconMaterial.SetVector("_Color", progradeColorValue);

                        progradeHeadingIconOrigin = headingBarPosition.x + 0.5f * (headingBarPosition.z - screenWidth);

                        progradeHeadingIcon = JUtil.CreateSimplePlane("JSIHeadsUpDisplayHeadingProgradeIcon" + hudCamera.GetInstanceID(), new Vector2(iconPixelSize * 0.5f, iconPixelSize * 0.5f), texCoord, drawingLayer);
                        progradeHeadingIcon.transform.position = new Vector3(progradeHeadingIconOrigin, 0.5f * (screenHeight - headingBarPosition.w) - headingBarPosition.y, 1.35f);
                        progradeHeadingIcon.GetComponent <Renderer>().material = progradeIconMaterial;
                        progradeHeadingIcon.transform.parent = headingMesh.transform;
                    }
                }
            }

            if (!string.IsNullOrEmpty(verticalBar))
            {
                ConfigNode[] nodes = GameDatabase.Instance.GetConfigNodes("JSIHUD_VERTICAL_BAR");
                string[]     vBars = verticalBar.Split(';');
                for (int i = 0; i < vBars.Length; ++i)
                {
                    for (int j = 0; j < nodes.Length; ++j)
                    {
                        if (nodes[j].HasValue("name") && vBars[i].Trim() == nodes[j].GetValue("name"))
                        {
                            try
                            {
                                VerticalBar vb = new VerticalBar(nodes[j], screenWidth, screenHeight, drawingLayer, displayShader, cameraBody);
                                verticalBars.Add(vb);
                            }
                            catch (Exception e)
                            {
                                JUtil.LogErrorMessage(this, "Error parsing JSIHUD_VERTICAL_BAR: {0}", e);
                            }
                            break;
                        }
                    }
                }
            }

            if (!string.IsNullOrEmpty(horizontalBar))
            {
                ConfigNode[] nodes = GameDatabase.Instance.GetConfigNodes("JSIHUD_HORIZONTAL_BAR");
                string[]     hBars = horizontalBar.Split(';');
                for (int i = 0; i < hBars.Length; ++i)
                {
                    for (int j = 0; j < nodes.Length; ++j)
                    {
                        if (nodes[j].HasValue("name") && hBars[i].Trim() == nodes[j].GetValue("name"))
                        {
                            try
                            {
                                HorizontalBar hb = new HorizontalBar(nodes[j], screenWidth, screenHeight, drawingLayer, displayShader, cameraBody);
                                horizontalBars.Add(hb);
                            }
                            catch (Exception e)
                            {
                                JUtil.LogErrorMessage(this, "Error parsing JSIHUD_HORIZONTAL_BAR: {0}", e);
                            }
                            break;
                        }
                    }
                }
            }
        }
Пример #4
0
        public void Start()
        {
            if (HighLogic.LoadedSceneIsEditor)
            {
                return;
            }

            rpmComp = RasterPropMonitorComputer.Instantiate(internalProp, true);

            if (string.IsNullOrEmpty(cameraTransform))
            {
                // Nothing to do if there're no camera transforms.
                return;
            }

            string[] cameraTransformList = cameraTransform.Split('|');

            // I'm sure this and the loop can be done a little differently to
            // make it clearer, but this works.
            string[] fovLimitsList   = (string.IsNullOrEmpty(fovLimits)) ? null : fovLimits.Split('|');
            string[] yawLimitsList   = (string.IsNullOrEmpty(yawLimits)) ? null : yawLimits.Split('|');
            string[] pitchLimitsList = (string.IsNullOrEmpty(pitchLimits)) ? null : pitchLimits.Split('|');
            string[] zoomRateList    = (string.IsNullOrEmpty(zoomRate)) ? null : zoomRate.Split('|');
            string[] yawRateList     = (string.IsNullOrEmpty(yawRate)) ? null : yawRate.Split('|');
            string[] pitchRateList   = (string.IsNullOrEmpty(pitchRate)) ? null : pitchRate.Split('|');

            // cameraTransformList controls the number of cameras instantiated.
            // Every other value has a default, so if it's not specified, we
            // will use that default.
            for (int i = 0; i < cameraTransformList.Length; ++i)
            {
                Vector2 thisFovLimit   = (fovLimitsList != null && i < fovLimitsList.Length) ? (Vector2)ConfigNode.ParseVector2(fovLimitsList[i]) : defaultFovLimits;
                Vector2 thisYawLimit   = (yawLimitsList != null && i < yawLimitsList.Length) ? (Vector2)ConfigNode.ParseVector2(yawLimitsList[i]) : defaultYawLimits;
                Vector2 thisPitchLimit = (pitchLimitsList != null && i < pitchLimitsList.Length) ? (Vector2)ConfigNode.ParseVector2(pitchLimitsList[i]) : defaultPitchLimits;
                float   thisZoomRate   = (zoomRateList != null && i < zoomRateList.Length) ? JUtil.GetFloat(zoomRateList[i]) ?? 0.0f : 0.0f;
                float   thisYawRate    = (yawRateList != null && i < yawRateList.Length) ? JUtil.GetFloat(yawRateList[i]) ?? 0.0f : 0.0f;
                float   thisPitchRate  = (pitchRateList != null && i < pitchRateList.Length) ? JUtil.GetFloat(pitchRateList[i]) ?? 0.0f : 0.0f;

                var thatCamera = new SteerableCameraParameters(cameraTransformList[i],
                                                               thisFovLimit, thisYawLimit, thisPitchLimit,
                                                               thisZoomRate, thisYawRate, thisPitchRate, i + 1);
                cameras.Add(thatCamera);
            }

            gizmoTexture = JUtil.GetGizmoTexture();

            iconMaterial = new Material(Shader.Find("KSP/Alpha/Unlit Transparent"));

            // MOARdV: The maneuver gizmo texture is white. Unity's DrawTexture
            // expects a (0.5, 0.5, 0.5, 0.5) texture to be neutral for coloring
            // purposes.  Multiplying the desired alpha by 1/2 gets around the
            // gizmo texture's color, and gets correct alpha effects.
            Color32 iconColor = ConfigNode.ParseColor32(targetIconColor);

            iconColor.a       /= 2;
            iconMaterial.color = iconColor;

            homeCrosshairMaterial       = new Material(Shader.Find("KSP/Alpha/Unlit Transparent"));
            homeCrosshairMaterial.color = ConfigNode.ParseColor32(homeCrosshairColor);

            if (!string.IsNullOrEmpty(cameraInfoVarName))
            {
                //rpmComp = RasterPropMonitorComputer.Instantiate(internalProp);
                //if (rpmComp.HasPropVar(cameraInfoVarName + "_ID", internalProp.propID))
                //{
                //    currentCamera = rpmComp.GetPropVar(cameraInfoVarName + "_ID", internalProp.propID) - 1;
                //}
                //else
                //{
                //    rpmComp.SetPropVar(cameraInfoVarName + "_ID", internalProp.propID, currentCamera + 1);
                //}
            }

            if (!string.IsNullOrEmpty(cameraEffectShader))
            {
                cameraEffectMaterial = new Material(JUtil.LoadInternalShader(cameraEffectShader));

                if (!string.IsNullOrEmpty(cameraEffectVariables))
                {
                    try
                    {
                        string[] vars = cameraEffectVariables.Split('|');
                        for (int i = 0; i < vars.Length; ++i)
                        {
                            string[] components = vars[i].Split(',');
                            if (components.Length == 2)
                            {
                                ShaderEffectVariable sev = new ShaderEffectVariable();
                                sev.variable = Shader.PropertyToID(components[0].Trim());
                                sev.value    = rpmComp.InstantiateVariableOrNumber(components[1]);
                                ceVariables.Add(sev);
                            }
                        }
                    }
                    catch { }
                }

                if (!string.IsNullOrEmpty(cameraEffectTextures))
                {
                    try
                    {
                        string[] vars = cameraEffectTextures.Split('|');
                        for (int i = 0; i < vars.Length; ++i)
                        {
                            string[] components = vars[i].Split(',');
                            if (components.Length == 2)
                            {
                                Texture tex = GameDatabase.Instance.GetTexture(components[1], false);
                                cameraEffectMaterial.SetTexture(components[0], tex);
                            }
                        }
                    }
                    catch { }
                }
            }

            if (!string.IsNullOrEmpty(cameraPixelSize))
            {
                string[] vars = cameraPixelSize.Split(',');
                if (vars.Length == 2)
                {
                    if (!int.TryParse(vars[0], out rentexWidth) || !int.TryParse(vars[1], out rentexHeight) || rentexHeight < 0 || rentexWidth < 0)
                    {
                        JUtil.LogMessage(this, "Bad image dimensions? {0} and {1}", vars[0], vars[1]);
                        rentexHeight = rentexWidth = 0;
                    }
                    else
                    {
                        JUtil.LogMessage(this, "Setting rentex to {0} x {1}", rentexWidth, rentexHeight);
                    }
                }
            }
        }
Пример #5
0
        public void Start()
        {
            if (HighLogic.LoadedSceneIsEditor)
            {
                return;
            }
            try {
                backgroundColorValue = ConfigNode.ParseColor32(backgroundColor);

                Shader unlit = Shader.Find("Hidden/Internal-GUITexture");
                ladderMaterial       = new Material(unlit);
                ladderMaterial.color = new Color(0.5f, 0.5f, 0.5f, 1.0f);
                if (!String.IsNullOrEmpty(horizonTexture))
                {
                    ladderMaterial.mainTexture = GameDatabase.Instance.GetTexture(horizonTexture.EnforceSlashes(), false);
                    if (ladderMaterial.mainTexture != null)
                    {
                        horizonTextureSize.x = horizonTextureSize.x / ladderMaterial.mainTexture.width;
                        ladderMaterial.mainTexture.wrapMode = TextureWrapMode.Clamp;
                    }
                }

                if (!String.IsNullOrEmpty(headingBar))
                {
                    headingMaterial             = new Material(unlit);
                    headingMaterial.color       = new Color(0.5f, 0.5f, 0.5f, 1.0f);
                    headingMaterial.mainTexture = GameDatabase.Instance.GetTexture(headingBar.EnforceSlashes(), false);
                }

                if (!String.IsNullOrEmpty(staticOverlay))
                {
                    overlayMaterial             = new Material(unlit);
                    overlayMaterial.color       = new Color(0.5f, 0.5f, 0.5f, 1.0f);
                    overlayMaterial.mainTexture = GameDatabase.Instance.GetTexture(staticOverlay.EnforceSlashes(), false);
                }

                if (!String.IsNullOrEmpty(vertBar1Texture) && !String.IsNullOrEmpty(vertBar1Variable))
                {
                    vertBar1Material             = new Material(unlit);
                    vertBar1Material.color       = new Color(0.5f, 0.5f, 0.5f, 1.0f);
                    vertBar1Material.mainTexture = GameDatabase.Instance.GetTexture(vertBar1Texture.EnforceSlashes(), false);
                    if (vertBar1Material.mainTexture != null)
                    {
                        float height = (float)vertBar1Material.mainTexture.height;
                        vertBar1TextureLimit.x = 1.0f - (vertBar1TextureLimit.x / height);
                        vertBar1TextureLimit.y = 1.0f - (vertBar1TextureLimit.y / height);
                        vertBar1TextureSize    = 0.5f * (vertBar1TextureSize / height);
                        vertBar1Material.mainTexture.wrapMode = TextureWrapMode.Clamp;
                    }
                }

                if (!String.IsNullOrEmpty(vertBar2Texture) && !String.IsNullOrEmpty(vertBar2Variable))
                {
                    vertBar2Material             = new Material(unlit);
                    vertBar2Material.color       = new Color(0.5f, 0.5f, 0.5f, 1.0f);
                    vertBar2Material.mainTexture = GameDatabase.Instance.GetTexture(vertBar2Texture.EnforceSlashes(), false);
                    if (vertBar2Material.mainTexture != null)
                    {
                        float height = (float)vertBar2Material.mainTexture.height;
                        vertBar2TextureLimit.x = 1.0f - (vertBar2TextureLimit.x / height);
                        vertBar2TextureLimit.y = 1.0f - (vertBar2TextureLimit.y / height);
                        vertBar2TextureSize    = 0.5f * (vertBar2TextureSize / height);
                        vertBar2Material.mainTexture.wrapMode = TextureWrapMode.Clamp;
                    }
                }

                if (vertBar1UseLog10)
                {
                    vertBar1Limit.x = JUtil.PseudoLog10(vertBar1Limit.x);
                    vertBar1Limit.y = JUtil.PseudoLog10(vertBar1Limit.y);
                }

                if (vertBar2UseLog10)
                {
                    vertBar2Limit.x = JUtil.PseudoLog10(vertBar2Limit.x);
                    vertBar2Limit.y = JUtil.PseudoLog10(vertBar2Limit.y);
                }

                if (!string.IsNullOrEmpty(progradeColor))
                {
                    progradeColorValue = ConfigNode.ParseColor32(progradeColor);
                }

                comp = RasterPropMonitorComputer.Instantiate(internalProp);

                iconMaterial       = new Material(unlit);
                iconMaterial.color = new Color(0.5f, 0.5f, 0.5f, 1.0f);
                gizmoTexture       = JUtil.GetGizmoTexture();

                startupComplete = true;
            } catch {
                JUtil.AnnoyUser(this);
                throw;
            }
        }
Пример #6
0
        private void ConfigureElements(float screenWidth, float screenHeight)
        {
            // How big is the nav ball, anyway?
            navballRadius = 0.0f;
            MeshFilter meshFilter = navBall.GetComponent <MeshFilter>();

            if (meshFilter != null)
            {
                // NOTE: I assume this really is a nav*ball*, not something
                // weird, and that it's centered on the origin.
                navballRadius = meshFilter.mesh.bounds.size.x * 0.5f;
                if (!(navballRadius > 0.0f))
                {
                    throw new Exception("JSIPrimaryFlightDisplay navball had an invalid size");
                }
            }
            else
            {
                throw new Exception("JSIPrimaryFlightDisplay could not get the navball mesh");
            }

            // Figure out how we have to manipulate the camera to get the
            // navball in the right place, and in the right size.
            float cameraSpan = navballRadius * screenHeight / navBallDiameter;
            float pixelSize  = cameraSpan / (screenHeight * 0.5f);

            ballCamera.orthographicSize = cameraSpan;

            float newXPos = navBallCenter.x - screenWidth * 0.5f;
            float newYPos = screenHeight * 0.5f - navBallCenter.y;

            navBallOrigin              = navBall.transform.position;
            navBallOrigin.x           += newXPos * pixelSize;
            navBallOrigin.y           += newYPos * pixelSize;
            navBall.transform.position = navBallOrigin;
            // Because we use this value to offset the markers, we don't
            // want/need depth info.
            navBallOrigin.z = 0.0f;

            float overlayDepth = navBall.transform.position.z - navballRadius - 0.1f;

            Shader displayShader = JUtil.LoadInternalShader("RPM-DisplayShader");

            if (!string.IsNullOrEmpty(staticOverlay))
            {
                Material overlayMaterial = new Material(displayShader);
                overlayMaterial.mainTexture = GameDatabase.Instance.GetTexture(staticOverlay.EnforceSlashes(), false);

                overlay       = JUtil.CreateSimplePlane("RPMPFDOverlay" + internalProp.propID, cameraSpan, drawingLayer);
                overlay.layer = drawingLayer;
                overlay.transform.position = new Vector3(0, 0, overlayDepth);
                overlay.renderer.material  = overlayMaterial;
                overlay.transform.parent   = cameraBody.transform;
            }

            if (!string.IsNullOrEmpty(headingBar))
            {
                Material headingMaterial = new Material(displayShader);
                headingMaterial.mainTexture = GameDatabase.Instance.GetTexture(headingBar.EnforceSlashes(), false);

                float hbXPos = headingBarPosition.x - screenWidth * 0.5f;
                float hbYPos = screenHeight * 0.5f - headingBarPosition.y;

                heading = JUtil.CreateSimplePlane("RPMPFDHeading" + internalProp.propID, new Vector2(headingBarPosition.z * pixelSize, headingBarPosition.w * pixelSize), new Rect(0.0f, 0.0f, 1.0f, 1.0f), drawingLayer);
                heading.transform.position = new Vector3(hbXPos * pixelSize, hbYPos * pixelSize, headingAboveOverlay ? (overlayDepth - 0.1f) : (overlayDepth + 0.1f));
                heading.transform.parent   = cameraBody.transform;
                heading.renderer.material  = headingMaterial;
                heading.renderer.material.SetTextureScale("_MainTex", new Vector2(headingSpan, 1f));
            }

            Texture2D gizmoTexture = JUtil.GetGizmoTexture();

            markerDepth = navBall.transform.position.z - navballRadius - 0.05f;
            float scaledMarkerSize = markerSize * 0.5f * pixelSize;

            markerPrograde      = BuildMarker(0, 2, scaledMarkerSize, gizmoTexture, progradeColorValue, drawingLayer, internalProp.propID, displayShader);
            markerRetrograde    = BuildMarker(1, 2, scaledMarkerSize, gizmoTexture, progradeColorValue, drawingLayer, internalProp.propID, displayShader);
            markerManeuver      = BuildMarker(2, 0, scaledMarkerSize, gizmoTexture, maneuverColorValue, drawingLayer, internalProp.propID, displayShader);
            markerManeuverMinus = BuildMarker(1, 2, scaledMarkerSize, gizmoTexture, maneuverColorValue, drawingLayer, internalProp.propID, displayShader);
            markerTarget        = BuildMarker(2, 1, scaledMarkerSize, gizmoTexture, targetColorValue, drawingLayer, internalProp.propID, displayShader);
            markerTargetMinus   = BuildMarker(2, 2, scaledMarkerSize, gizmoTexture, targetColorValue, drawingLayer, internalProp.propID, displayShader);
            markerNormal        = BuildMarker(0, 0, scaledMarkerSize, gizmoTexture, normalColorValue, drawingLayer, internalProp.propID, displayShader);
            markerNormalMinus   = BuildMarker(1, 0, scaledMarkerSize, gizmoTexture, normalColorValue, drawingLayer, internalProp.propID, displayShader);
            markerRadial        = BuildMarker(1, 1, scaledMarkerSize, gizmoTexture, radialColorValue, drawingLayer, internalProp.propID, displayShader);
            markerRadialMinus   = BuildMarker(0, 1, scaledMarkerSize, gizmoTexture, radialColorValue, drawingLayer, internalProp.propID, displayShader);

            markerDockingAlignment = BuildMarker(0, 2, scaledMarkerSize, gizmoTexture, dockingColorValue, drawingLayer, internalProp.propID, displayShader);
            markerNavWaypoint      = BuildMarker(0, 2, scaledMarkerSize, gizmoTexture, waypointColorValue, drawingLayer, internalProp.propID, displayShader);
        }