示例#1
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);
                    }
                }
            }
        }
示例#2
0
        public void Start()
        {
            if (HighLogic.LoadedSceneIsEditor)
            {
                return;
            }
            try
            {
                rpmComp = RasterPropMonitorComputer.Instantiate(internalProp, true);

                backgroundColorValue = ConfigNode.ParseColor32(backgroundColor);

                cameraBody                 = new GameObject();
                cameraBody.name            = "RPMPFD" + cameraBody.GetInstanceID();
                cameraBody.layer           = drawingLayer;
                hudCamera                  = cameraBody.AddComponent <Camera>();
                hudCamera.enabled          = false;
                hudCamera.orthographic     = true;
                hudCamera.eventMask        = 0;
                hudCamera.farClipPlane     = 3f;
                hudCamera.orthographicSize = 1.0f;
                hudCamera.cullingMask      = 1 << drawingLayer;
                // does this actually work?
                hudCamera.backgroundColor      = backgroundColorValue;
                hudCamera.clearFlags           = CameraClearFlags.Depth | CameraClearFlags.Color;
                hudCamera.transparencySortMode = TransparencySortMode.Orthographic;
                hudCamera.transform.position   = Vector3.zero;
                hudCamera.transform.LookAt(new Vector3(0.0f, 0.0f, 1.5f), Vector3.up);

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

                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 { }
                    }
                }
            }
            catch (Exception e)
            {
                JUtil.LogErrorMessage(this, "Start() failed with an exception: {0}", e);
                JUtil.AnnoyUser(this);
                throw;
            }

            startupComplete = true;
        }
        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);
                    }
                }
            }
        }
        public void Start()
        {
            if (HighLogic.LoadedSceneIsEditor)
            {
                return;
            }
            try
            {
                rpmComp = RasterPropMonitorComputer.Instantiate(internalProp, true);

                backgroundColorValue = ConfigNode.ParseColor32(backgroundColor);

                cameraBody = new GameObject();
                cameraBody.name = "RPMPFD" + cameraBody.GetInstanceID();
                cameraBody.layer = drawingLayer;
                hudCamera = cameraBody.AddComponent<Camera>();
                hudCamera.enabled = false;
                hudCamera.orthographic = true;
                hudCamera.eventMask = 0;
                hudCamera.farClipPlane = 3f;
                hudCamera.orthographicSize = 1.0f;
                hudCamera.cullingMask = 1 << drawingLayer;
                // does this actually work?
                hudCamera.backgroundColor = backgroundColorValue;
                hudCamera.clearFlags = CameraClearFlags.Depth | CameraClearFlags.Color;
                hudCamera.transparencySortMode = TransparencySortMode.Orthographic;
                hudCamera.transform.position = Vector3.zero;
                hudCamera.transform.LookAt(new Vector3(0.0f, 0.0f, 1.5f), Vector3.up);

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

                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 { }
                    }
                }
            }
            catch (Exception e)
            {
                JUtil.LogErrorMessage(this, "Start() failed with an exception: {0}", e);
                JUtil.AnnoyUser(this);
                throw;
            }

            startupComplete = true;
        }