コード例 #1
0
ファイル: Replacer.cs プロジェクト: cydonian-monk/KSP-DiRT
        // General texture replacement step.
        void replaceTextures()
        {
            foreach (Material material in Resources.FindObjectsOfTypeAll <Material>())
            {
                // Only get the main texture if this object has one.
                if (material.HasProperty(Shader.PropertyToID("_MainTex")))
                {
                    Texture texture = material.mainTexture;

                    if (texture == null || texture.name.Length == 0 || texture.name.StartsWith("Temp", StringComparison.Ordinal))
                    {
                        continue;
                    }

                    Texture2D newTexture;
                    mappedTextures.TryGetValue(texture.name, out newTexture);

                    if (newTexture != null)
                    {
                        if (newTexture != texture)
                        {
                            newTexture.anisoLevel = texture.anisoLevel;
                            newTexture.wrapMode   = texture.wrapMode;

                            material.mainTexture = newTexture;
                            UnityEngine.Object.Destroy(texture);

                            DiRT.log("Replaced texture " + material.mainTexture.name);
                        }
                    }
                }

                if (material.HasProperty(BUMPMAP_PROPERTY))
                {
                    Texture normalMap = material.GetTexture(BUMPMAP_PROPERTY);
                    if (normalMap == null)
                    {
                        continue;
                    }
                    Texture2D newNormalMap;
                    mappedTextures.TryGetValue(normalMap.name, out newNormalMap);

                    if (newNormalMap != null)
                    {
                        if (newNormalMap != normalMap)
                        {
                            newNormalMap.anisoLevel = normalMap.anisoLevel;
                            newNormalMap.wrapMode   = normalMap.wrapMode;

                            material.SetTexture(BUMPMAP_PROPERTY, newNormalMap);
                            UnityEngine.Object.Destroy(normalMap);

                            DiRT.log("Replaced normalMap " + newNormalMap.name);
                        }
                    }
                }
            }
        }
コード例 #2
0
ファイル: Replacer.cs プロジェクト: cydonian-monk/KSP-DiRT
        // Read configuration and perform pre-load initialisation.
        public void readConfig(ConfigNode configFile)
        {
            string newPath = configFile.GetValue("TextureFolder");

            if ((null != newPath) &&
                (!texturePaths.Contains(newPath)))
            {
                texturePaths.Add(newPath);
                DiRT.log("Added texture path: " + newPath);
            }
            string exportNode = configFile.GetValue("exportTextureNames");

            if ((null != exportNode) &&
                (exportNode.ToLower().Equals("true")))
            {
                DiRT.log("Will export texture names.");
                doExportTextureNames = true;
            }
        }
コード例 #3
0
        public void Awake()
        {
            DontDestroyOnLoad(this);
            DiRT.log("Awake {0}", Assembly.GetExecutingAssembly().GetName().Version);

            Replacer.instance = new Replacer();

            myConfigs = GameDatabase.Instance.GetConfigs(DIRT_CONFIG);
            if (myConfigs.Length < 1)
            {
                DiRT.log("No DiRT Config found. Using default path: " + REPLACE_TEXTURES);
            }
            foreach (UrlDir.UrlConfig configFile in myConfigs)
            {
                Replacer.instance.readConfig(configFile.config);
            }
            if (Replacer.doExportTextureNames)
            {
                Replacer.instance.exportTextureNames();
            }
        }
コード例 #4
0
 public void Start()
 {
     DiRT.log("Start {0}", Assembly.GetExecutingAssembly().GetName().Version);
     Replacer.instance.load();
     isReplacerLoaded = true;
 }