Esempio n. 1
0
        public override ConfigNode[] GetOptionNodes(string nodeName = kOptionNode)
        {
            ConfigNode[]        optionNodes = base.GetOptionNodes(nodeName);
            TextureSwitchOption option;

            textureOptions.Clear();
            foreach (ConfigNode node in optionNodes)
            {
                option = new TextureSwitchOption();

                option.displayName = node.GetValue("name");

                if (node.HasValue("diffuseMap") == false)
                {
                    continue;
                }
                option.diffuseMap = node.GetValue("diffuseMap");

                if (node.HasValue("normalMap"))
                {
                    option.normalMap = node.GetValue("normalMap");
                }

                textureOptions.Add(option.displayName, option);
            }

            return(optionNodes);
        }
Esempio n. 2
0
        public void SetTexture()
        {
            if (string.IsNullOrEmpty(transformName))
            {
                return;
            }
            TextureSwitchOption textureOption = textureOptions[optionNames[currentOptionIndex]];

            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);
                    }
                }
            }
        }