Esempio n. 1
0
 private void applyConfig(Transform root, TextureSet set, bool useSetColors, bool useIconShaders = false)
 {
     if (set == null)
     {
         return;
     }
     RecoloringData[] colors = useSetColors? set.maskColors : customColors;
     if (useSetColors)
     {
         customColors = set.maskColors;
         saveColors(customColors);
     }
     //apply the texture set to the base model (and trusses?)
     set.enable(root, colors, useIconShaders);
     if (stockFairing)
     {
         TextureSetMaterialData tsmd = set.textureData[0];
         //adjust the already existing fairing materials and fairing panels
         ModuleProceduralFairing mpf = part.GetComponent <ModuleProceduralFairing>();
         if (mpf != null)
         {
             Material mat;
             if (mpf.FairingMaterial != null && mpf.FairingConeMaterial != null)
             {
                 mat = mpf.FairingMaterial;
                 tsmd.apply(mat, useIconShaders);
                 tsmd.applyRecoloring(mat, colors);
                 mat = mpf.FairingConeMaterial;
                 tsmd.apply(mat, useIconShaders);
                 tsmd.applyRecoloring(mat, colors);
             }
             if (mpf.Panels != null && mpf.Panels.Count > 0)//cones are included in regular panels
             {
                 int len = mpf.Panels.Count;
                 for (int i = 0; i < len; i++)
                 {
                     mat = mpf.Panels[i].mat;
                     tsmd.apply(mat, useIconShaders);
                     tsmd.applyRecoloring(mat, colors);
                     mat = mpf.Panels[i].go.GetComponent <Renderer>().material;
                     tsmd.apply(mat, useIconShaders);
                     tsmd.applyRecoloring(mat, colors);
                 }
             }
         }
     }
 }
Esempio n. 2
0
        //really, could probably just move this back to the base class, possibly with a config bool for toggling enable of the secondary updates
        public void Start()
        {
            TextureSet ts = TexturesUnlimitedLoader.getTextureSet(textureSet);

            if (ts != null)
            {
                //apply the textur set to the base model, use set-specified mask colors (does not support user recoloring)
                ts.enable(part.transform.FindRecursive("model"), ts.maskColors);
                TextureSetMaterialData tsmd = ts.textureData[materialIndex];
                //adjust the already existing fairing materials and fairing panels
                ModuleProceduralFairing mpf = part.GetComponent <ModuleProceduralFairing>();
                if (mpf != null)
                {
                    if (mpf.FairingMaterial != null && mpf.FairingConeMaterial != null)
                    {
                        tsmd.apply(mpf.FairingMaterial);
                        tsmd.apply(mpf.FairingConeMaterial);
                    }
                    if (mpf.Panels != null && mpf.Panels.Count > 0)//cones are included in regular panels
                    {
                        int len = mpf.Panels.Count;
                        for (int i = 0; i < len; i++)
                        {
                            tsmd.apply(mpf.Panels[i].mat);
                            tsmd.apply(mpf.Panels[i].go.GetComponent <Renderer>().material);
                        }
                    }
                }
            }
            //prev shader-only code...
            //Shader shader = TexturesUnlimitedLoader.getShader(this.shader);
            //if (mpf != null && shader != null && mpf.FairingMaterial != null)
            //{
            //    mpf.FairingMaterial.shader = shader;
            //    if (mpf.FairingConeMaterial != null) { mpf.FairingConeMaterial.shader = shader; }
            //    MonoBehaviour.print("Adjusted MPF materials!");
            //    if (mpf.Panels != null && mpf.Panels.Count > 0)//cones are included in regular panels
            //    {
            //        int len = mpf.Panels.Count;
            //        for (int i = 0; i < len; i++)
            //        {
            //            mpf.Panels[i].mat.shader = shader;
            //            mpf.Panels[i].go.GetComponent<Renderer>().material.shader = shader;
            //        }
            //    }
            //}
        }
        /// <summary>
        /// Apply the current texture to the input transform.  The texture sets include/exclude settings will be used to determine what children of the input transforms should be adjusted.
        /// </summary>
        /// <param name="root"></param>
        public void enableCurrentSet(Transform root)
        {
            TextureSet set = currentTextureSet;

            if (set == null)
            {
                MonoBehaviour.print("ERROR: KSPTextureSwitch could not locate texture set for name: " + currentTextureSetName);
            }
            if (customColors == null || customColors.Length == 0)
            {
                customColors    = new RecoloringData[3];
                customColors[0] = set.maskColors[0];
                customColors[1] = set.maskColors[1];
                customColors[2] = set.maskColors[2];
            }
            set.enable(root, customColors);
            saveColors(customColors);
        }
        /// <summary>
        /// Apply the current texture to the input transforms.  The texture sets include/exclude settings will be used to determine what children of the input transforms should be adjusted.
        /// </summary>
        /// <param name="roots"></param>
        public void enableCurrentSet(Transform[] roots, bool userInput)
        {
            TextureSet set = currentTextureSet;

            if (set == null)
            {
                return;
            }
            if (userInput || customColors == null || customColors.Length == 0)
            {
                customColors    = new RecoloringData[3];
                customColors[0] = set.maskColors[0];
                customColors[1] = set.maskColors[1];
                customColors[2] = set.maskColors[2];
            }
            int len = roots.Length;

            for (int i = 0; i < len; i++)
            {
                set.enable(roots[i], customColors);
            }
            saveColors(customColors);
        }
Esempio n. 5
0
        public void enableCurrentSet(Transform[] roots)
        {
            TextureSet set = Array.Find(textureSets, m => m.name == currentTextureSet);

            if (set == null)
            {
                MonoBehaviour.print("ERROR: KSPTextureSwitch could not locate texture set for name: " + currentTextureSet);
            }
            if (customColors == null || customColors.Length == 0)
            {
                customColors    = new RecoloringData[3];
                customColors[0] = set.maskColors[0];
                customColors[1] = set.maskColors[1];
                customColors[2] = set.maskColors[2];
            }
            int len = roots.Length;

            for (int i = 0; i < len; i++)
            {
                set.enable(roots[i].gameObject, customColors);
            }
            saveColors(customColors);
        }