コード例 #1
0
    public void OnGUI()
    {
        if (gradient == null)
        {
            gradient = new Gradient();
        }
        EditorGUI.BeginChangeCheck();
        SerializedObject   serializedGradient = new SerializedObject(this);
        SerializedProperty colorGradient      = serializedGradient.FindProperty("gradient");

        EditorGUILayout.PropertyField(colorGradient, true, null);
        serializedGradient.ApplyModifiedProperties();

        int width  = 128;
        int height = 8;

        res = (resolutions)EditorGUILayout.EnumPopup("Resolution: ", res);

        switch (res)
        {
        case resolutions.Large512x8:
            width = 512;
            break;

        case resolutions.Medium256x8:
            width = 256;
            break;

        case resolutions.Small128x8:
            width = 128;
            break;

        case resolutions.Tiny64x8:
            width = 64;
            break;
        }

        if (gradient != null)
        {
            Texture2D tex = new Texture2D(width, height, TextureFormat.RGBA32, false);


            for (int y = 0; y < tex.height; y++)
            {
                for (int x = 0; x < tex.width; x++)
                {
                    tex.SetPixel(x, y, gradient.Evaluate((float)x / (float)width));
                }
            }


            XSStyles.Separator();
            if (GUILayout.Button("Save Ramp"))
            {
                XSStyles.findAssetPath(finalFilePath);
                string path = EditorUtility.SaveFilePanel("Save Ramp as PNG", finalFilePath + "/Textures/Shadow Ramps/Generated", "gradient.png", "png");
                if (path.Length != 0)
                {
                    GenTexture(tex, path);
                }
            }
        }

        XSStyles.HelpBox("You can use this to create a custom shadow ramp. \nYou must save the asset with the save button to apply changes. \n\n - Click the Gradient box. \n - Choose resolution. \n - Save. \n - Drag texture into slot.", MessageType.Info);
    }
コード例 #2
0
        public void OnGUI()
        {
            scrollPos = EditorGUILayout.BeginScrollView(scrollPos);

            GUILayout.BeginHorizontal();
            GUILayout.Space(105);
            XSStyles.doLabel("1");
            GUILayout.Space(105);
            XSStyles.doLabel("2");
            GUILayout.Space(105);
            XSStyles.doLabel("3");
            GUILayout.Space(105);
            XSStyles.doLabel("4");
            GUILayout.EndHorizontal();

            XSStyles.SeparatorThin();
            GUILayout.BeginHorizontal();
            for (int i = 0; i < 4; i++)
            {
                EditorGUIUtility.labelWidth = 0.01f;
                textures[i] = (Texture2D)EditorGUILayout.ObjectField(new GUIContent("", ""), textures[i], typeof(Texture2D), true);
            }
            GUILayout.EndHorizontal();

            float oldLabelWidth = EditorGUIUtility.labelWidth;

            EditorGUIUtility.labelWidth = 40;
            GUIStyle headerStyle = EditorStyles.boldLabel;

            headerStyle.alignment    = TextAnchor.UpperLeft;
            headerStyle.fontStyle    = FontStyle.Bold;
            headerStyle.stretchWidth = true;

            XSStyles.SeparatorThin();
            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("Output Channel:", headerStyle);

            GUILayout.Label("R", headerStyle);
            GUILayout.Label("G", headerStyle);
            GUILayout.Label("B", headerStyle);
            GUILayout.Label("A", headerStyle);
            EditorGUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Src Texture:");
            GUILayout.Space(20);
            for (int i = 0; i < 4; i++)
            {
                pickTexture[i] = (ETextures)EditorGUILayout.EnumPopup("", pickTexture[i]);
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Src Channel:");
            GUILayout.Space(17);
            for (int i = 0; i < 4; i++)
            {
                texChannels[i] = (EChannels)EditorGUILayout.EnumPopup("", texChannels[i]);
            }
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            GUILayout.Label("Invert Channel:");
            for (int i = 0; i < 4; i++)
            {
                invertChannel[i] = EditorGUILayout.Toggle("", invertChannel[i]);
            }
            GUILayout.EndHorizontal();

            GUILayout.Space(20);
            EditorGUILayout.EndScrollView();

            //Button and Resolution
            GUILayout.BeginVertical();
            XSStyles.doLabel("Resolution");

            GUILayout.BeginHorizontal();
            GUILayout.Space(175);
            res = (resolutions)EditorGUILayout.EnumPopup("", res);
            GUILayout.Space(175);
            GUILayout.EndHorizontal();

            if (GUILayout.Button("Merge Channels"))
            {
                if (progress < 2)
                {
                    EditorUtility.DisplayProgressBar("XSToon Texture Merger", "Merging and compressing new texture...", (float)(progress / 2));
                }

                //Set target textures to be ReadWriteable

                for (int i = 0; i < textures.Length; i++)
                {
                    if (textures[i] == null)
                    {
                        break;
                    }

                    string          texturePath = AssetDatabase.GetAssetPath(textures[i]);
                    TextureImporter texture     = (TextureImporter)TextureImporter.GetAtPath(texturePath);
                    if (texture != null)
                    {
                        texture.isReadable = true;
                        texture.SaveAndReimport();
                    }
                }

                switch (res)
                {
                case resolutions.Tiny_256x256:
                    resolution = 256;
                    break;

                case resolutions.Small_512x512:
                    resolution = 512;
                    break;

                case resolutions.Medium_1024x1024:
                    resolution = 1024;
                    break;

                case resolutions.Large_2048x2048:
                    resolution = 2048;
                    break;

                case resolutions.VeryLarge_4096x4096:
                    resolution = 4096;
                    break;

                case resolutions.Why_8192x8192:
                    resolution = 8192;
                    break;
                }

                XSStyles.findAssetPath(finalFilePath);
                finalFilePath = EditorUtility.SaveFilePanel("Save Merged Texture", finalFilePath + "/Textures/", "mergedTex.png", "png");


                Texture2D newTexture = new Texture2D(resolution, resolution, TextureFormat.RGBA32, false);

                //Get Colors textures and write them to the proper channel

                for (int y = 0; y < resolution; y++)
                {
                    for (int x = 0; x < resolution; x++)
                    {
                        float u = x / (float)resolution;
                        float v = y / (float)resolution;

                        // Grab out the texture values into an array for later lookup. Could probably just be done at the moment the texture color is needed.
                        for (int i = 0; i < textures.Length; i++)
                        {
                            if (textures[i] != null)
                            {
                                texColors[i] = textures[i].GetPixelBilinear(u, v);
                            }
                            else
                            {
                                texColors[i] = new Color(0, 0, 0, 1);
                            }
                        }

                        Color outputColor = new Color(0, 0, 0, 1);

                        // Iterate the output RGBA channels
                        for (int i = 0; i < 4; i++)
                        {
                            // Convert the enums to indices we can use. 'None' will turn into -1 which will be discarded as invalid.
                            int srcTexIdx     = ((int)pickTexture[i]) - 1;
                            int srcChannelIdx = ((int)texChannels[i]) - 1;

                            // Go through each channel in the output color and assign it
                            if (srcTexIdx >= 0 && srcChannelIdx >= 0)
                            {
                                outputColor[i] = texColors[srcTexIdx][srcChannelIdx];

                                //Allow you to invert specific channels.
                                if (invertChannel[i])
                                {
                                    outputColor[i] = 1f - outputColor[i];
                                }
                            }
                        }

                        newTexture.SetPixel(x, y, outputColor);
                    }
                }
                progress += 1;
                newTexture.Apply();
                ExportTexture(newTexture);
            }

            GUILayout.Space(10);
            GUILayout.EndVertical();



            EditorGUIUtility.labelWidth = oldLabelWidth;
        }
コード例 #3
0
 public void setResolution(resolutions r, bool fullScreen, bool resizeRoom = false)
 {
     switch (r)
     {
         case resolutions.AutoFullScreen:
             ScreenWidth = GraphicsDevice.Adapter.CurrentDisplayMode.Width;
             ScreenHeight = GraphicsDevice.Adapter.CurrentDisplayMode.Height;
             break;
         case resolutions.FHD_1920x1080:
             ScreenWidth = 1920; ScreenHeight = 1080; break;
         case resolutions.HD_1366x768:
             ScreenWidth = 1366; ScreenHeight = 768; break;
         case resolutions.SVGA_800x600:
             ScreenWidth = 800; ScreenHeight = 600; break;
         case resolutions.SXGA_1280x1024:
             ScreenWidth = 1280; ScreenHeight = 1024; break;
         case resolutions.VGA_640x480:
             ScreenWidth = 640; ScreenHeight = 480; break;
         case resolutions.WSXGA_1680x1050:
             ScreenWidth = 1680; ScreenHeight = 1050; break;
         case resolutions.WXGA_1280x800:
             ScreenWidth = 1280; ScreenHeight = 800; break;
         case resolutions.XGA_1024x768:
             ScreenWidth = 1024; ScreenHeight = 768; break;
     }
     Manager.Graphics.IsFullScreen = fullScreen;
     GraphicsReset = true;
 }