Example #1
0
        public static void DrawElement(SerializedProperty property)
        {
            var rect  = P3dHelper.Reserve();
            var rectA = rect; rectA.width = EditorGUIUtility.labelWidth;
            var rectB = rect; rectB.xMin += EditorGUIUtility.labelWidth; rectB.xMax -= 52.0f;
            var rectC = rect; rectC.xMin += EditorGUIUtility.labelWidth; rectC.xMin = rectC.xMax - 50.0f;

            EditorGUI.LabelField(rectA, new GUIContent(property.name, property.tooltip));

            P3dGroup_Drawer.Draw(rectB, property.FindPropertyRelative("SourceGroup"));

            EditorGUI.PropertyField(rectC, property.FindPropertyRelative("SourceChannel"), GUIContent.none);
        }
Example #2
0
        public void OnGUI()
        {
            Technique = (P3dWindowBrushTechnique)EditorGUILayout.EnumPopup("Technique", Technique);

            EditorGUI.indentLevel++;
            switch (Technique)
            {
            case P3dWindowBrushTechnique.Replace:
            {
                P3dGroup_Drawer.OnGUI(P3dHelper.Reserve(), this, new GUIContent("Group"));
                Texture = EditorGUI.ObjectField(P3dHelper.Reserve(), "Texture", Texture, typeof(Texture), false) as Texture;
                Color   = EditorGUILayout.ColorField("Color", Color);
                Opacity = EditorGUILayout.Slider("Opacity", Opacity, 0.0f, 1.0f);
            }
            break;

            case P3dWindowBrushTechnique.Fill:
            {
                P3dGroup_Drawer.OnGUI(P3dHelper.Reserve(), this, new GUIContent("Group"));
                BlendMode = (P3dBlendMode)EditorGUILayout.EnumPopup("Blend Mode", BlendMode);
                Texture   = EditorGUI.ObjectField(P3dHelper.Reserve(), "Texture", Texture, typeof(Texture), false) as Texture;
                Color     = EditorGUILayout.ColorField("Color", Color);
                Opacity   = EditorGUILayout.Slider("Opacity", Opacity, 0.0f, 1.0f);
            }
            break;

            case P3dWindowBrushTechnique.Sphere:
            {
                P3dGroup_Drawer.OnGUI(P3dHelper.Reserve(), this, new GUIContent("Group"));
                BlendMode = (P3dBlendMode)EditorGUILayout.EnumPopup("Blend Mode", BlendMode);
                Color     = EditorGUILayout.ColorField("Color", Color);
                Opacity   = EditorGUILayout.Slider("Opacity", Opacity, 0.0f, 1.0f);
                Radius    = EditorGUILayout.FloatField("Radius", Radius);
                Hardness  = EditorGUILayout.FloatField("Hardness", Hardness);
            }
            break;

            case P3dWindowBrushTechnique.Decal:
            {
                P3dGroup_Drawer.OnGUI(P3dHelper.Reserve(), this, new GUIContent("Group"));
                BlendMode = (P3dBlendMode)EditorGUILayout.EnumPopup("Blend Mode", BlendMode);
                P3dHelper.BeginColor(Texture == null);
                Texture = EditorGUI.ObjectField(P3dHelper.Reserve(), "Texture", Texture, typeof(Texture), false) as Texture;
                P3dHelper.EndColor();
                if (BlendMode == P3dBlendMode.Replace)
                {
                    P3dHelper.BeginColor(Shape == null);
                    Shape = EditorGUI.ObjectField(P3dHelper.Reserve(), "Shape", Shape, typeof(Texture), false) as Texture;
                    P3dHelper.EndColor();
                }
                Color       = EditorGUILayout.ColorField("Color", Color);
                Opacity     = EditorGUILayout.Slider("Opacity", Opacity, 0.0f, 1.0f);
                Radius      = EditorGUILayout.FloatField("Radius", Radius);
                Angle       = EditorGUILayout.FloatField("Angle", Angle);
                Depth       = EditorGUILayout.FloatField("Depth", Depth);
                Hardness    = EditorGUILayout.FloatField("Hardness", Hardness);
                NormalFront = EditorGUILayout.Slider("Normal Front", NormalFront, 0.0f, 1.0f);
                NormalBack  = EditorGUILayout.Slider("Normal Back", NormalBack, 0.0f, 1.0f);
                NormalRange = EditorGUILayout.Slider("Normal Range", NormalRange, 0.001f, 0.25f);
            }
            break;

            case P3dWindowBrushTechnique.SphereTriplanar:
            {
                P3dGroup_Drawer.OnGUI(P3dHelper.Reserve(), this, new GUIContent("Group"));
                BlendMode = (P3dBlendMode)EditorGUILayout.EnumPopup("Blend Mode", BlendMode);
                P3dHelper.BeginColor(Texture == null);
                Texture = EditorGUI.ObjectField(P3dHelper.Reserve(), "Texture", Texture, typeof(Texture), false) as Texture;
                P3dHelper.EndColor();
                Strength = EditorGUILayout.FloatField("Strength", Strength);
                Tiling   = EditorGUILayout.FloatField("Tiling", Tiling);
                Color    = EditorGUILayout.ColorField("Color", Color);
                Opacity  = EditorGUILayout.Slider("Opacity", Opacity, 0.0f, 1.0f);
                Radius   = EditorGUILayout.FloatField("Radius", Radius);
                Hardness = EditorGUILayout.FloatField("Hardness", Hardness);
            }
            break;

            case P3dWindowBrushTechnique.SphereBlur:
            {
                P3dGroup_Drawer.OnGUI(P3dHelper.Reserve(), this, new GUIContent("Group"));
                Opacity    = EditorGUILayout.Slider("Opacity", Opacity, 0.0f, 1.0f);
                KernelSize = EditorGUILayout.Slider("Kernel Size", KernelSize, 0.0001f, 0.1f);
                Radius     = EditorGUILayout.FloatField("Radius", Radius);
                Hardness   = EditorGUILayout.FloatField("Hardness", Hardness);
            }
            break;
            }
            EditorGUI.indentLevel--;
        }
Example #3
0
        private Texture DrawObject(P3dWindowPaintableTexture paintableTexture, Material material, Texture texture)
        {
            if (texture != null)
            {
                var texture2D = texture as Texture2D;

                if (texture2D != null)
                {
                    EditorGUI.BeginDisabledGroup(paintableTexture.Locked == true);
                    if (material.hideFlags != HideFlags.None)
                    {
                        EditorGUILayout.HelpBox("This may be a shared texture, so you should clone it before modification.", MessageType.Warning);
                    }

                    if (GUILayout.Button("Clone") == true)
                    {
                        texture = texture2D = Instantiate(texture2D);
                    }

                    var textureImporter = P3dHelper.GetAssetImporter <TextureImporter>(texture);

                    if (textureImporter != null)
                    {
                        if (textureImporter.isReadable == false)
                        {
                            EditorGUILayout.HelpBox("This texture's import settings does not have Read/Write Enabled.", MessageType.Error);

                            P3dHelper.BeginColor(Color.green);
                            if (GUILayout.Button("Enable Read/Write") == true)
                            {
                                textureImporter.isReadable = true;

                                textureImporter.SaveAndReimport();
                            }
                            P3dHelper.EndColor();
                        }
                    }
                    else
                    {
                        changeFormat = EditorGUILayout.Foldout(changeFormat, "Change Format");

                        if (changeFormat == true)
                        {
                            EditorGUI.BeginDisabledGroup(true);
                            EditorGUILayout.EnumPopup("Current Format", texture2D.format, EditorStyles.popup);
                            EditorGUI.EndDisabledGroup();

                            changeFormatNew = (TextureFormat)EditorGUILayout.EnumPopup("New Format", changeFormatNew, EditorStyles.popup);

                            P3dHelper.BeginColor(Color.green);
                            if (GUI.Button(P3dHelper.Reserve(), "Change Format") == true)
                            {
                                var newTexture2D = new Texture2D(texture2D.width, texture2D.height, changeFormatNew, texture2D.mipmapCount > 0);

                                changeFormatFailed = true;

                                if (CanReadWrite(newTexture2D) == true)
                                {
                                    var readableTexture = P3dHelper.GetReadableCopy(texture2D);
                                    var pixels          = readableTexture.GetPixels32();

                                    P3dHelper.Destroy(readableTexture);

                                    newTexture2D.name = texture2D.name;
                                    newTexture2D.SetPixels32(pixels);
                                    newTexture2D.Apply();

                                    texture            = texture2D = newTexture2D;
                                    changeFormat       = false;
                                    changeFormatFailed = false;
                                }
                            }
                            P3dHelper.EndColor();

                            if (changeFormatFailed == true)
                            {
                                EditorGUILayout.HelpBox("Failed to change format. This means the format you tried to use is not readable.", MessageType.Error);
                            }
                        }

                        changeSize = EditorGUILayout.Foldout(changeSize, "Change Size");

                        if (changeSize == true)
                        {
                            EditorGUI.BeginDisabledGroup(true);
                            EditorGUILayout.IntField("Current Width", texture2D.width);
                            EditorGUILayout.IntField("Current Height", texture2D.height);
                            EditorGUI.EndDisabledGroup();
                            changeWidth  = EditorGUILayout.IntField("Width", changeWidth);
                            changeHeight = EditorGUILayout.IntField("Height", changeHeight);

                            P3dHelper.BeginColor(Color.green);
                            if (GUILayout.Button("Change Size") == true)
                            {
                                var newTexture2D = new Texture2D(changeWidth, changeHeight, texture2D.format, texture2D.mipmapCount > 0);

                                changeSizeFailed = true;

                                if (CanReadWrite(newTexture2D) == true)
                                {
                                    var readableTexture = P3dHelper.GetReadableCopy(texture2D, TextureFormat.ARGB32, false, changeWidth, changeHeight);
                                    var pixels          = readableTexture.GetPixels32();

                                    P3dHelper.Destroy(readableTexture);

                                    newTexture2D.name = texture2D.name;
                                    newTexture2D.SetPixels32(pixels);
                                    newTexture2D.Apply();

                                    texture          = texture2D = newTexture2D;
                                    changeSize       = false;
                                    changeSizeFailed = false;
                                }
                            }
                            P3dHelper.EndColor();

                            if (changeSizeFailed == true)
                            {
                                EditorGUILayout.HelpBox("Failed to change size. Either the texture format is non-readable, or the texture size you chose is invalid.", MessageType.Error);
                            }
                        }
                    }

                    if (P3dHelper.IsAsset(material) == true && P3dHelper.IsAsset(texture) == false)
                    {
                        EditorGUILayout.HelpBox("This texture is stored in the scene, but it's applied to a material that's stored in an asset. You should save the texture as an asset too, otherwise it won't work properly.", MessageType.Warning);
                    }

                    if (P3dHelper.IsAsset(texture) == false)
                    {
                        if (GUILayout.Button("Save As Texture2D Asset") == true)
                        {
                            var path = P3dHelper.SaveDialog("Save Texture As Asset", "Assets", texture.name, "asset");

                            if (string.IsNullOrEmpty(path) == false)
                            {
                                AssetDatabase.CreateAsset(texture, path);
                            }
                        }

                        if (GUILayout.Button("Save As Png Asset") == true)
                        {
                            var path = P3dHelper.SaveDialog("Export Texture", "Assets", texture.name, "png");

                            if (string.IsNullOrEmpty(path) == false)
                            {
                                P3dHelper.SaveTextureAsset(texture, path, true);

                                var newTexture2D = (Texture2D)AssetDatabase.LoadAssetAtPath(path, typeof(Texture2D));

                                if (newTexture2D != null)
                                {
                                    //ClearUndo();

                                    var importer = P3dHelper.GetAssetImporter <TextureImporter>(newTexture2D);

                                    importer.isReadable         = true;
                                    importer.textureCompression = TextureImporterCompression.Uncompressed;
                                    importer.filterMode         = FilterMode.Trilinear;
                                    importer.anisoLevel         = 8;
                                    importer.SaveAndReimport();

                                    texture = texture2D = newTexture2D;

                                    P3dHelper.SetDirty(this);
                                }
                            }
                        }
                    }
                    EditorGUI.EndDisabledGroup();

                    if (paintableTexture.Locked == true)
                    {
                        EditorGUILayout.BeginHorizontal();
                        P3dHelper.BeginColor(Color.red);
                        if (GUILayout.Button("Unlock", GUILayout.Width(50.0f)) == true)
                        {
                            paintableTexture.Unlock();
                        }
                        P3dHelper.EndColor();
                        P3dGroup_Drawer.OnGUI(P3dHelper.Reserve(), paintableTexture);
                        paintableTexture.Channel = (P3dChannel)EditorGUILayout.EnumPopup(paintableTexture.Channel);
                        if (GUILayout.Button("Paint", GUILayout.Width(45.0f)) == true)
                        {
                            tab = 2;
                        }
                        EditorGUILayout.EndHorizontal();
                    }
                    else
                    {
                        var shared = false;

                        if (TextureAlreadyLocked(texture) == true)
                        {
                            EditorGUILayout.HelpBox("This texture has already been locked in another object, so you don't need to lock it again. Paint will automatically be applied as long as you keep this texture expanded.", MessageType.Info);

                            shared = true;
                        }

                        EditorGUILayout.BeginHorizontal();
                        EditorGUI.BeginDisabledGroup(shared);
                        P3dHelper.BeginColor(Color.green);
                        if (GUILayout.Button("Lock", GUILayout.Width(45.0f)) == true)
                        {
                            Repaint();

                            paintableTexture.Lock(this);
                        }
                        P3dHelper.EndColor();
                        P3dGroup_Drawer.OnGUI(P3dHelper.Reserve(), paintableTexture);
                        EditorGUI.EndDisabledGroup();
                        paintableTexture.Channel = (P3dChannel)EditorGUILayout.EnumPopup(paintableTexture.Channel);
                        P3dHelper.BeginColor(Color.green);
                        EditorGUI.BeginDisabledGroup(shared);
                        if (GUILayout.Button("Lock & Paint", GUILayout.Width(85.0f)) == true)
                        {
                            Repaint();

                            if (paintableTexture.Lock(this) == true)
                            {
                                tab = 2;
                            }
                        }
                        EditorGUI.EndDisabledGroup();
                        P3dHelper.EndColor();
                        EditorGUILayout.EndHorizontal();

                        if (paintableTexture.LockFailed == true)
                        {
                            EditorGUILayout.HelpBox("Failed to lock texture.\nThis may be because the texture is not readable, if so, try cloning it.\nThis may be because the texture format is not readable, if so, try changing the format.", MessageType.Error);
                        }
                    }
                }
                else
                {
                    EditorGUILayout.HelpBox("This texture isn't a Texture2D, so it cannot be painted.", MessageType.Error);
                }
            }
            else
            {
                EditorGUILayout.HelpBox("There is no texture in this slot. Either drag and drop one in, or create one below.", MessageType.Warning);

                createFormat  = (TextureFormat)EditorGUILayout.EnumPopup("Format", createFormat);
                createMipMaps = EditorGUILayout.Toggle("Mip Maps", createMipMaps);
                createLinear  = EditorGUILayout.Toggle("Linear", createLinear);
                createColor   = EditorGUILayout.ColorField("Color", createColor);
                createWidth   = EditorGUILayout.IntField("Width", createWidth);
                createHeight  = EditorGUILayout.IntField("Height", createHeight);

                P3dHelper.BeginColor(Color.green);
                if (GUILayout.Button("Create") == true)
                {
                    var newTexture2D = new Texture2D(createWidth, createHeight, createFormat, createMipMaps, createLinear);

                    createFailed = true;

                    if (CanReadWrite(newTexture2D) == true)
                    {
                        var pixels32 = new Color32[createWidth * createHeight];
                        var color32  = (Color32)createColor;

                        for (var i = createWidth * createHeight - 1; i >= 0; i--)
                        {
                            pixels32[i] = color32;
                        }

                        newTexture2D.SetPixels32(pixels32);
                        newTexture2D.Apply();

                        texture      = newTexture2D;
                        createFailed = false;
                    }
                }
                P3dHelper.EndColor();

                if (createFailed == true)
                {
                    EditorGUILayout.HelpBox("Failed to create texture. This means the format you tried to use is not readable, or the size is invalid.", MessageType.Error);
                }
            }

            return(texture);
        }