/// <summary> /// Import additional custom components of material. /// </summary> /// <param name="archive">Archive index</param> /// <param name="record">Record index</param> /// <param name="frame">Texture frame</param> /// <param name="material">Material.</param> static public void CustomizeMaterial(int archive, int record, int frame, Material material) { // MetallicGloss map if (CustomMetallicGlossExist(archive, record, frame)) { material.EnableKeyword("_METALLICGLOSSMAP"); material.SetTexture("_MetallicGlossMap", LoadCustomMetallicGloss(archive, record, frame)); } // Properties if (XMLManager.XmlFileExist(archive, record, frame)) { string fileName = GetName(archive, record, frame); float value; // Metallic parameter if (XMLManager.TryGetFloat(fileName, "metallic", out value, texturesPath)) { material.SetFloat("_Metallic", value); } // Smoothness parameter if (XMLManager.TryGetFloat(fileName, "smoothness", out value, texturesPath)) { material.SetFloat("_Glossiness", value); } } }
/// <summary> /// Import custom texture and label settings for buttons /// </summary> /// <param name="button">Button</param> /// <param name="colorName">Name of texture</param> static public void SetCustomButton(ref Button button, string colorName) { // Load texture button.BackgroundTexture = LoadCustomTexture(colorName); button.BackgroundTexture.filterMode = (FilterMode)DaggerfallUnity.Settings.GUIFilterMode; // Load settings from Xml if (XMLManager.XmlFileExist(colorName, texturesPath)) { // Set custom color if (XMLManager.GetString(colorName, "customtext", texturesPath) == "true") { button.Label.TextColor = XMLManager.GetColor(colorName, texturesPath); } // Disable text. This is useful if text is drawn on texture else if (XMLManager.GetString(colorName, "customtext", texturesPath) == "notext") { button.Label.Text = ""; } } }
/// <summary> /// Set custom material on billboard gameobject. /// </summary> /// <paran name="go">Billboard gameobject.</param> /// <param name="archive">Archive index.</param> /// <param name="record">Record index.</param> static public void SetBillboardCustomMaterial(GameObject go, ref DaggerfallBillboard.BillboardSummary summary) { // Variables int numberOfFrames; int archive = summary.Archive; int record = summary.Record; string name = GetName(archive, record); var meshRenderer = go.GetComponent <MeshRenderer>(); Texture2D albedoTexture, emissionMap; // Check if billboard is emissive bool isEmissive = meshRenderer.material.GetTexture("_EmissionMap"); // UVs Vector2 uv = Vector2.zero; // Get properties from Xml if (XMLManager.XmlFileExist(archive, record)) { // Customize billboard size (scale) Transform transform = go.GetComponent <Transform>(); transform.localScale = XMLManager.GetScale(name, texturesPath, transform.localScale); summary.Size.x *= transform.localScale.x; summary.Size.y *= transform.localScale.y; // Get UV uv = XMLManager.GetUv(name, texturesPath, uv.x, uv.y); } // Update UV UpdateUV(go.GetComponent <MeshFilter>(), uv.x, uv.y); // Get material from cache or import from disk MaterialReader materialReader = DaggerfallUnity.Instance.MaterialReader; CachedMaterial cachedMaterialOut; if (materialReader.GetCachedMaterialCustomBillboard(archive, record, 0, out cachedMaterialOut)) { // Get and set material meshRenderer.material = cachedMaterialOut.material; // Get other properties numberOfFrames = cachedMaterialOut.singleFrameCount; albedoTexture = cachedMaterialOut.albedoMap; emissionMap = cachedMaterialOut.emissionMap; } else { // Get textures from disk LoadCustomBillboardFrameTexture(isEmissive, out albedoTexture, out emissionMap, archive, record); // Main texture meshRenderer.material.SetTexture("_MainTex", albedoTexture); // Emission maps for lights if (isEmissive) { meshRenderer.material.SetTexture("_EmissionMap", emissionMap); } // Get number of frames on disk numberOfFrames = NumberOfAvailableFrames(archive, record); // Save material in cache CachedMaterial newcm = new CachedMaterial() { albedoMap = albedoTexture, emissionMap = emissionMap, material = meshRenderer.material, singleFrameCount = numberOfFrames }; materialReader.SetCachedMaterialCustomBillboard(archive, record, 0, newcm); } // Import textures for each frame if billboard is animated summary.CustomBillboard = new CustomBillboard(); summary.CustomBillboard.isCustomAnimated = numberOfFrames > 1; if (summary.CustomBillboard.isCustomAnimated) { List <Texture2D> albedoTextures = new List <Texture2D>(); List <Texture2D> emissionmaps = new List <Texture2D>(); // Frame zero albedoTextures.Add(albedoTexture); if (isEmissive) { emissionmaps.Add(emissionMap); } // Other frames for (int frame = 1; frame < numberOfFrames; frame++) { if (materialReader.GetCachedMaterialCustomBillboard(archive, record, frame, out cachedMaterialOut)) { // Get textures from cache albedoTexture = cachedMaterialOut.albedoMap; emissionMap = cachedMaterialOut.emissionMap; } else { // Get textures from disk LoadCustomBillboardFrameTexture(isEmissive, out albedoTexture, out emissionMap, archive, record, frame); // Save textures in cache CachedMaterial newcm = new CachedMaterial() { albedoMap = albedoTexture, emissionMap = emissionMap, }; materialReader.SetCachedMaterialCustomBillboard(archive, record, frame, newcm); } albedoTextures.Add(albedoTexture); if (isEmissive) { emissionmaps.Add(emissionMap); } } // Set textures and properties summary.CustomBillboard.MainTexture = albedoTextures; summary.CustomBillboard.EmissionMap = emissionmaps; summary.CustomBillboard.NumberOfFrames = numberOfFrames; summary.CustomBillboard.isEmissive = isEmissive; } }