Exemplo n.º 1
0
        /// <summary>
        /// Gets terrain albedo texture array containing each terrain tile in a seperate array slice.
        /// </summary>
        /// <param name="archive">Archive index.</param>
        /// <param name="stayReadable">Texture should stay readable.</param>
        /// <param name="nonAlphaFormat">Non-alpha TextureFormat.</param>
        /// <returns>Texture2DArray or null</returns>
        public Texture2DArray GetTerrainAlbedoTextureArray(
            int archive,
            bool stayReadable = false,
            SupportedNonAlphaTextureFormats nonAlphaFormat = SupportedNonAlphaTextureFormats.RGB24)
        {
            // Load texture file and check count matches terrain tiles
            TextureFile textureFile = new TextureFile(Path.Combine(Arena2Path, TextureFile.IndexToFileName(archive)), FileUsage.UseMemory, true);
            int         numSlices   = 0;

            if (textureFile.RecordCount == 56)
            {
                numSlices = textureFile.RecordCount;
            }
            else
            {
                return(null);
            }

            Texture2DArray textureArray;

            if (TextureReplacement.CustomTextureExist(archive, 0, 0))
            {
                Texture2D albedoMap = TextureReplacement.LoadCustomTexture(archive, 0, 0);
                textureArray = new Texture2DArray(albedoMap.width, albedoMap.height, numSlices, ParseTextureFormat(nonAlphaFormat), MipMaps);
            }
            else
            {
                textureArray = new Texture2DArray(textureFile.GetWidth(0), textureFile.GetWidth(1), numSlices, ParseTextureFormat(nonAlphaFormat), MipMaps);
            }

            // Rollout tiles into texture array
            for (int record = 0; record < textureFile.RecordCount; record++)
            {
                Color32[] albedo;

                if (TextureReplacement.CustomTextureExist(archive, record, 0))
                {
                    // Import custom texture
                    Texture2D albedoMap = TextureReplacement.LoadCustomTexture(archive, record, 0);
                    albedo = albedoMap.GetPixels32();
                }
                else
                {
                    // Create base image with gutter
                    DFSize sz;
                    albedo = textureFile.GetColor32(record, 0, -1, 0, out sz);
                }

                // Insert into texture array
                textureArray.SetPixels32(albedo, record, 0);
            }
            textureArray.Apply(true, !stayReadable);

            // Change settings for these textures
            textureArray.wrapMode   = TextureWrapMode.Clamp;
            textureArray.anisoLevel = 8;

            return(textureArray);
        }
Exemplo n.º 2
0
 void LoadAssets()
 {
     if (TextureReplacement.CustomTextureExist(defaultCrosshairFilename))
     {
         CrosshairTexture = TextureReplacement.LoadCustomTexture(defaultCrosshairFilename);
     }
     else
     {
         CrosshairTexture = Resources.Load <Texture2D>(defaultCrosshairFilename);
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Gets Unity textures from Daggerfall texture with all options.
        /// Returns all supported texture maps for Standard shader in one call.
        /// </summary>
        /// <param name="settings">Get texture settings.</param>
        /// <param name="alphaTextureFormat">Alpha TextureFormat.</param>
        /// <param name="nonAlphaFormat">Non-alpha TextureFormat.</param>
        /// <param name="allowImport">Import texture from disk if present.</param>
        /// <returns>GetTextureResults.</returns>
        public GetTextureResults GetTexture2D(
            GetTextureSettings settings,
            SupportedAlphaTextureFormats alphaTextureFormat = SupportedAlphaTextureFormats.RGBA32,
            SupportedNonAlphaTextureFormats nonAlphaFormat  = SupportedNonAlphaTextureFormats.RGB24,
            bool allowImport = true)
        {
            GetTextureResults results = new GetTextureResults();

            // Check if window or auto-emissive
            bool isWindow   = ClimateSwaps.IsExteriorWindow(settings.archive, settings.record);
            bool isEmissive = (settings.autoEmission) ? IsEmissive(settings.archive, settings.record) : false;

            // Override readable flag when user has set preference in material reader
            if (DaggerfallUnity.Instance.MaterialReader.ReadableTextures)
            {
                settings.stayReadable = true;
            }

            // Assign texture file
            TextureFile textureFile;

            if (settings.textureFile == null)
            {
                textureFile = new TextureFile(Path.Combine(Arena2Path, TextureFile.IndexToFileName(settings.archive)), FileUsage.UseMemory, true);
            }
            else
            {
                textureFile = settings.textureFile;
            }

            // Get starting DFBitmap and albedo Color32 array
            DFSize   sz;
            DFBitmap srcBitmap = textureFile.GetDFBitmap(settings.record, settings.frame);

            Color32[] albedoColors = textureFile.GetColor32(srcBitmap, settings.alphaIndex, settings.borderSize, out sz);

            // Sharpen source image
            if (settings.sharpen)
            {
                albedoColors = ImageProcessing.Sharpen(ref albedoColors, sz.Width, sz.Height);
            }

            // Dilate edges
            if (settings.borderSize > 0 && settings.dilate && !settings.copyToOppositeBorder)
            {
                ImageProcessing.DilateColors(ref albedoColors, sz);
            }

            // Copy to opposite border
            if (settings.borderSize > 0 && settings.copyToOppositeBorder)
            {
                ImageProcessing.WrapBorder(ref albedoColors, sz, settings.borderSize);
            }

            // Set albedo texture
            Texture2D albedoMap = null;

            if (allowImport && TextureReplacement.CustomTextureExist(settings.archive, settings.record, settings.frame))
            {
                // Import albedo texture
                albedoMap = TextureReplacement.LoadCustomTexture(settings.archive, settings.record, settings.frame);
            }
            else
            {
                // Create albedo texture
                if (settings.alphaIndex < 0)
                {
                    albedoMap = new Texture2D(sz.Width, sz.Height, ParseTextureFormat(nonAlphaFormat), MipMaps);
                }
                else
                {
                    albedoMap = new Texture2D(sz.Width, sz.Height, ParseTextureFormat(alphaTextureFormat), MipMaps);
                }
                albedoMap.SetPixels32(albedoColors);
                albedoMap.Apply(true, !settings.stayReadable);
            }

            // Set normal texture
            Texture2D normalMap = null;

            if (allowImport && TextureReplacement.CustomNormalExist(settings.archive, settings.record, settings.frame))
            {
                // Always import normal if present on disk
                normalMap = TextureReplacement.LoadCustomNormal(settings.archive, settings.record, settings.frame);
            }
            else if (settings.createNormalMap && textureFile.SolidType == TextureFile.SolidTypes.None)
            {
                // Create normal texture - must be ARGB32
                // Normal maps are bypassed for solid-colour textures
                Color32[] normalColors;
                normalColors = ImageProcessing.GetBumpMap(ref albedoColors, sz.Width, sz.Height);
                normalColors = ImageProcessing.ConvertBumpToNormals(ref normalColors, sz.Width, sz.Height, settings.normalStrength);
                normalMap    = new Texture2D(sz.Width, sz.Height, TextureFormat.ARGB32, MipMaps);
                normalMap.SetPixels32(normalColors);
                normalMap.Apply(true, !settings.stayReadable);
            }

            // Import emission map or create basic emissive texture
            Texture2D emissionMap    = null;
            bool      resultEmissive = false;

            if (allowImport && TextureReplacement.CustomEmissionExist(settings.archive, settings.record, settings.frame))
            {
                // Always import emission if present on disk
                emissionMap    = TextureReplacement.LoadCustomEmission(settings.archive, settings.record, settings.frame);
                resultEmissive = true;
            }
            else
            {
                if (settings.createEmissionMap || (settings.autoEmission && isEmissive) && !isWindow)
                {
                    // Just reuse albedo map for basic colour emission
                    emissionMap    = albedoMap;
                    resultEmissive = true;
                }

                // Windows need special handling as only glass parts are emissive
                if ((settings.createEmissionMap || settings.autoEmissionForWindows) && isWindow)
                {
                    // Create custom emission texture for glass area of windows
                    Color32[] emissionColors = textureFile.GetWindowColors32(srcBitmap);
                    emissionMap = new Texture2D(sz.Width, sz.Height, ParseTextureFormat(alphaTextureFormat), MipMaps);
                    emissionMap.SetPixels32(emissionColors);
                    emissionMap.Apply(true, !settings.stayReadable);
                    resultEmissive = true;
                }

                // Lights need special handling as this archive contains a mix of emissive and non-emissive flats
                // This can cause problems with atlas packing due to mismatch between albedo and emissive texture counts
                if ((settings.createEmissionMap || settings.autoEmission) && settings.archive == LightsTextureArchive)
                {
                    // For the unlit flats we create a null-emissive black texture
                    if (!isEmissive)
                    {
                        Color32[] emissionColors = new Color32[sz.Width * sz.Height];
                        emissionMap = new Texture2D(sz.Width, sz.Height, ParseTextureFormat(alphaTextureFormat), MipMaps);
                        emissionMap.SetPixels32(emissionColors);
                        emissionMap.Apply(true, !settings.stayReadable);
                        resultEmissive = true;
                    }
                }
            }

            // Shrink UV rect to compensate for internal border
            float ru = 1f / sz.Width;
            float rv = 1f / sz.Height;

            results.singleRect = new Rect(
                settings.borderSize * ru,
                settings.borderSize * rv,
                (sz.Width - settings.borderSize * 2) * ru,
                (sz.Height - settings.borderSize * 2) * rv);

            // Store results
            results.albedoMap   = albedoMap;
            results.normalMap   = normalMap;
            results.emissionMap = emissionMap;
            results.isWindow    = isWindow;
            results.isEmissive  = resultEmissive;
            results.textureFile = textureFile;

            return(results);
        }
Exemplo n.º 4
0
        protected override void Setup()
        {
            // Main panel
            mainPanel.HorizontalAlignment = HorizontalAlignment.Center;
            mainPanel.VerticalAlignment   = VerticalAlignment.Middle;
            mainPanel.Size            = mainPanelSize;
            mainPanel.Outline.Enabled = true;
            if (TextureReplacement.CustomTextureExist("mainPanelBackgroundColor"))
            {
                mainPanel.BackgroundTexture = TextureReplacement.LoadCustomTexture("mainPanelBackgroundColor");
            }
            else
            {
                mainPanel.BackgroundColor = mainPanelBackgroundColor;
            }
            NativePanel.Components.Add(mainPanel);

            // Prompt
            promptLabel.ShadowPosition = Vector2.zero;
            promptLabel.Position       = new Vector2(4, 4);
            mainPanel.Components.Add(promptLabel);

            // Name panel
            Panel namePanel = new Panel();

            namePanel.Position        = new Vector2(4, 12);
            namePanel.Size            = new Vector2(272, 9);
            namePanel.Outline.Enabled = true;
            if (TextureReplacement.CustomTextureExist("namePanelBackgroundColor"))
            {
                namePanel.BackgroundTexture = TextureReplacement.LoadCustomTexture("namePanelBackgroundColor");
            }
            else
            {
                namePanel.BackgroundColor = namePanelBackgroundColor;
            }
            mainPanel.Components.Add(namePanel);

            // Name input
            saveNameTextBox.Position      = new Vector2(2, 2);
            saveNameTextBox.MaxCharacters = 26;
            saveNameTextBox.OnType       += SaveNameTextBox_OnType;
            namePanel.Components.Add(saveNameTextBox);

            // Save panel
            Panel savesPanel = new Panel();

            savesPanel.Position        = new Vector2(4, 25);
            savesPanel.Size            = new Vector2(100, 141);
            savesPanel.Outline.Enabled = true;
            mainPanel.Components.Add(savesPanel);

            // Save list
            savesList.Position  = new Vector2(2, 2);
            savesList.Size      = new Vector2(91, 129);
            savesList.TextColor = savesListTextColor;
            if (TextureReplacement.CustomTextureExist("savesListBackgroundColor"))
            {
                savesList.BackgroundTexture = TextureReplacement.LoadCustomTexture("savesListBackgroundColor");
            }
            else
            {
                savesList.BackgroundColor = savesListBackgroundColor;
            }
            savesList.ShadowPosition      = Vector2.zero;
            savesList.RowsDisplayed       = 16;
            savesList.OnScroll           += SavesList_OnScroll;
            savesList.OnSelectItem       += SavesList_OnSelectItem;
            savesList.OnMouseDoubleClick += SaveLoadEventHandler;
            savesPanel.Components.Add(savesList);

            // Save scroller
            savesScroller.Position     = new Vector2(94, 2);
            savesScroller.Size         = new Vector2(5, 129);
            savesScroller.DisplayUnits = 16;
            savesScroller.OnScroll    += SavesScroller_OnScroll;
            savesPanel.Components.Add(savesScroller);

            // Save/Load button
            goButton.Position          = new Vector2(108, 150);
            goButton.Size              = new Vector2(40, 16);
            goButton.Label.ShadowColor = Color.black;
            if (TextureReplacement.CustomTextureExist("saveButtonBackgroundColor"))
            {
                TextureReplacement.SetCustomButton(ref goButton, "saveButtonBackgroundColor");
            }
            else
            {
                goButton.BackgroundColor = saveButtonBackgroundColor;
            }
            goButton.Outline.Enabled = true;
            goButton.OnMouseClick   += SaveLoadEventHandler;
            mainPanel.Components.Add(goButton);

            // Switch to classic save window button
            switchClassicButton.Position   = new Vector2(172, 150);
            switchClassicButton.Size       = new Vector2(40, 16);
            switchClassicButton.Label.Text = "Classic";
            //switchClassicButton.Label.TextColor = new Color(0.6f, 0.3f, 0.6f);
            switchClassicButton.Label.ShadowColor = Color.black;
            if (TextureReplacement.CustomTextureExist("switchClassicButtonBackgroundColor"))
            {
                TextureReplacement.SetCustomButton(ref switchClassicButton, "switchClassicButtonBackgroundColor");
            }
            else
            {
                switchClassicButton.BackgroundColor = new Color(0.2f, 0.2f, 0);
            }
            switchClassicButton.Outline.Enabled = true;
            switchClassicButton.OnMouseClick   += SwitchClassicButton_OnMouseClick;
            mainPanel.Components.Add(switchClassicButton);

            // Cancel button
            Button cancelButton = new Button();

            cancelButton.Position          = new Vector2(236, 150);
            cancelButton.Size              = new Vector2(40, 16);
            cancelButton.Label.Text        = "Cancel";
            cancelButton.Label.ShadowColor = Color.black;
            if (TextureReplacement.CustomTextureExist("cancelButtonBackgroundColor"))
            {
                TextureReplacement.SetCustomButton(ref cancelButton, "cancelButtonBackgroundColor");
            }
            else
            {
                cancelButton.BackgroundColor = cancelButtonBackgroundColor;
            }
            cancelButton.Outline.Enabled = true;
            cancelButton.OnMouseClick   += CancelButton_OnMouseClick;
            mainPanel.Components.Add(cancelButton);

            // Screenshot panel
            screenshotPanel.Position = new Vector2(108, 25);
            screenshotPanel.Size     = new Vector2(168, 95);
            screenshotPanel.BackgroundTextureLayout = BackgroundLayout.ScaleToFit;
            if (TextureReplacement.CustomTextureExist("screenshotPanelBackgroundColor"))
            {
                screenshotPanel.BackgroundTexture = TextureReplacement.LoadCustomTexture("screenshotPanelBackgroundColor");
            }
            else
            {
                screenshotPanel.BackgroundColor = savesListBackgroundColor;
            }
            screenshotPanel.Outline.Enabled = true;
            mainPanel.Components.Add(screenshotPanel);

            // Info panel
            Panel infoPanel = new Panel();

            infoPanel.Position = new Vector2(108, 122);
            infoPanel.Size     = new Vector2(168, 26);
            mainPanel.Components.Add(infoPanel);

            // Save version
            saveVersionLabel.ShadowColor = Color.black;
            saveVersionLabel.Position    = new Vector2(1, 1);
            saveVersionLabel.TextColor   = saveFolderColor;
            screenshotPanel.Components.Add(saveVersionLabel);

            // Save folder
            saveFolderLabel.ShadowColor         = Color.black;
            saveFolderLabel.HorizontalAlignment = HorizontalAlignment.Right;
            saveFolderLabel.Position            = new Vector2(0, 1);
            saveFolderLabel.TextColor           = saveFolderColor;
            screenshotPanel.Components.Add(saveFolderLabel);

            // Time labels
            saveTimeLabel.ShadowPosition      = Vector2.zero;
            saveTimeLabel.HorizontalAlignment = HorizontalAlignment.Center;
            saveTimeLabel.Position            = new Vector2(0, 0);
            infoPanel.Components.Add(saveTimeLabel);
            gameTimeLabel.ShadowPosition      = Vector2.zero;
            gameTimeLabel.HorizontalAlignment = HorizontalAlignment.Center;
            gameTimeLabel.Position            = new Vector2(0, 9);
            infoPanel.Components.Add(gameTimeLabel);

            // Delete save button
            deleteSaveButton.Position            = new Vector2(0, 132);
            deleteSaveButton.Size                = new Vector2(98, 8);
            deleteSaveButton.HorizontalAlignment = HorizontalAlignment.Center;
            deleteSaveButton.Label.Text          = "Delete Save";
            deleteSaveButton.Label.ShadowColor   = Color.black;
            if (TextureReplacement.CustomTextureExist("deleteSaveButtonBackgroundColor"))
            {
                TextureReplacement.SetCustomButton(ref deleteSaveButton, "deleteSaveButtonBackgroundColor");
            }
            else
            {
                deleteSaveButton.BackgroundColor = namePanelBackgroundColor;
            }
            deleteSaveButton.Outline.Enabled = false;
            deleteSaveButton.OnMouseClick   += DeleteSaveButton_OnMouseClick;
            savesPanel.Components.Add(deleteSaveButton);

            // Switch character button
            switchCharButton.Position          = new Vector2(216, 2);
            switchCharButton.Size              = new Vector2(60, 8);
            switchCharButton.Label.Text        = "Switch Char";
            switchCharButton.Label.ShadowColor = Color.black;
            if (TextureReplacement.CustomTextureExist("switchCharButtonBackgroundColor"))
            {
                TextureReplacement.SetCustomButton(ref switchCharButton, "switchCharButtonBackgroundColor");
            }
            else
            {
                switchCharButton.BackgroundColor = saveButtonBackgroundColor;
            }
            switchCharButton.OnMouseClick += SwitchCharButton_OnMouseClick;
            mainPanel.Components.Add(switchCharButton);
        }