Пример #1
0
        protected void UpdateTargets()
        {
            if (_targets == null)
            {
                _targets = new List <ProjectionTarget>();
            }
            else
            {
                _targets.Clear();
            }

            // find all valid renderers
            var renderers = part.parent.FindModelComponents <MeshRenderer>();

            foreach (var renderer in renderers)
            {
                // skip disabled renderers
                if (renderer.gameObject.activeInHierarchy == false)
                {
                    continue;
                }

                // skip blacklisted shaders
                if (DecalConfig.IsBlacklisted(renderer.material.shader))
                {
                    continue;
                }

                var meshFilter = renderer.GetComponent <MeshFilter>();
                if (meshFilter == null)
                {
                    continue;                     // object has a meshRenderer with no filter, invalid
                }
                var mesh = meshFilter.mesh;
                if (mesh == null)
                {
                    continue;               // object has a null mesh, invalid
                }
                // create new ProjectionTarget to represent the renderer
                var target = new ProjectionTarget(renderer, mesh);

                // add the target to the list
                _targets.Add(target);
            }
        }
        public override void OnLoad(ConfigNode node)
        {
            base.OnLoad(node);

            string textRaw = "";

            if (ParseUtil.ParseStringIndirect(ref textRaw, node, "text"))
            {
                text = WebUtility.UrlDecode(textRaw);
            }

            string fontName = "";

            if (ParseUtil.ParseStringIndirect(ref fontName, node, "fontName"))
            {
                font = DecalConfig.GetFont(fontName);
            }
            else if (font == null)
            {
                font = DecalConfig.GetFont("Calibri SDF");
            }

            int styleInt = 0;

            if (ParseUtil.ParseIntIndirect(ref styleInt, node, "style"))
            {
                style = (FontStyles)styleInt;
            }

            ParseUtil.ParseColor32Indirect(ref fillColor, node, "fillColor");
            ParseUtil.ParseColor32Indirect(ref outlineColor, node, "outlineColor");

            if (HighLogic.LoadedSceneIsGame)
            {
                // For some reason, rendering doesnt work right on the first frame a scene is loaded
                // So delay any rendering until the next frame when called in OnLoad
                // This is probably a problem with Unity, not KSP
                StartCoroutine(UpdateTextLate());
            }
            else
            {
                UpdateText();
            }
        }