protected bool DrawExpand(ref bool expand, string propertyPath, string overrideTooltip = null, string overrideText = null)
        {
            var rect     = P3dHelper.Reserve();
            var property = serializedObject.FindProperty(propertyPath);

            customContent.text    = string.IsNullOrEmpty(overrideText) == false ? overrideText    : property.displayName;
            customContent.tooltip = string.IsNullOrEmpty(overrideTooltip) == false ? overrideTooltip : property.tooltip;

            if (expandStyle == null)
            {
                expandStyle = new GUIStyle(EditorStyles.miniLabel); expandStyle.alignment = TextAnchor.MiddleRight;
            }

            if (EditorGUI.DropdownButton(new Rect(rect.position + Vector2.left * 15, new Vector2(15.0f, rect.height)), new GUIContent(expand ? "-" : "+"), FocusType.Keyboard, expandStyle) == true)
            {
                expand = !expand;
            }

            EditorGUI.BeginChangeCheck();

            EditorGUI.PropertyField(rect, property, customContent, true);

            var changed = EditorGUI.EndChangeCheck();

            return(changed);
        }
        private void DrawCamera()
        {
            Settings.OverrideCamera = EditorGUILayout.Toggle("Override Camera", Settings.OverrideCamera);

            if (Settings.OverrideCamera == true)
            {
                if (Settings.Observer == null && Camera.main != null)
                {
                    Settings.Observer = Camera.main.transform;
                }

                EditorGUI.indentLevel++;
                Settings.Distance = LogSlider("Distance", Settings.Distance, -4, 4);
                Settings.Observer = (Transform)EditorGUILayout.ObjectField("Root", Settings.Observer, typeof(Transform), true);

                if (GUI.Button(EditorGUI.IndentedRect(P3dHelper.Reserve()), "Snap To Scene View", EditorStyles.miniButton) == true)
                {
                    var camA = Camera.main;

                    if (camA != null && SceneView.lastActiveSceneView != null && SceneView.lastActiveSceneView.camera != null)
                    {
                        var camB = SceneView.lastActiveSceneView.camera;

                        camA.transform.position = camB.transform.position;
                        camA.transform.rotation = camB.transform.rotation;
                    }
                }
                EditorGUI.indentLevel--;
            }
        }
Esempio n. 3
0
        private void DrawSize()
        {
            var rect  = P3dHelper.Reserve();
            var rectL = rect; rectL.width = EditorGUIUtility.labelWidth;

            EditorGUI.LabelField(rectL, new GUIContent("Size", "This allows you to control the width and height of the texture when it gets activated."));

            rect.xMin += EditorGUIUtility.labelWidth;

            var rectR = rect; rectR.xMin = rectR.xMax - 48;
            var rectW = rect; rectW.xMax -= 50; rectW.xMax -= rectW.width / 2 + 1;
            var rectH = rect; rectH.xMax -= 50; rectH.xMin += rectH.width / 2 + 1;

            EditorGUI.PropertyField(rectW, serializedObject.FindProperty("width"), GUIContent.none);
            EditorGUI.PropertyField(rectH, serializedObject.FindProperty("height"), GUIContent.none);

            BeginDisabled(All(CannotScale));
            if (GUI.Button(rectR, new GUIContent("Copy", "Copy the width and height from the current slot?"), EditorStyles.miniButton) == true)
            {
                Undo.RecordObjects(targets, "Copy Sizes");

                Each(t => t.CopySize(), true);
            }
            EndDisabled();
        }
Esempio n. 4
0
        private static float Slider(string title, float value, float min, float max)
        {
            var rect  = P3dHelper.Reserve();
            var rectA = rect; rectA.width = EditorGUIUtility.labelWidth + 50;
            var rectB = rect; rectB.xMin += EditorGUIUtility.labelWidth + 52;

            value = GUI.HorizontalSlider(rectB, value, min, max);

            return(EditorGUI.FloatField(rectA, title, value));
        }
Esempio n. 5
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);
        }
Esempio n. 6
0
        public static void DrawDropdown(string title, Material material, P3dShaderTemplate.IHasTemplate hasTemplate, SerializedProperty property = null)
        {
            var template = hasTemplate.GetTemplate();
            var rect     = P3dHelper.Reserve();
            var rectA    = rect; rectA.width = EditorGUIUtility.labelWidth;
            var rectB    = rect; rectB.xMin += EditorGUIUtility.labelWidth;

            EditorGUI.LabelField(rectA, title);

            if (material != null)
            {
                if (GUI.Button(rectB, template != null ? template.name : "", EditorStyles.popup) == true)
                {
                    var menu           = new GenericMenu();
                    var otherTemplates = P3dShaderTemplate.GetTemplates(material.shader);

                    if (otherTemplates.Count == 0)
                    {
                        menu.AddDisabledItem(new GUIContent("No templates found for this material shader."));
                    }

                    for (var i = 0; i < otherTemplates.Count; i++)
                    {
                        var otherTemplate = otherTemplates[i];

                        menu.AddItem(new GUIContent(otherTemplate.name), template == otherTemplate, () =>
                        {
                            if (property != null)
                            {
                                property.objectReferenceValue = otherTemplate;

                                property.serializedObject.ApplyModifiedProperties();
                            }
                            else
                            {
                                hasTemplate.SetTemplate(otherTemplate);
                            }
                        });
                    }

                    menu.DropDown(rectB);
                }
            }
            else
            {
                EditorGUI.BeginDisabledGroup(true);
                GUI.Button(rectB, "Material Missing", EditorStyles.popup);
                EditorGUI.EndDisabledGroup();
            }
        }
Esempio n. 7
0
        private static float LogSlider(string title, float value, float logMin, float logMax)
        {
            var rect   = P3dHelper.Reserve();
            var rectA  = rect; rectA.width = EditorGUIUtility.labelWidth + 50;
            var rectB  = rect; rectB.xMin += EditorGUIUtility.labelWidth + 52;
            var logOld = Mathf.Log10(value);
            var logNew = GUI.HorizontalSlider(rectB, logOld, logMin, logMax);

            if (logOld != logNew)
            {
                value = Mathf.Pow(10.0f, logNew);
            }

            return(EditorGUI.FloatField(rectA, title, value));
        }
Esempio n. 8
0
        private void DrawTextures()
        {
            var sTextures   = serializedObject.FindProperty("textures");
            var deleteIndex = -1;

            for (var i = 0; i < sTextures.arraySize; i++)
            {
                var sTexture = sTextures.GetArrayElementAtIndex(i);
                var title    = GetTitle(sTexture.objectReferenceValue);

                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.PropertyField(sTexture, new GUIContent(title));
                if (GUILayout.Button("x", EditorStyles.miniButton, GUILayout.Width(20)) == true)
                {
                    deleteIndex = i;
                }
                EditorGUILayout.EndHorizontal();

                if (sTexture.hasMultipleDifferentValues == false)
                {
                    EditorGUI.BeginDisabledGroup(true);
                    foreach (var groupData in P3dGroupData_Editor.CachedInstances)
                    {
                        foreach (var textureData in groupData.TextureDatas)
                        {
                            if (textureData.Name == title)
                            {
                                EditorGUILayout.ObjectField(" ", groupData, typeof(P3dGroupData), false);
                            }
                        }
                    }
                    EditorGUI.EndDisabledGroup();
                }
            }

            if (deleteIndex >= 0)
            {
                sTextures.DeleteArrayElementAtIndex(deleteIndex);
            }

            var newTexture = (Texture2D)EditorGUI.ObjectField(P3dHelper.Reserve(), new GUIContent("Add Texture"), null, typeof(Texture2D), false);

            if (newTexture != null)
            {
                sTextures.InsertArrayElementAtIndex(sTextures.arraySize);
                sTextures.GetArrayElementAtIndex(sTextures.arraySize - 1).objectReferenceValue = newTexture;
            }
        }
Esempio n. 9
0
        private void DrawTexture()
        {
            var rect  = P3dHelper.Reserve();
            var rectL = rect; rectL.xMax -= 50;
            var rectR = rect; rectR.xMin = rectR.xMax - 48;

            EditorGUI.PropertyField(rectL, serializedObject.FindProperty("texture"), new GUIContent("Texture", "When activated or cleared, this paintable texture will be given this texture, and then multiplied/tinted by the Color.\n\nNone = White."));

            BeginDisabled(All(CannotCopyTexture));
            if (GUI.Button(rectR, new GUIContent("Copy", "Copy the texture from the current slot?"), EditorStyles.miniButton) == true)
            {
                Undo.RecordObjects(targets, "Copy Textures");

                Each(t => t.CopyTexture(), true);
            }
            EndDisabled();
        }
        protected override void OnInspector()
        {
            if (All(t => t.Activated == true))
            {
                EditorGUILayout.HelpBox("This component has already activated.", MessageType.Info);
            }

            if (Any(t => t.Activated == false))
            {
                DrawDefault("slot", "The material slot and texture name that will be painted.");
                DrawDefault("channel", "The UV channel this texture is mapped to.");
                BeginDisabled();
                EditorGUI.ObjectField(P3dHelper.Reserve(), "Texture", Target.Slot.FindTexture(Target.gameObject), typeof(Texture), false);
                EndDisabled();

                Separator();

                DrawDefault("group", "The group you want to associate this texture with. You only need to set this if you are painting multiple types of textures at the same time (e.g. 0 = albedo, 1 = illumination).");
                DrawDefault("stateLimit", "The amount of times this texture can have its paint operations undone.");
                DrawDefault("saveName", "If you want this texture to automatically save/load, then you can set the unique save name for it here. Keep in mind this setting won't work properly with prefab spawning since all clones will share the same SaveName.");
                DrawDefault("shaderKeyword", "Some shaders require specific shader keywords to be enabled when adding new textures. If there is no texture in your selected slot then you may need to set this keyword.");

                Separator();

                DrawDefault("format", "The format of the created texture.");
                DrawDefault("width", "The base width of the created texture.");
                DrawDefault("height", "The base height of the created texture.");
                DrawDefault("inheritSize", "If there is already a texture in the specified slot, inherit the width/height of that texture?");
                DrawDefault("baseScale", "If you want the width/height to be multiplied by the scale of this GameObject, this allows you to set the scale where you want the multiplier to be 1.");
                DrawDefault("color", "The base color of the created texture.");
                DrawDefault("texture", "The format of the created texture.");
            }

            Target.GetComponentsInChildren(paintHandlers);

            if (paintHandlers.Count > 0)
            {
                Separator();

                for (var i = 0; i < paintHandlers.Count; i++)
                {
                    EditorGUILayout.HelpBox("This component is sending paint events to " + paintHandlers[i], MessageType.Info);
                }
            }
        }
Esempio n. 11
0
        protected bool DrawExpand(ref bool expand, string propertyPath, string overrideTooltip = null, string overrideText = null)
        {
            var rect     = P3dHelper.Reserve();
            var property = serializedObject.FindProperty(propertyPath);

            customContent.text    = string.IsNullOrEmpty(overrideText) == false ? overrideText    : property.displayName;
            customContent.tooltip = string.IsNullOrEmpty(overrideTooltip) == false ? overrideTooltip : property.tooltip;

            EditorGUI.BeginChangeCheck();

            EditorGUI.PropertyField(rect, property, customContent, true);

            var changed = EditorGUI.EndChangeCheck();

            expand = EditorGUI.Foldout(new Rect(rect.position, new Vector2(25.0f, rect.height)), expand, string.Empty);

            return(changed);
        }
Esempio n. 12
0
        private void DrawCurrentColor()
        {
            var rectT   = P3dHelper.Reserve();
            var rect    = P3dHelper.Reserve();
            var rectA   = GetRect(rect, rect.xMin + 20, rect.xMax);
            var rectS   = GetRect(rect, rect.xMin, rect.xMin + 18);
            var starred = P3dWindowData.Instance.FavouriteColors.Contains(P3dWindowData.Instance.CurrentColor);

            P3dHelper.BeginColor(Color.gray, P3dWindowData.Instance.CurrentBlend != P3dWindowData.ColorBlendType.None);
            if (GUI.Button(GetRect(rectT, rectT.xMin + rectT.width / 3 * 0, rectT.xMin + rectT.width / 3 * 1), blendContentA, EditorStyles.miniButtonLeft) == true)
            {
                P3dWindowData.Instance.CurrentBlend = P3dWindowData.ColorBlendType.None;
            }
            P3dHelper.EndColor();

            P3dHelper.BeginColor(Color.gray, P3dWindowData.Instance.CurrentBlend != P3dWindowData.ColorBlendType.Replace);
            if (GUI.Button(GetRect(rectT, rectT.xMin + rectT.width / 3 * 1, rectT.xMin + rectT.width / 3 * 2), blendContentB, EditorStyles.miniButtonMid) == true)
            {
                P3dWindowData.Instance.CurrentBlend = P3dWindowData.ColorBlendType.Replace;
            }
            P3dHelper.EndColor();

            P3dHelper.BeginColor(Color.gray, P3dWindowData.Instance.CurrentBlend != P3dWindowData.ColorBlendType.Multiply);
            if (GUI.Button(GetRect(rectT, rectT.xMin + rectT.width / 3 * 2, rectT.xMin + rectT.width / 3 * 3), blendContentC, EditorStyles.miniButtonRight) == true)
            {
                P3dWindowData.Instance.CurrentBlend = P3dWindowData.ColorBlendType.Multiply;
            }
            P3dHelper.EndColor();

            P3dWindowData.Instance.CurrentColor = EditorGUI.ColorField(rectA, GUIContent.none, P3dWindowData.Instance.CurrentColor);

            if (DrawStarButton(rectS, starred) == true)
            {
                if (starred == true)
                {
                    P3dWindowData.Instance.FavouriteColors.Remove(P3dWindowData.Instance.CurrentColor);
                }
                else
                {
                    P3dWindowData.Instance.FavouriteColors.Add(P3dWindowData.Instance.CurrentColor);
                }
            }
        }
Esempio n. 13
0
        protected override void OnInspector()
        {
            if (Any(t => t.Activated == true))
            {
                EditorGUILayout.HelpBox("This component has been activated.", MessageType.Info);
            }

            DrawExpand(ref expandSlot, "slot", "The material index and shader texture slot name that this component will paint.");
            if (expandSlot == true)
            {
                BeginIndent();
                BeginDisabled();
                EditorGUI.ObjectField(P3dHelper.Reserve(), new GUIContent("Texture", "This is the current texture in the specified texture slot."), Target.Slot.FindTexture(Target.gameObject), typeof(Texture), false);
                EndDisabled();
                EndIndent();
            }
            Draw("coord", "The UV channel this texture is mapped to.");
            Draw("shaderKeyword", "Some shaders require specific shader keywords to be enabled when adding new textures. If there is no texture in your selected slot then you may need to set this keyword.");

            Separator();

            Draw("group", "The group you want to associate this texture with. Only painting components with a matching group can paint this texture. This allows you to paint multiple textures at the same time with different settings (e.g. Albedo + Normal).");
            Draw("state", "This allows you to set how this texture's state is stored. This allows you to perform undo and redo operations.\n\nFullTextureCopy = A full copy of your texture will be copied for each state. This allows you to quickly undo and redo, and works with animated skinned meshes, but it uses up a lot of texture memory.\n\nLocalCommandCopy = Each paint command will be stored in local space for each state. This allows you to perform unlimited undo and redo states with minimal memory usage, because the object will be repainted from scratch. However, performance will depend on how many states must be redrawn.");
            if (Any(t => t.State == P3dPaintableTexture.StateType.FullTextureCopy))
            {
                BeginIndent();
                Draw("stateLimit", "The amount of times this texture can have its paint operations undone.", "Limit");
                EndIndent();
            }
            Draw("saveName", "If you want this texture to automatically save/load, then you can set the unique save name for it here. Keep in mind this setting won't work properly with prefab spawning since all clones will share the same SaveName.");

            Separator();

            Draw("format", "The format of the created texture.");
            Draw("mipMaps", "The mip maps of the created texture.\n\nAuto = On or Off based on the <b>Texture</b> mip map count.\n\nForceOn = Always enabled.\n\nForceOff = Always disabled.");
            Draw("keepUnpaintable", "If you disable this, then the unpaintable areas of this texture be discarded, and thus improve painting performance.\n\nNOTE: This is on by default, because some effects may require them to be preserved.");

            DrawSize();
            DrawTexture();
            Draw("color", "When activated or cleared, this paintable texture will be given this color.\n\nNOTE: If Texture is set, then each pixel RGBA value will be multiplied/tinted by this color.");
        }
Esempio n. 14
0
        protected override void OnInspector()
        {
            if (Any(t => t.Activated == true))
            {
                EditorGUILayout.HelpBox("This component has been activated.", MessageType.Info);
            }

            DrawExpand(ref expandSlot, "slot", "The material index and shader texture slot name that this component will paint.");
            if (expandSlot == true)
            {
                BeginIndent();
                BeginDisabled();
                EditorGUI.ObjectField(P3dHelper.Reserve(), new GUIContent("Texture", "This is the current texture in the specified texture slot."), Target.Slot.FindTexture(Target.gameObject), typeof(Texture), false);
                EndDisabled();
                EndIndent();
            }
            Draw("channel", "The UV channel this texture is mapped to.");
            Draw("shaderKeyword", "Some shaders require specific shader keywords to be enabled when adding new textures. If there is no texture in your selected slot then you may need to set this keyword.");

            Separator();

            Draw("group", "The group you want to associate this texture with. You only need to set this if you are painting multiple types of textures at the same time (e.g. 0 = albedo, 1 = illumination).");
            Draw("state", "This allows you to set how this texture's state is stored. This allows you to perform undo and redo operations.\nFullTextureCopy = A full copy of your texture will be copied for each state. This allows you to quickly undo and redo, and works with animated skinned meshes, but it uses up a lot of texture memory.\nLocalCommandCopy = Each paint command will be stored in local space for each state. This allows you to perform unlimited undo and redo states with minimal memory usage, because the object will be repainted from scratch. However, performance will depend on how many states must be redrawn.");
            if (Any(t => t.State == P3dPaintableTexture.StateType.FullTextureCopy))
            {
                BeginIndent();
                Draw("stateLimit", "The amount of times this texture can have its paint operations undone.", "Limit");
                EndIndent();
            }
            Draw("saveName", "If you want this texture to automatically save/load, then you can set the unique save name for it here. Keep in mind this setting won't work properly with prefab spawning since all clones will share the same SaveName.");

            Separator();

            Draw("format", "The format of the created texture.");
            DrawSize();
            Draw("color", "The base color of the created texture.");
            Draw("texture", "The format of the created texture.");
        }
Esempio n. 15
0
        private void DrawFavouriteColors()
        {
            if (GUILayout.Button("Favourite Colors", expandFavouriteColors == true ? EditorStyles.toolbarDropDown : EditorStyles.toolbarButton) == true)
            {
                expandFavouriteColors = !expandFavouriteColors;
            }

            if (expandFavouriteColors == true)
            {
                var count = 0;

                for (var i = 0; i < P3dWindowData.Instance.FavouriteColors.Count; i++)
                {
                    var color = P3dWindowData.Instance.FavouriteColors[i]; count++;
                    var rect  = P3dHelper.Reserve();

                    if (GUI.Button(rect, GUIContent.none) == true)
                    {
                        P3dWindowData.Instance.CurrentColor = color;
                    }

                    rect.xMin += 3;
                    rect.xMax -= 3;
                    rect.yMin += 3;
                    rect.yMax -= 3;

                    P3dHelper.BeginColor(color);
                    GUI.DrawTexture(rect, EditorGUIUtility.whiteTexture);
                    P3dHelper.EndColor();
                }

                if (count == 0)
                {
                    EditorGUILayout.HelpBox("You have no favourite colors!", MessageType.Info);
                }
            }
        }
Esempio n. 16
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);
        }
Esempio n. 17
0
        private void DrawMaterialBuilder()
        {
            for (var i = 0; i < textures.Count; i++)
            {
                var texture = textures[i];
                var title   = GetTitle(texture);

                textures[i] = (Texture2D)EditorGUI.ObjectField(P3dHelper.Reserve(), new GUIContent(title), textures[i], typeof(Texture2D), false);

                EditorGUI.BeginDisabledGroup(true);
                foreach (var groupData in P3dGroupData.CachedInstances)
                {
                    foreach (var textureData in groupData.TextureDatas)
                    {
                        if (textureData.Name == title)
                        {
                            EditorGUILayout.ObjectField(" ", groupData, typeof(P3dGroupData), false);
                        }
                    }
                }
                EditorGUI.EndDisabledGroup();
            }

            EditorGUILayout.Separator();

            var newTexture = (Texture2D)EditorGUILayout.ObjectField(default(Texture2D), typeof(Texture2D), false);

            if (newTexture != null)
            {
                textures.Add(newTexture);
            }

            EditorGUILayout.Separator();

            EditorGUI.BeginDisabledGroup(Target.transform.childCount == 0);
            if (GUILayout.Button("Populate From Children") == true)
            {
                textures.Clear();

                for (var i = 0; i < Target.transform.childCount; i++)
                {
                    var paintDecal = Target.transform.GetChild(i).GetComponent <P3dPaintDecal>();

                    if (paintDecal != null)
                    {
                        var tex = paintDecal.TileTexture as Texture2D;

                        if (tex != null)
                        {
                            textures.Add(tex);
                        }
                    }
                }
            }
            EditorGUI.EndDisabledGroup();

            EditorGUI.BeginDisabledGroup(textures.Exists(t => t != null) == false);
            if (GUILayout.Button("Build Material") == true)
            {
                for (var i = Target.transform.childCount - 1; i >= 0; i--)
                {
                    DestroyImmediate(Target.transform.GetChild(i).gameObject);
                }

                foreach (var texture in textures)
                {
                    var title = GetTitle(texture);

                    if (string.IsNullOrEmpty(title) == false)
                    {
                        var child = new GameObject(title);

                        child.transform.SetParent(Target.transform, false);

                        foreach (var groupData in P3dGroupData.CachedInstances)
                        {
                            foreach (var textureData in groupData.TextureDatas)
                            {
                                if (textureData.Name == title)
                                {
                                    var paintDecal = child.AddComponent <P3dPaintDecal>();

                                    paintDecal.Group       = groupData.Index;
                                    paintDecal.BlendMode   = textureData.BlendMode;
                                    paintDecal.TileTexture = texture;
                                }
                            }
                        }
                    }
                }

                EditorSceneManager.MarkSceneDirty(Target.gameObject.scene);
            }
            EditorGUI.EndDisabledGroup();
        }
Esempio n. 18
0
        private void UpdateObjectsPanel()
        {
            if (Selection.gameObjects.Length == 0 && scene.Objs.Count == 0)
            {
                EditorGUILayout.HelpBox("Select a GameObject with a MesFilter+MeshRenderer or SkinnedMeshRenderer.", MessageType.Info);
            }

            // Mark
            tempObjs.ForEach(t => t.Dirty = true);

            foreach (var go in Selection.gameObjects)
            {
                if (scene.ObjExists(go.transform) == false)
                {
                    var mf = go.GetComponent <MeshFilter>();
                    var mr = go.GetComponent <MeshRenderer>();

                    if (mf != null && mr != null && mf.sharedMesh != null)
                    {
                        GUILayout.BeginVertical(EditorStyles.helpBox);
                        EditorGUI.BeginDisabledGroup(true);
                        EditorGUILayout.ObjectField(go, typeof(GameObject), true);
                        EditorGUI.EndDisabledGroup();

                        var materials = mr.sharedMaterials;

                        tempTemplates.Clear();

                        for (var i = 0; i < materials.Length; i++)
                        {
                            var material  = materials[i];
                            var templates = P3dShaderTemplate.GetTemplates(material != null ? material.shader : null);
                            var slot      = GetTempObj(go, i);

                            if (templates.Contains(slot.Template) == false)
                            {
                                slot.Template = templates.Count > 0 ? templates[0] : null;
                            }

                            GUILayout.BeginVertical(EditorStyles.helpBox);
                            P3dHelper.BeginLabelWidth(60.0f);
                            EditorGUI.BeginDisabledGroup(true);
                            EditorGUILayout.ObjectField("Material", material, typeof(Material), true);
                            EditorGUI.EndDisabledGroup();
                            P3dHelper.BeginColor(slot.Template == null);
                            P3dShaderTemplate_Editor.DrawDropdown("Template", material, slot);
                            P3dHelper.EndColor();
                            P3dHelper.EndLabelWidth();
                            GUILayout.EndVertical();

                            tempTemplates.Add(slot.Template);
                        }

                        if (GUILayout.Button("Add") == true)
                        {
                            scene.AddObj(go.transform, mf.sharedMesh, go.transform.position, go.transform.rotation, go.transform.lossyScale, materials, tempTemplates.ToArray(), settings.DefaultTextureSize);
                        }
                        GUILayout.EndVertical();
                    }
                }
            }

            // Sweep
            tempObjs.RemoveAll(t => t.Dirty == true);

            EditorGUILayout.Separator();

            for (var i = 0; i < scene.Objs.Count; i++)
            {
                if (i > 0)
                {
                    EditorGUILayout.Space();
                }

                var obj     = scene.Objs[i];
                var objRect =
                    EditorGUILayout.BeginVertical(GetSelectableStyle(obj == currentObj, true));
                P3dHelper.BeginLabelWidth(60.0f);
                if (obj == currentObj)
                {
                    EditorGUILayout.BeginHorizontal();
                    obj.Name = EditorGUILayout.TextField(obj.Name);
                    if (GUILayout.Button("X", EditorStyles.miniButton, GUILayout.Width(20)) == true && EditorUtility.DisplayDialog("Are you sure?", "This will delete the current layer from the paint window.", "Delete") == true)
                    {
                        scene.RemoveObj(obj); i--; P3dHelper.ClearControl();
                    }
                    EditorGUILayout.EndHorizontal();

                    obj.Mesh      = (Mesh)EditorGUILayout.ObjectField("Mesh", obj.Mesh, typeof(Mesh), true);
                    obj.Paintable = EditorGUILayout.Toggle("Paintable", obj.Paintable);
                    obj.Coord     = (P3dCoord)EditorGUILayout.EnumPopup("Coord", obj.Coord);
                    obj.Transform = (Transform)EditorGUILayout.ObjectField("Transform", obj.Transform, typeof(Transform), true);

                    if (obj.Transform == null)
                    {
                        obj.Position = EditorGUILayout.Vector3Field("Position", obj.Position);

                        EditorGUI.BeginChangeCheck();
                        var newRot = EditorGUILayout.Vector3Field("Rotation", obj.Rotation.eulerAngles);
                        if (EditorGUI.EndChangeCheck() == true)
                        {
                            obj.Rotation = Quaternion.Euler(newRot);
                        }

                        obj.Scale = EditorGUILayout.Vector3Field("Scale", obj.Scale);
                    }

                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.LabelField("Materials", EditorStyles.boldLabel);
                    if (GUILayout.Button("+", EditorStyles.miniButton, GUILayout.Width(20)) == true)
                    {
                        obj.MatIds.Add(-1);
                    }
                    EditorGUILayout.EndHorizontal();

                    for (var j = 0; j < obj.MatIds.Count; j++)
                    {
                        var matId = obj.MatIds[j];
                        var rect  = P3dHelper.Reserve(); rect.xMin += 10;
                        var mat   = scene.GetMat(matId);

                        if (GUI.Button(rect, mat != null ? mat.Name : "", EditorStyles.popup) == true)
                        {
                            var menu = new GenericMenu();

                            for (var k = 0; k < scene.Mats.Count; k++)
                            {
                                var setObj = obj;
                                var setIdx = j;
                                var setMat = scene.Mats[k];

                                menu.AddItem(new GUIContent(setMat.Name), setMat == mat, () => setObj.MatIds[setIdx] = setMat.Id);
                            }

                            var remObj = obj;
                            var remIdx = j;

                            menu.AddSeparator("");
                            menu.AddItem(new GUIContent("Remove"), false, () => remObj.MatIds.RemoveAt(remIdx));

                            menu.DropDown(rect);
                        }
                    }
                }
                else
                {
                    EditorGUILayout.LabelField(obj.Name);
                }
                P3dHelper.EndLabelWidth();
                EditorGUILayout.EndVertical();

                if (Event.current.type == EventType.MouseDown && objRect.Contains(Event.current.mousePosition) == true)
                {
                    currentObj = obj; P3dHelper.ClearControl();
                }
            }
        }
        protected bool Button(string text)
        {
            var rect = P3dHelper.Reserve();

            return(GUI.Button(rect, text));
        }
Esempio n. 20
0
        private Material DrawMaterial(P3dWindowPaintable paintable, Material material, int materialIndex)
        {
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Material " + materialIndex, EditorStyles.boldLabel, GUILayout.Width(120.0f));
            material = (Material)EditorGUILayout.ObjectField("", material, typeof(Material), false);
            EditorGUILayout.EndHorizontal();

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

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

                if (MaterialIsShared(material) == true && GUILayout.Button("Shared Clone") == true)
                {
                    var oldMaterial = material;

                    material = Instantiate(material);

                    MaterialIsShared(oldMaterial, material);
                }

                if (P3dHelper.IsAsset(material) == false && GUILayout.Button("Save As Asset") == true)
                {
                    var path = P3dHelper.SaveDialog("Save Material As Asset", "Assets", material.name, "mat");

                    if (string.IsNullOrEmpty(path) == false)
                    {
                        var textures = P3dHelper.CopyTextures(material);

                        AssetDatabase.CreateAsset(material, path);

                        P3dHelper.PasteTextures(material, textures);
                    }
                }

                var texEnvs = P3dHelper.GetTexEnvs(material);

                if (texEnvs.Count > 0)
                {
                    for (var j = 0; j < texEnvs.Count; j++)
                    {
                        var texEnv           = texEnvs[j];
                        var rect             = P3dHelper.Reserve();
                        var paintableTexture = paintable.PaintableTextures.Find(t => t.MaterialIndex == materialIndex && t.SlotName == texEnv.Name);

                        EditorGUI.BeginDisabledGroup(paintableTexture != null && paintableTexture.Locked == true);
                        var texture = EditorGUI.ObjectField(rect, default(string), material.GetTexture(texEnv.Name), typeof(Texture), true) as Texture;
                        EditorGUI.EndDisabledGroup();

                        // Make sure this is done after the texture field so it can be edited
                        var expand = EditorGUI.Foldout(rect, paintableTexture != null, new GUIContent(texEnv.Name, texEnv.Desc), false);

                        if (expand == true)
                        {
                            if (paintableTexture == null)
                            {
                                paintableTexture = new P3dWindowPaintableTexture(paintable, materialIndex, texEnv.Name); paintable.PaintableTextures.Add(paintableTexture);
                            }

                            paintableTexture.Revert();

                            paintableTexture.OldTexture = material.GetTexture(texEnv.Name) as Texture2D;

                            EditorGUILayout.BeginVertical("box");
                            texture = DrawObject(paintableTexture, material, texture);
                            EditorGUILayout.EndVertical();
                        }
                        else
                        {
                            if (paintableTexture != null)
                            {
                                paintableTexture.Unlock();

                                paintable.PaintableTextures.Remove(paintableTexture);
                            }
                        }

                        material.SetTexture(texEnv.Name, texture);
                    }
                }
                else
                {
                    EditorGUILayout.HelpBox("This material's shader has no texture slots.", MessageType.Info);
                }
            }
            else
            {
                EditorGUILayout.HelpBox("There is no material in this material slot.", MessageType.Info);
            }

            return(material);
        }
Esempio n. 21
0
        public static void Draw(SerializedProperty sSlots, Shader shader)
        {
            var removeIndex = -1;

            for (var i = 0; i < sSlots.arraySize; i++)
            {
                var sSlot  = sSlots.GetArrayElementAtIndex(i);
                var sName  = sSlot.FindPropertyRelative("Name");
                var sAlias = sSlot.FindPropertyRelative("Alias");

                EditorGUILayout.BeginVertical(EditorStyles.helpBox);

                P3dHelper.BeginColor(P3dHelper.TexEnvNameExists(shader, sName.stringValue) == false);
                {
                    var rect  = P3dHelper.Reserve();
                    var rectA = rect; rectA.width = EditorGUIUtility.labelWidth;
                    var rectB = rect; rectB.xMin += EditorGUIUtility.labelWidth; rectB.xMax -= 20;
                    var rectC = rect; rectC.xMin = rectC.xMax - 18;

                    EditorGUI.LabelField(rectA, new GUIContent(sName.name, sName.tooltip));
                    EditorGUI.PropertyField(rectB, sName, GUIContent.none);

                    // Draw menu
                    if (GUI.Button(rectC, "", EditorStyles.popup) == true)
                    {
                        var menu    = new GenericMenu();
                        var texEnvs = P3dHelper.GetTexEnvs(shader);

                        if (texEnvs != null && texEnvs.Count > 0)
                        {
                            for (var j = 0; j < texEnvs.Count; j++)
                            {
                                var texName = texEnvs[j].Name;

                                menu.AddItem(new GUIContent(texName), sName.stringValue == texName, () => { sName.stringValue = texName; sName.serializedObject.ApplyModifiedProperties(); });
                            }
                        }
                        else
                        {
                            menu.AddDisabledItem(new GUIContent("This shader has no textures!"));
                        }

                        menu.DropDown(rectC);
                    }
                }
                P3dHelper.EndColor();

                EditorGUILayout.PropertyField(sAlias);

                DrawElement(sSlot.FindPropertyRelative("WriteR"));
                DrawElement(sSlot.FindPropertyRelative("WriteG"));
                DrawElement(sSlot.FindPropertyRelative("WriteB"));
                DrawElement(sSlot.FindPropertyRelative("WriteA"));

                P3dHelper.BeginColor(Color.red);
                if (GUILayout.Button("Remove Slot") == true)
                {
                    removeIndex = i;
                }
                P3dHelper.EndColor();

                EditorGUILayout.EndVertical();
            }

            EditorGUILayout.Separator();

            if (GUILayout.Button("Add Slot") == true)
            {
                sSlots.arraySize += 1;
            }

            if (removeIndex >= 0)
            {
                sSlots.DeleteArrayElementAtIndex(removeIndex);
            }
        }
Esempio n. 22
0
        private void DrawCameraTab()
        {
            cameraScrollPosition = GUILayout.BeginScrollView(cameraScrollPosition, GUILayout.ExpandHeight(true));
            EditorGUILayout.HelpBox("This allows you to control the Game view camera. Keep in mind this will not work if your camera already has controls from another source.", MessageType.Info);

            EditorGUILayout.Separator();

            P3dHelper.BeginLabelWidth(100);
            EditorGUILayout.LabelField("Controls", EditorStyles.boldLabel);
            Settings.MoveSpeed    = EditorGUILayout.FloatField("Speed", Settings.MoveSpeed);
            Settings.MoveForward  = (KeyCode)EditorGUILayout.EnumPopup("Forward", Settings.MoveForward);
            Settings.MoveBackward = (KeyCode)EditorGUILayout.EnumPopup("Backward", Settings.MoveBackward);
            Settings.MoveLeft     = (KeyCode)EditorGUILayout.EnumPopup("Left", Settings.MoveLeft);
            Settings.MoveRight    = (KeyCode)EditorGUILayout.EnumPopup("Right", Settings.MoveRight);
            Settings.Rotate       = (KeyCode)EditorGUILayout.EnumPopup("Rotate", Settings.Rotate);
            Settings.Pan          = (KeyCode)EditorGUILayout.EnumPopup("Pan", Settings.Pan);
            EditorGUI.BeginDisabledGroup(true);
            EditorGUILayout.TextField("Paint", "Mouse 0", EditorStyles.popup);
            EditorGUILayout.TextField("Zoom", "Mouse Wheel", EditorStyles.popup);
            EditorGUILayout.TextField("Move Pivot", "Double Click (Right / Middle)", EditorStyles.popup);
            EditorGUI.EndDisabledGroup();

            EditorGUILayout.Separator();

            Settings.OverrideCamera = EditorGUILayout.Toggle("Override Camera", Settings.OverrideCamera);

            if (Settings.OverrideCamera == true)
            {
                EditorGUI.indentLevel++;
                Settings.Distance  = LogSlider("Distance", Settings.Distance, -4, 4);
                Settings.Observer  = (Transform)EditorGUILayout.ObjectField("Root", Settings.Observer, typeof(Transform), true);
                Settings.ShowPivot = EditorGUILayout.Toggle("Show Pivot", Settings.ShowPivot);

                if (GUI.Button(EditorGUI.IndentedRect(P3dHelper.Reserve()), "Snap To Scene View", EditorStyles.miniButton) == true)
                {
                    var camA = Camera.main;

                    if (camA != null && SceneView.lastActiveSceneView != null && SceneView.lastActiveSceneView.camera != null)
                    {
                        var camB = SceneView.lastActiveSceneView.camera;

                        camA.transform.position = camB.transform.position;
                        camA.transform.rotation = camB.transform.rotation;
                    }
                }
                EditorGUI.indentLevel--;

                if (toolInstance != null && toolInstance.CameraMovedUnexpectedly == true)
                {
                    EditorGUILayout.HelpBox("The camera moved unexpectedly. Mabe your scene already has camera controls?", MessageType.Warning);
                }
            }
            P3dHelper.EndLabelWidth();
            GUILayout.EndScrollView();

            GUILayout.FlexibleSpace();

            if (Application.isPlaying == false)
            {
                EditorGUILayout.HelpBox("You must enter play mode to move the Game camera.", MessageType.Warning);
            }
        }
Esempio n. 23
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--;
        }
 public override void DrawEditorLayout()
 {
     texture     = (Texture)UnityEditor.EditorGUI.ObjectField(P3dHelper.Reserve(), new GUIContent("Texture", "The painting texture will be changed to this."), texture, typeof(Texture), true);
     pressureMin = UnityEditor.EditorGUILayout.FloatField(new GUIContent("Pressure Min", "The paint pressure must be at least this value."), pressureMin);
     pressureMax = UnityEditor.EditorGUILayout.FloatField(new GUIContent("Pressure Max", "The paint pressure must be at most this value."), pressureMax);
 }
        protected override void OnInspector()
        {
            if (mesh != null)
            {
                EditorGUI.BeginDisabledGroup(true);
                EditorGUILayout.ObjectField("Mesh", mesh, typeof(Mesh), false);
                EditorGUI.EndDisabledGroup();

                if (mesh.subMeshCount != submeshNames.Length)
                {
                    var submeshNamesList = new List <string>();

                    for (var i = 0; i < mesh.subMeshCount; i++)
                    {
                        submeshNamesList.Add(i.ToString());
                    }

                    submeshNames = submeshNamesList.ToArray();
                }

                EditorGUILayout.Separator();

                var newSubmesh  = EditorGUILayout.Popup("Submesh", submesh, submeshNames);
                var newCoord    = EditorGUILayout.Popup("Coord", coord, new string[] { "UV0", "UV1", "UV2", "UV3" });
                var newMode     = EditorGUILayout.Popup("Mode", mode, new string[] { "Texcoord", "Triangles" });
                var newRotation = EditorGUILayout.Vector3Field("Rotation", rotation);

                EditorGUILayout.Separator();

                EditorGUILayout.LabelField("Triangles", EditorStyles.boldLabel);
                EditorGUI.BeginDisabledGroup(true);
                EditorGUILayout.IntField("Total", triangleCount);
                EditorGUILayout.IntField("With No UV", invalidCount);
                EditorGUI.EndDisabledGroup();

                if (coord != newCoord || newSubmesh != submesh || newMode != mode || newRotation != rotation || ready == false)
                {
                    ready    = true;
                    coord    = newCoord;
                    submesh  = newSubmesh;
                    mode     = newMode;
                    rotation = newRotation;

                    listA.Clear();
                    listB.Clear();
                    ratioList.Clear();
                    mesh.GetTriangles(indices, submesh);
                    mesh.GetVertices(positions);
                    mesh.GetUVs(coord, coords);

                    triangleCount = indices.Count / 3;
                    invalidCount  = 0;

                    if (coords.Count > 0)
                    {
                        var rot  = Quaternion.Euler(rotation);
                        var off  = -mesh.bounds.center;
                        var mul  = P3dHelper.Reciprocal(mesh.bounds.size.magnitude);
                        var half = Vector3.one * 0.5f;

                        for (var i = 0; i < indices.Count; i += 3)
                        {
                            var positionA = positions[indices[i + 0]];
                            var positionB = positions[indices[i + 1]];
                            var positionC = positions[indices[i + 2]];
                            var coordA    = coords[indices[i + 0]];
                            var coordB    = coords[indices[i + 1]];
                            var coordC    = coords[indices[i + 2]];
                            var area      = Vector3.Cross(coordA - coordB, coordA - coordC).sqrMagnitude;
                            var invalid   = area <= float.Epsilon;

                            if (invalid == true)
                            {
                                invalidCount++;
                            }

                            if (mode == 0)                             // Texcoord
                            {
                                listA.Add(coordA); listA.Add(coordB);
                                listA.Add(coordB); listA.Add(coordC);
                                listA.Add(coordC); listA.Add(coordA);
                            }

                            if (mode == 1)                             // Triangles
                            {
                                positionA = half + rot * (off + positionA) * mul;
                                positionB = half + rot * (off + positionB) * mul;
                                positionC = half + rot * (off + positionC) * mul;

                                positionA.z = positionB.z = positionC.z = 0.0f;

                                listA.Add(positionA); listA.Add(positionB);
                                listA.Add(positionB); listA.Add(positionC);
                                listA.Add(positionC); listA.Add(positionA);

                                if (invalid == true)
                                {
                                    listB.Add(positionA); listB.Add(positionB);
                                    listB.Add(positionB); listB.Add(positionC);
                                    listB.Add(positionC); listB.Add(positionA);
                                }
                            }
                        }
                    }

                    arrayA = listA.ToArray();
                    arrayB = listB.ToArray();
                }

                var rect = P3dHelper.Reserve(position.height - 186.0f); GUI.Box(rect, ""); rect.min += Vector2.one * 3.0f; rect.max -= Vector2.one * 3.0f;
                var pos  = rect.min;
                var siz  = rect.size;

                Handles.BeginGUI();
                if (listA.Count > 0)
                {
                    for (var i = listA.Count - 1; i >= 0; i--)
                    {
                        var coord = listA[i];

                        coord.x = pos.x + siz.x * coord.x;
                        coord.y = pos.y + siz.y * (1.0f - coord.y);

                        arrayA[i] = coord;
                    }

                    Handles.DrawLines(arrayA);

                    for (var i = listB.Count - 1; i >= 0; i--)
                    {
                        var coord = listB[i];

                        coord.x = pos.x + siz.x * coord.x;
                        coord.y = pos.y + siz.y * (1.0f - coord.y);

                        arrayB[i] = coord;
                    }

                    Handles.color = Color.red;
                    Handles.DrawLines(arrayB);
                }
                Handles.EndGUI();
            }
            else
            {
                EditorGUILayout.HelpBox("No Mesh Selected.\nTo select a mesh, click Analyze Mesh from the P3dPaintable component, or from the Mesh inspector context menu (gear icon at top right).", MessageType.Info);
            }
        }
Esempio n. 26
0
        private void DrawBrush(P3dBrush brush)
        {
            var rect   = P3dHelper.Reserve();
            var rectS  = GetRect(rect, rect.xMin, rect.xMin + 18);
            var rectA  = GetRect(rect, rect.xMin + 20, rect.xMax - 102);
            var rectB  = GetRect(rect, rect.xMax - 100, rect.xMax - 40);
            var rectC  = GetRect(rect, rect.xMax - 40, rect.xMax);
            var active = P3dWindowData.Instance.CurrentBrushesSafe.Contains(brush);
            var locked = Locked.Contains(brush);

            if (buttonL == null)
            {
                buttonL = new GUIStyle(EditorStyles.helpBox);
                //buttonL.fontSize = 15;
                buttonL.clipping = TextClipping.Overflow;
            }

            EditorGUI.BeginDisabledGroup(locked == true);
            P3dHelper.BeginColor(active == true ? Color.green : Color.white);
            if (GUI.Button(rectA, brush.name, buttonL) == true)
            {
                if (Event.current.control == true || Event.current.shift == true)
                {
                    if (active == true)
                    {
                        P3dWindowData.Instance.CurrentBrushesSafe.Remove(brush);
                    }
                    else
                    {
                        P3dWindowData.Instance.CurrentBrushesSafe.Add(brush);
                    }
                }
                else
                {
                    var count = P3dWindowData.Instance.CurrentBrushesSafe.RemoveAll(b => Locked.Contains(b) == false);

                    if (active == false || count > 1)
                    {
                        P3dWindowData.Instance.CurrentBrushesSafe.Add(brush);
                    }
                }
            }
            P3dHelper.EndColor();
            EditorGUI.EndDisabledGroup();

            EditorGUI.BeginDisabledGroup(active == false);
            P3dHelper.BeginColor(locked == true ? Color.green : Color.white);
            if (GUI.Button(rectB, locked == true ? "Unlock" : "Lock", EditorStyles.miniButtonLeft) == true)
            {
                if (locked == true)
                {
                    Locked.Remove(brush);
                }
                else
                {
                    Locked.Add(brush);
                }
            }
            P3dHelper.EndColor();
            EditorGUI.EndDisabledGroup();

            if (GUI.Button(rectC, new GUIContent("Find", "Select the brush in the project?"), EditorStyles.miniButtonRight) == true)
            {
                Selection.activeObject = brush;

                EditorGUIUtility.PingObject(brush);
            }

            var starred = P3dWindowData.Instance.FavouriteBrushesSafe.Contains(brush) == true;

            if (DrawStarButton(rectS, starred) == true)
            {
                if (starred == true)
                {
                    P3dWindowData.Instance.FavouriteBrushesSafe.Remove(brush);
                }
                else
                {
                    P3dWindowData.Instance.FavouriteBrushesSafe.Add(brush);
                }
            }
        }
Esempio n. 27
0
        private void UpdateObjectsPanel()
        {
            if (Selection.gameObjects.Length == 0 && scene.Objs.Count == 0)
            {
                EditorGUILayout.HelpBox("Select a GameObject with a MesFilter+MeshRenderer or SkinnedMeshRenderer.", MessageType.Info);
            }

            // Mark
            tempObjs.ForEach(t => t.Dirty = true);

            roots.Clear();

            foreach (var transform in Selection.transforms)
            {
                RunRoots(transform);
            }

            foreach (var root in roots)
            {
                if (scene.ObjExists(root) == false)
                {
                    var mf  = root.GetComponent <MeshFilter>();
                    var mr  = root.GetComponent <MeshRenderer>();
                    var smr = root.GetComponent <SkinnedMeshRenderer>();

                    if (mf != null && mr != null && mf.sharedMesh != null)
                    {
                        if (DrawAddableObject(root.gameObject, mr.sharedMaterials) == true)
                        {
                            scene.AddObj(root, mf.sharedMesh, root.position, root.rotation, root.lossyScale, mr.sharedMaterials, tempTemplates.ToArray(), settings.DefaultTextureSize);
                        }
                    }
                    else if (smr != null && smr.sharedMesh != null)
                    {
                        if (DrawAddableObject(root.gameObject, smr.sharedMaterials) == true)
                        {
                            scene.AddObj(root, smr.sharedMesh, root.position, root.rotation, root.lossyScale, smr.sharedMaterials, tempTemplates.ToArray(), settings.DefaultTextureSize);
                        }
                    }
                }
            }

            // Sweep
            tempObjs.RemoveAll(t => t.Dirty == true);

            EditorGUILayout.Separator();

            for (var i = 0; i < scene.Objs.Count; i++)
            {
                if (i > 0)
                {
                    EditorGUILayout.Space();
                }

                var obj     = scene.Objs[i];
                var objRect =
                    EditorGUILayout.BeginVertical(GetSelectableStyle(obj == currentObj, true));
                P3dHelper.BeginLabelWidth(60.0f);
                if (obj == currentObj)
                {
                    EditorGUILayout.BeginHorizontal();
                    obj.Name = EditorGUILayout.TextField(obj.Name);
                    if (GUILayout.Button("X", EditorStyles.miniButton, GUILayout.Width(20)) == true && EditorUtility.DisplayDialog("Are you sure?", "This will delete the current layer from the paint window.", "Delete") == true)
                    {
                        scene.RemoveObj(obj); i--; P3dHelper.ClearControl();
                    }
                    EditorGUILayout.EndHorizontal();

                    obj.Mesh      = (Mesh)EditorGUILayout.ObjectField("Mesh", obj.Mesh, typeof(Mesh), true);
                    obj.Paintable = EditorGUILayout.Toggle("Paintable", obj.Paintable);
                    obj.Coord     = (P3dCoord)EditorGUILayout.EnumPopup("Coord", obj.Coord);
                    obj.Transform = (Transform)EditorGUILayout.ObjectField("Transform", obj.Transform, typeof(Transform), true);
                    obj.Preview   = (Transform)EditorGUILayout.ObjectField("Preview", obj.Preview, typeof(Transform), true);

                    if (obj.Transform == null)
                    {
                        obj.Position = EditorGUILayout.Vector3Field("Position", obj.Position);

                        EditorGUI.BeginChangeCheck();
                        var newRot = EditorGUILayout.Vector3Field("Rotation", obj.Rotation.eulerAngles);
                        if (EditorGUI.EndChangeCheck() == true)
                        {
                            obj.Rotation = Quaternion.Euler(newRot);
                        }

                        obj.Scale = EditorGUILayout.Vector3Field("Scale", obj.Scale);
                    }
                    else
                    {
                        var smr = obj.Transform.GetComponent <SkinnedMeshRenderer>();

                        if (smr != null && smr.sharedMesh != null)
                        {
                            if (obj.BakedMesh == null)
                            {
                                if (GUILayout.Button("Bake Pose") == true)
                                {
                                    BakeMesh(smr, ref obj.BakedMesh, false);
                                }

                                if (GUILayout.Button("Bake Pose + Scale") == true)
                                {
                                    BakeMesh(smr, ref obj.BakedMesh, true);
                                }
                            }
                            else
                            {
                                if (GUILayout.Button("Update Pose") == true)
                                {
                                    BakeMesh(smr, ref obj.BakedMesh, obj.BakedMesh.name == "SCALED");
                                }

                                if (GUILayout.Button("Reset Pose") == true)
                                {
                                    DestroyImmediate(obj.BakedMesh);

                                    obj.BakedMesh = null;
                                }
                            }
                        }
                    }

                    if (GUILayout.Button("Center Camera") == true)
                    {
                        cameraOrigin = obj.Position;
                    }

                    EditorGUILayout.Separator();

                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.LabelField("Materials", EditorStyles.boldLabel);
                    if (GUILayout.Button("+", EditorStyles.miniButton, GUILayout.Width(20)) == true)
                    {
                        obj.MatIds.Add(-1);
                    }
                    EditorGUILayout.EndHorizontal();

                    for (var j = 0; j < obj.MatIds.Count; j++)
                    {
                        var matId = obj.MatIds[j];
                        var rect  = P3dHelper.Reserve(); rect.xMin += 10;
                        var mat   = scene.GetMat(matId);

                        if (GUI.Button(rect, mat != null ? mat.Name : "", EditorStyles.popup) == true)
                        {
                            var menu = new GenericMenu();

                            for (var k = 0; k < scene.Mats.Count; k++)
                            {
                                var setObj = obj;
                                var setIdx = j;
                                var setMat = scene.Mats[k];

                                menu.AddItem(new GUIContent(setMat.Name), setMat == mat, () => setObj.MatIds[setIdx] = setMat.Id);
                            }

                            var remObj = obj;
                            var remIdx = j;

                            menu.AddSeparator("");
                            menu.AddItem(new GUIContent("Remove"), false, () => remObj.MatIds.RemoveAt(remIdx));

                            menu.DropDown(rect);
                        }
                    }
                }
                else
                {
                    EditorGUILayout.LabelField(obj.Name);
                }
                P3dHelper.EndLabelWidth();
                EditorGUILayout.EndVertical();

                if (Event.current.type == EventType.MouseDown && objRect.Contains(Event.current.mousePosition) == true)
                {
                    currentObj = obj; P3dHelper.ClearControl();
                }
            }
        }