Esempio n. 1
0
        public static void LoadTextures()
        {
            if (shroudTextures == null)
            {
                List <GameDatabase.TextureInfo> textures = GameDatabase.Instance.GetAllTexturesInFolder("DecouplerShroud/Textures/");
                shroudTextures = new List <ShroudTexture>();

                foreach (ConfigNode texconf in GameDatabase.Instance.GetConfigNodes("ShroudTexture"))
                {
                    if (!texconf.HasNode("outside") || !texconf.HasNode("top") || !texconf.HasNode("inside"))
                    {
                        Debug.LogError("Decoupler Shroud texture config missing node: " + texconf);
                        continue;
                    }

                    ShroudTexture tex = new ShroudTexture();
                    if (texconf.HasValue("name"))
                    {
                        tex.name = texconf.GetValue("name");
                    }

                    tex.textures.Add(new SurfaceTexture(texconf.GetNode("outside")));
                    tex.textures.Add(new SurfaceTexture(texconf.GetNode("top")));
                    tex.textures.Add(new SurfaceTexture(texconf.GetNode("inside")));

                    shroudTextures.Add(tex);
                }
            }
        }
Esempio n. 2
0
        //Gets textures from Textures folder and loads them into surfaceTextures list + set Field options
        void getTextureNames()
        {
            if (ShroudTexture.shroudTextures == null)
            {
                ShroudTexture.LoadTextures();
            }

            if (textureIndex >= ShroudTexture.shroudTextures.Count)
            {
                textureIndex = 0;
            }

            string[] options = new string[ShroudTexture.shroudTextures.Count];
            for (int i = 0; i < options.Length; i++)
            {
                options[i] = ShroudTexture.shroudTextures[i].name;

                //Sets textureindex to the saved texture
                if (options[i].Equals(textureName))
                {
                    textureIndex = i;
                }
            }

            BaseField       textureField   = Fields[nameof(textureIndex)];
            UI_ChooseOption textureOptions = (UI_ChooseOption)textureField.uiControlEditor;

            textureOptions.options = options;
        }
        //Creates the material for the mesh
        void CreateMaterials(ShroudTexture shroudTex)
        {
            //Clean up old materials
            if (shroudMats != null)
            {
                foreach (Material mat in shroudMats)
                {
                    if (mat != null)
                    {
                        Destroy(mat);
                    }
                }
            }
            shroudMats = new Material[3];

            for (int i = 0; i < shroudMats.Length; i++)
            {
                SurfaceTexture surf = shroudTex.textures[i];

                shroudMats[i]      = Instantiate(surf.mat);
                shroudMats[i].name = "shroudMat: " + i + ", " + segments + " segments";

                if (HighLogic.LoadedSceneIsEditor)
                {
                    // Enables transparency in editor
                    shroudMats[i].renderQueue = 3000;
                }
            }
        }
        void changeMaterial()
        {
            ShroudTexture shroudTex = ShroudTexture.shroudTextures[textureIndex];

            //save current textures name
            textureName = shroudTex.name;
            CreateMaterials(shroudTex);

            updateTextureScale();
        }
        static void ParseShroudTextureWithTexBase(ConfigNode node, ShroudTexture texBase, Dictionary <string, List <ConfigNode> > waiting)
        {
            int v = 1;

            if (node.HasValue("v"))
            {
                int.TryParse(node.GetValue("v"), out v);
            }

            ShroudTexture tex = new ShroudTexture();

            if (node.HasValue("name"))
            {
                tex.name        = node.GetValue("name");
                tex.displayName = tex.name;
                if (getShroudTextureByName(tex.name) != null)
                {
                    Debug.LogError("[DecouplerShroud] Another ShroudTexture already exists with name " + tex.name + ". Make sure all textures have unique names");
                    return;
                }
            }
            else
            {
                Debug.LogError("[DecouplerShroud] ShroudTexture needs name! " + node);
                return;
            }
            if (node.HasValue("displayName"))
            {
                tex.displayName = node.GetValue("displayName");
            }
            if (node.HasValue("showInVAB"))
            {
                bool.TryParse(node.GetValue("showInVAB"), out tex.showInVAB);
            }

            tex.textures.Add(new SurfaceTexture(node.GetNode("outside"), texBase.textures[0], v));
            tex.textures.Add(new SurfaceTexture(node.GetNode("top"), texBase.textures[1], v));
            tex.textures.Add(new SurfaceTexture(node.GetNode("inside"), texBase.textures[2], v));
            shroudTextureDictionary.Add(tex.name, tex);
            Debug.Log("[DecouplerShroud] Loaded ShroudedTexture: " + tex.name + "(outside shader = " + tex.textures[0].shader + ") with base: " + texBase.name);

            // Check if this is the base of a texture in the waiting list, if so parse all textures waiting for this texture
            List <ConfigNode> waitingForMe;

            if (waiting.TryGetValue(tex.name, out waitingForMe))
            {
                waiting.Remove(tex.name);
                //Debug.Log("[DecouplerShroud] Found " + waitingForMe.Count + " nodes waiting for " + tex.name);
                foreach (ConfigNode waitingNode in waitingForMe)
                {
                    ParseShroudTextureWithTexBase(waitingNode, tex, waiting);
                }
            }
        }
Esempio n. 6
0
        void updateTexture()
        {
            ShroudTexture shroudTex = ShroudTexture.shroudTextures[textureIndex];

            //save current textures name
            textureName = shroudTex.name;

            Vector2 sideSize = new Vector2(Mathf.Max(botWidth, topWidth), new Vector2(height, topWidth - botWidth).magnitude);
            Vector2 topSize  = new Vector2(topWidth, topWidth * thickness);

            shroudTex.textures[0].SetMaterialProperties(shroudMats[0], sideSize);
            shroudTex.textures[1].SetMaterialProperties(shroudMats[1], topSize);
            shroudTex.textures[2].SetMaterialProperties(shroudMats[2], sideSize);

            shroudGO.GetComponent <Renderer>().materials = shroudMats;
        }
        void updateTextureScale()
        {
            if (shroudMats == null)
            {
                changeMaterial();
                return;
            }
            if (shroudMats[0] == null)
            {
                Debug.LogWarning("called updateTextureScale while shroudMats[0] == null");
                changeMaterial();
                return;
            }

            ShroudTexture shroudTex = ShroudTexture.shroudTextures[textureIndex];

            Vector2 sideSize = new Vector2(Mathf.Max(botWidth, topWidth), new Vector2(height, topWidth - botWidth).magnitude);
            Vector2 topSize  = new Vector2(topWidth, topWidth * thickness);

            shroudTex.textures[0].SetTextureScale(shroudMats[0], sideSize);
            shroudTex.textures[1].SetTextureScale(shroudMats[1], topSize);
            shroudTex.textures[2].SetTextureScale(shroudMats[2], sideSize);

            if (shroudGO == null)
            {
                return;
            }
            foreach (Renderer r in shroudGO.GetComponentsInChildren <Renderer>())
            {
                if (r.materials != shroudMats)
                {
                    foreach (Material mat in r.materials)
                    {
                        if (mat != null)
                        {
                            Destroy(mat);
                        }
                    }
                    r.materials = shroudMats;
                }
            }
        }
Esempio n. 8
0
        public static void LoadTextures()
        {
            if (surfaceTextures == null)
            {
                List <GameDatabase.TextureInfo> textures = GameDatabase.Instance.GetAllTexturesInFolder("DecouplerShroud/Textures/");
                surfaceTextures = new List <ShroudTexture>();

                foreach (ConfigNode texconf in GameDatabase.Instance.GetConfigNodes("ShroudTexture"))
                {
                    ShroudTexture tex = new ShroudTexture();
                    Debug.Log(texconf.GetValue("name"));
                    Debug.Log(texconf.GetValue("texture"));
                    Debug.Log(texconf.GetValue("normals"));

                    tex.name      = texconf.GetValue("name");
                    tex.texture   = GameDatabase.Instance.GetTexture(texconf.GetValue("texture"), false);
                    tex.normalMap = GameDatabase.Instance.GetTexture(texconf.GetValue("normals"), false);

                    surfaceTextures.Add(tex);
                }
            }
        }