Exemple #1
0
 /// <summary>
 /// Make sure the shaders have access to a flight computer, so they can update
 /// variables.
 /// </summary>
 /// <param name="comp"></param>
 public void UpdateFlightComputer(MASFlightComputer comp)
 {
     for (int i = 0; i < mode.Length; ++i)
     {
         mode[i].UpdateShaderProperties(comp);
     }
 }
        //private static void HackWalkTransforms(Transform transform, int p)
        //{
        //    StringBuilder sb = new StringBuilder(p + 3);
        //    for (int i = 0; i < p; ++i)
        //    {
        //        sb.Append(" ");
        //    }
        //    sb.Append("+");
        //    sb.Append(transform.name);
        //    Utility.LogMessage(transform, "{0} @ ({1:0.0}, {2:0.0}, {3:0.000}) face ({4:0.0}, {5:0.0}, {6:0.0})", sb.ToString(), transform.position.x, transform.position.y, transform.position.z, transform.eulerAngles.x, transform.eulerAngles.y, transform.eulerAngles.z);
        //    for (int i = 0; i < transform.childCount; ++i)
        //    {
        //        HackWalkTransforms(transform.GetChild(i), p + 1);
        //    }
        //}

        /// <summary>
        /// Tear things down
        /// </summary>
        public void OnDestroy()
        {
            Camera.onPreCull    -= EnablePage;
            Camera.onPostRender -= DisablePage;

            if (screenCamera != null)
            {
                screenCamera.targetTexture = null;
            }

            if (screen != null)
            {
                screen.Release();
                screen = null;
            }

            if (initialized)
            {
                variableRegistrar.ReleaseResources();
                MASFlightComputer comp = MASFlightComputer.Instance(internalProp.part);

                foreach (var value in page.Values)
                {
                    value.ReleaseResources(comp, internalProp);
                }
                page.Clear();

                comp.UnregisterMonitor(monitorID, internalProp, this);

                GameObject.DestroyObject(screenSpace);
                screenSpace  = null;
                screenCamera = null;
            }
        }
        /// <summary>
        /// Release resources
        /// </summary>
        public override void ReleaseResources(MASFlightComputer comp, InternalProp internalProp)
        {
            renderMethod      = null;
            pageActiveMethod  = null;
            buttonClickMethod = null;
            pageEnabled       = false;
            this.comp         = null;

            UnityEngine.GameObject.Destroy(imageObject);
            imageObject = null;
            UnityEngine.GameObject.Destroy(imageMaterial);
            imageMaterial = null;
            if (displayTexture != null)
            {
                if (displayTexture.IsCreated())
                {
                    displayTexture.Release();
                }
                UnityEngine.GameObject.Destroy(displayTexture);
                displayTexture = null;
            }
            if (renderTexture != null)
            {
                if (renderTexture.IsCreated())
                {
                    renderTexture.Release();
                }
                UnityEngine.GameObject.Destroy(renderTexture);
                renderTexture = null;
            }

            variableRegistrar.ReleaseResources();
        }
Exemple #4
0
        /// <summary>
        /// Release resources
        /// </summary>
        public override void ReleaseResources(MASFlightComputer comp, InternalProp internalProp)
        {
            this.comp = null;

            if (activeCamera != null)
            {
                activeCamera.renderCallback -= ReadCamera;
            }
            activeCamera = null;

            if (cameraTexture.IsCreated())
            {
                cameraTexture.Release();
            }
            UnityEngine.GameObject.Destroy(cameraTexture);
            cameraTexture = null;

            UnityEngine.GameObject.Destroy(imageObject);
            imageObject = null;
            UnityEngine.GameObject.Destroy(imageMaterial);
            imageMaterial = null;

            variableRegistrar.ReleaseResources();

            //if (renderFrames > 0)
            //{
            //    double msPerFrame = 1000.0 * (double)(renderStopwatch.ElapsedTicks) / (double)(renderFrames * Stopwatch.Frequency);
            //    Utility.LogMessage(this, "Camera page {0}: {1} frames rendered, {2:0.0}ms/frame",
            //        name, renderFrames, msPerFrame);
            //}
        }
        /// <summary>
        /// Convert a string to a Color32; supports RasterPropMonitor COLOR_
        /// names.
        /// </summary>
        /// <param name="colorString">String to convert</param>
        /// <param name="comp">Reference to the MASFlightComputer</param>
        /// <returns>Color value.</returns>
        internal static UnityEngine.Color32 ParseColor32(string colorString, MASFlightComputer comp)
        {
            colorString = colorString.Trim();

            if (colorString.StartsWith("#"))
            {
                Color32 c;

                ParseHexColor(colorString, out c);

                return(c);
            }
            else if (colorString.StartsWith("COLOR_"))
            {
                // Using a RasterPropMonitor named color.
                return(comp.GetNamedColor(colorString));
            }
            else
            {
                int numCommas = colorString.Split(',').Length - 1;
                if (numCommas < 2 || numCommas > 3)
                {
                    Utility.LogStaticWarning("Parsing color string \"{0}\": it does not appear to have the right number of entries for an R,G,B{{,A}} entry.", colorString);
                }
                return(ConfigNode.ParseColor32(colorString));
            }
        }
Exemple #6
0
 /// <summary>
 /// Configure the common fields.
 /// </summary>
 /// <param name="config"></param>
 /// <param name="prop"></param>
 /// <param name="comp"></param>
 internal IMASSubComponent(ConfigNode config, InternalProp prop, MASFlightComputer comp)
 {
     variableRegistrar = new VariableRegistrar(comp, prop);
     if (!config.TryGetValue("name", ref name))
     {
         name = "anonymous";
     }
 }
Exemple #7
0
 /// <summary>
 /// Release resources
 /// </summary>
 public override void ReleaseResources(MASFlightComputer comp, InternalProp internalProp)
 {
     if (buttonObject != null)
     {
         buttonObject.parent = null;
     }
     variableRegistrar.ReleaseResources();
 }
Exemple #8
0
        /// <summary>
        /// Release resources
        /// </summary>
        public override void ReleaseResources(MASFlightComputer comp, InternalProp internalProp)
        {
            Font.textureRebuilt -= FontRebuiltCallback;

            UnityEngine.GameObject.Destroy(meshObject);
            meshObject = null;

            variableRegistrar.ReleaseResources();
        }
Exemple #9
0
        /// <summary>
        /// Release resources
        /// </summary>
        public override void ReleaseResources(MASFlightComputer comp, InternalProp internalProp)
        {
            variableRegistrar.ReleaseResources();

            UnityEngine.GameObject.Destroy(imageObject);
            imageObject = null;
            UnityEngine.GameObject.Destroy(imageMaterial);
            imageMaterial = null;
        }
        internal MASComponentAnimationPlayer(ConfigNode config, InternalProp prop, MASFlightComputer comp)
            : base(config, prop, comp)
        {
            bool exterior = false;

            if (!config.TryGetValue("animation", ref animationName))
            {
                if (!config.TryGetValue("externalAnimation", ref animationName) || string.IsNullOrEmpty(animationName))
                {
                    throw new ArgumentException("Invalid or missing 'externalAnimation' or 'animation' in ANIMATION_PLAYER " + name);
                }

                exterior = true;
            }

            // Set up the animation.
            Animation[] animators = (exterior) ? prop.part.FindModelAnimators(animationName) : prop.FindModelAnimators(animationName);
            if (animators.Length == 0)
            {
                animators = (exterior) ? prop.part.FindModelAnimators() : prop.FindModelAnimators();
                Utility.LogWarning(this, "Did not find{0}animation {1} for ANIMATION_PLAYER {2}.  Valid animation names are:",
                                   (exterior) ? " external " : " ", animationName, name);
                foreach (var a in animators)
                {
                    if (a.clip != null)
                    {
                        Utility.LogWarning(this, "... \"{0}\"", a.clip.name);
                    }
                }
                throw new ArgumentException("Unable to find" + ((exterior) ? " external " : " ") + "animation " + animationName + " for ANIMATION_PLAYER " + name);
            }
            animation      = animators[0];
            animationState = animation[animationName];

            if (!config.TryGetValue("loop", ref loop))
            {
                loop = false;
            }
            animationState.wrapMode = (loop) ? WrapMode.Loop : WrapMode.Once;

            string animationSpeedString = string.Empty;

            if (config.TryGetValue("animationSpeed", ref animationSpeedString))
            {
                variableRegistrar.RegisterVariableChangeCallback(animationSpeedString, AnimationSpeedCallback);
            }

            string variableName = string.Empty;

            if (!config.TryGetValue("variable", ref variableName) || string.IsNullOrEmpty(variableName))
            {
                throw new ArgumentException("Invalid or missing 'variable' in ANIMATION_PLAYER " + name);
            }
            variableName = variableName.Trim();

            variableRegistrar.RegisterVariableChangeCallback(variableName, VariableCallback);
        }
        /// <summary>
        /// Release resources
        /// </summary>
        public override void ReleaseResources(MASFlightComputer comp, InternalProp internalProp)
        {
            UnityEngine.Object.Destroy(polygonMaterial);
            polygonMaterial = null;
            UnityEngine.Object.Destroy(polygonOrigin);
            polygonOrigin = null;

            variableRegistrar.ReleaseResources();
        }
        /// <summary>
        /// Release resources
        /// </summary>
        public override void ReleaseResources(MASFlightComputer comp, InternalProp internalProp)
        {
            lineRenderer = null;
            UnityEngine.Object.Destroy(lineMaterial);
            lineMaterial = null;
            UnityEngine.Object.Destroy(lineOrigin);
            lineOrigin = null;

            variableRegistrar.ReleaseResources();
        }
Exemple #13
0
        /// <summary>
        /// Release resources
        /// </summary>
        public override void ReleaseResources(MASFlightComputer comp, InternalProp internalProp)
        {
            this.comp = null;

            UnityEngine.GameObject.Destroy(rootObject);
            rootObject = null;

            variableRegistrar.ReleaseResources();
            textElements = null;
        }
Exemple #14
0
        internal IMASMonitorComponent(ConfigNode config, InternalProp prop, MASFlightComputer comp)
            : base(config, prop, comp)
        {
            string range = string.Empty;

            if (config.TryGetValue("range", ref range))
            {
                Utility.LogError(this, "Support for 'range' in MASPage modes was removed in v0.20.0.  Please use 'fc.Between(variable, range1, range2)' in your 'variable' field. - " + config.name + " " + name);
            }
        }
Exemple #15
0
        /// <summary>
        /// Notify children to release resources prior to being freed.
        /// </summary>
        /// <param name="comp"></param>
        internal void ReleaseResources(MASFlightComputer comp, InternalProp internalProp)
        {
            int numComponents = component.Count;

            for (int i = 0; i < numComponents; ++i)
            {
                component[i].ReleaseResources(comp, internalProp);
            }
            component.Clear();
        }
Exemple #16
0
        /// <summary>
        /// Release resources
        /// </summary>
        public override void ReleaseResources(MASFlightComputer comp, InternalProp prop)
        {
            GameEvents.OnCameraChange.Remove(OnCameraChange);

            variableRegistrar.ReleaseResources();

            audioSource.Stop();
            audioSource.clip = null;
            audioSource      = null;
        }
Exemple #17
0
        /// <summary>
        /// Release resources
        /// </summary>
        public override void ReleaseResources(MASFlightComputer comp, InternalProp internalProp)
        {
            rpmModule = null;
            this.comp = null;
            this.prop = null;

            UnityEngine.GameObject.Destroy(meshObject);
            meshObject = null;

            variableRegistrar.ReleaseResources();
        }
Exemple #18
0
        public void Start()
        {
            if (HighLogic.LoadedSceneIsFlight)
            {
                lastState = actionState;

                comp = part.FindModuleImplementing <MASFlightComputer>();

                menuName = (lastState) ? deactivateText : activateText;
            }
        }
 /// <summary>
 /// Call the startupScript, if it exists.
 /// </summary>
 /// <param name="comp">The MASFlightComputer for this prop.</param>
 /// <returns>true if a script exists, false otherwise.</returns>
 internal bool RunStartupScript(MASFlightComputer comp)
 {
     if (!string.IsNullOrEmpty(startupScript))
     {
         Action startup = comp.GetAction(startupScript, internalProp);
         startup();
         return(true);
     }
     else
     {
         return(false);
     }
 }
Exemple #20
0
        /// <summary>
        /// Release resources used by this module's children.
        /// </summary>
        public void OnDestroy()
        {
            try
            {
                MASFlightComputer comp = MASFlightComputer.Instance(internalProp.part);

                for (int i = 0; i < actions.Count; ++i)
                {
                    actions[i].ReleaseResources(comp, internalProp);
                }
            }
            catch { }
        }
Exemple #21
0
        /// <summary>
        /// Release resources
        /// </summary>
        public override void ReleaseResources(MASFlightComputer comp, InternalProp internalProp)
        {
            lineRenderer = null;
            UnityEngine.Object.Destroy(graphMaterial);
            graphMaterial = null;
            UnityEngine.Object.Destroy(borderMaterial);
            borderMaterial = null;
            UnityEngine.Object.Destroy(graphObject);
            graphObject = null;
            UnityEngine.Object.Destroy(borderObject);
            borderObject = null;

            variableRegistrar.ReleaseResources();
        }
        /// <summary>
        /// Release resources
        /// </summary>
        public override void ReleaseResources(MASFlightComputer comp, InternalProp internalProp)
        {
            variableRegistrar.ReleaseResources();

            if (useFlash)
            {
                comp.UnregisterFlashCallback(flashRate, FlashToggle);
            }

            for (int i = localMaterial.Length - 1; i >= 0; --i)
            {
                UnityEngine.Object.Destroy(localMaterial[i]);
            }
        }
Exemple #23
0
 /// <summary>
 /// Release resources
 /// </summary>
 public override void ReleaseResources(MASFlightComputer comp, InternalProp internalProp)
 {
     coroutineEnabled = false;
     if (textRow.variable != null)
     {
         for (int var = 0; var < textRow.variable.Length; ++var)
         {
             textRow.variable[var] = null;
         }
         textRow.variable = null;
         textRow.callback = null;
     }
     variableRegistrar.ReleaseResources();
 }
Exemple #24
0
        /// <summary>
        /// Initialize the MASNavBall components.
        /// </summary>
        public void Start()
        {
            MASFlightComputer comp = MASFlightComputer.Instance(internalProp.part);

            if (comp == null)
            {
                throw new ArgumentNullException("Unable to find MASFlightComputer in part - please check part configs");
            }
            variableRegistrar = new VariableRegistrar(comp, null);

            lastOrientation = navBall.rotation;

            variableRegistrar.RegisterVariableChangeCallback(variable, (double newValue) => currentState = (newValue > 0.0));
        }
        /// <summary>
        /// Iterate over all registered variables and unregister them.
        /// </summary>
        internal void ReleaseResources()
        {
            if (isEnabled)
            {
                for (int i = variable.Count - 1; i >= 0; --i)
                {
                    variable[i].UnregisterNumericCallback(variableAction[i]);
                }
            }

            this.comp         = null;
            this.internalProp = null;
            variable.Clear();
            variableAction.Clear();
        }
Exemple #26
0
        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));
        }
 /// <summary>
 /// Release resources
 /// </summary>
 public override void ReleaseResources(MASFlightComputer comp, InternalProp internalProp)
 {
     Camera.onPreCull    -= CameraPrerender;
     Camera.onPostRender -= CameraPostrender;
     UnityEngine.GameObject.Destroy(imageObject);
     imageObject = null;
     UnityEngine.Object.Destroy(imageMaterial);
     imageMaterial = null;
     UnityEngine.GameObject.Destroy(navballModel);
     navballModel = null;
     UnityEngine.Object.Destroy(navballMaterial);
     navballMaterial = null;
     UnityEngine.GameObject.Destroy(cameraObject);
     cameraObject = null;
     variableRegistrar.ReleaseResources();
     this.comp = null;
 }
Exemple #28
0
        /// <summary>
        /// Callback used to tell the mode to refresh its shader properties.
        /// </summary>
        /// <param name="comp"></param>
        public void UpdateShaderProperties(MASFlightComputer comp)
        {
            if (this.comp == comp)
            {
                return;
            }

            UnregisterShaderProperties();

            this.comp         = comp;
            variableRegistrar = new VariableRegistrar(comp, null);

            for (int i = 0; i < propertyValue.Length; ++i)
            {
                int id = propertyId[i];
                variableRegistrar.RegisterVariableChangeCallback(propertyValue[i], (double newValue) => postProcShader.SetFloat(id, (float)newValue));
            }
        }
        /// <summary>
        /// Release resources
        /// </summary>
        public override void ReleaseResources(MASFlightComputer comp, InternalProp internalProp)
        {
            coroutineEnabled = false;
            updateVessel     = false;
            updateTarget     = false;
            updateManeuver   = false;
            variableRegistrar.ReleaseResources();

            for (int i = lineOrigin.Length - 1; i >= 0; --i)
            {
                lineRenderer[i] = null;
                UnityEngine.Object.Destroy(lineMaterial[i]);
                lineMaterial[i] = null;
                UnityEngine.Object.Destroy(lineOrigin[i]);
                lineOrigin[i] = null;
            }

            this.comp = null;
        }
Exemple #30
0
        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);
        }