Ejemplo n.º 1
0
        public void SetTexture()
        {
            if (string.IsNullOrEmpty(transformName))
            {
                return;
            }
            WBITextureOption textureOption = textureOptions[selectedIndex];

            Transform[] targets;
            Texture2D   texture;
            Renderer    rendererMaterial;

            if (string.IsNullOrEmpty(textureOption.diffuseMap))
            {
                return;
            }

            //Get the targets
            targets = part.FindModelTransforms(transformName);
            if (targets == null)
            {
                Debug.Log("No targets found for " + transformName);
            }

            //Now, replace the textures in each target
            foreach (Transform target in targets)
            {
                rendererMaterial = target.GetComponent <Renderer>();

                texture = GameDatabase.Instance.GetTexture(textureOption.diffuseMap, false);
                if (texture != null)
                {
                    rendererMaterial.material.SetTexture("_MainTex", texture);
                }

                if (!string.IsNullOrEmpty(textureOption.normalMap))
                {
                    texture = GameDatabase.Instance.GetTexture(textureOption.normalMap, false);
                    if (texture != null)
                    {
                        rendererMaterial.material.SetTexture("_BumpMap", texture);
                    }
                }
            }

            //Get the next index to set the guiName with.
            if (textureOptions.Count > 0)
            {
                int nextIndex = (selectedIndex + 1) % this.textureOptions.Count;
                if (!string.IsNullOrEmpty(textureOptions[nextIndex].displayName))
                {
                    Events["SetNextTexture"].guiName = textureOptions[nextIndex].displayName;
                }
                else
                {
                    Events["SetNextTexture"].guiName = "Next Option";
                }
            }
        }
Ejemplo n.º 2
0
        protected void loadTextureOptions()
        {
            ConfigNode[]     textureOptionNodes;
            ConfigNode[]     nodes = this.part.partInfo.partConfig.GetNodes("MODULE");
            ConfigNode       node  = null;
            WBITextureOption textureOption;

            textureOptions.Clear();
            for (int index = 0; index < nodes.Length; index++)
            {
                node = nodes[index];
                if (node.HasValue("name"))
                {
                    moduleName = node.GetValue("name");
                    if (moduleName == this.ClassName)
                    {
                        if (node.HasNode("TEXTURE"))
                        {
                            textureOptionNodes = node.GetNodes("TEXTURE");
                            foreach (ConfigNode optionNode in textureOptionNodes)
                            {
                                textureOption = new WBITextureOption();
                                if (optionNode.HasValue("displayName"))
                                {
                                    textureOption.displayName = optionNode.GetValue("displayName");
                                }
                                if (optionNode.HasValue("diffuseMap"))
                                {
                                    textureOption.diffuseMap = optionNode.GetValue("diffuseMap");
                                }
                                if (optionNode.HasValue("normalMap"))
                                {
                                    textureOption.normalMap = optionNode.GetValue("normalMap");
                                }
                                textureOptions.Add(textureOption);
                            }
                        }
                        break;
                    }
                }
            }
        }