Esempio n. 1
0
        void OnGUI()
        {
            if (Selection.activeGameObject == null)
            {
                EditorGUILayout.LabelField("No objects selected. Please select an object with a MeshFilter and Renderer");
                return;
            }

            if (swatches == null)
            {
                swatches = ColorSwatches.CreateInstance <ColorSwatches>();
                if (EditorPrefs.HasKey(sSwatchKey))
                {
                    JsonUtility.FromJsonOverwrite(EditorPrefs.GetString(sSwatchKey), swatches);
                }
                if (swatches == null)
                {
                    swatches = ColorSwatches.CreateInstance <ColorSwatches>();
                    EditorPrefs.SetString(sSwatchKey, JsonUtility.ToJson(swatches, false));
                }
            }

            DrawChannelGUI();

            var ot = tab;

            tab = (Tab)GUILayout.Toolbar((int)tab, TAB_NAMES);
            if (ot != tab)
            {
                UpdateDisplayMode();
            }

            if (tab == Tab.Paint)
            {
                scroll = EditorGUILayout.BeginScrollView(scroll);
                DrawPaintGUI();
            }
            else if (tab == Tab.Deform)
            {
                scroll = EditorGUILayout.BeginScrollView(scroll);
                DrawDeformGUI();
            }
            else if (tab == Tab.Flow)
            {
                scroll = EditorGUILayout.BeginScrollView(scroll);
                DrawFlowGUI();
            }
            else if (tab == Tab.Utility)
            {
                scroll = EditorGUILayout.BeginScrollView(scroll);
                DrawUtilityGUI();
            }
            else if (tab == Tab.Custom)
            {
                DrawCustomGUI();
            }
            EditorGUILayout.EndScrollView();
        }
Esempio n. 2
0
        void DrawPaintGUI()
        {
            GUILayout.Box("Brush Settings", new GUILayoutOption[] { GUILayout.ExpandWidth(true), GUILayout.Height(20) });
            var oldBM = brushMode;

            brushMode = (BrushTarget)EditorGUILayout.EnumPopup("Target Channel", brushMode);
            if (oldBM != brushMode)
            {
                UpdateDisplayMode();
            }
            if (brushMode == BrushTarget.Color || brushMode == BrushTarget.UV0_AsColor || brushMode == BrushTarget.UV1_AsColor ||
                brushMode == BrushTarget.UV2_AsColor || brushMode == BrushTarget.UV3_AsColor)
            {
                brushColorMode = (BrushColorMode)EditorGUILayout.EnumPopup("Blend Mode", (System.Enum)brushColorMode);

                if (brushColorMode == BrushColorMode.Overlay || brushColorMode == BrushColorMode.Normal)
                {
                    brushColor = EditorGUILayout.ColorField("Brush Color", brushColor);

                    if (GUILayout.Button("Reset Palette", EditorStyles.miniButton, GUILayout.Width(80), GUILayout.Height(16)))
                    {
                        if (swatches != null)
                        {
                            DestroyImmediate(swatches);
                        }
                        swatches = ColorSwatches.CreateInstance <ColorSwatches>();
                        EditorPrefs.SetString(sSwatchKey, JsonUtility.ToJson(swatches, false));
                    }

                    GUILayout.BeginHorizontal();

                    for (int i = 0; i < swatches.colors.Length; ++i)
                    {
                        if (GUILayout.Button("", EditorStyles.textField, GUILayout.Width(16), GUILayout.Height(16)))
                        {
                            brushColor = swatches.colors[i];
                        }
                        EditorGUI.DrawRect(new Rect(GUILayoutUtility.GetLastRect().x + 1, GUILayoutUtility.GetLastRect().y + 1, 14, 14), swatches.colors[i]);
                    }
                    GUILayout.EndHorizontal();
                    GUILayout.BeginHorizontal();
                    for (int i = 0; i < swatches.colors.Length; i++)
                    {
                        if (GUILayout.Button("+", EditorStyles.miniButton, GUILayout.Width(16), GUILayout.Height(12)))
                        {
                            swatches.colors[i] = brushColor;
                            EditorPrefs.SetString(sSwatchKey, JsonUtility.ToJson(swatches, false));
                        }
                    }
                    GUILayout.EndHorizontal();
                }
            }
            else if (brushMode == BrushTarget.ValueR || brushMode == BrushTarget.ValueG || brushMode == BrushTarget.ValueB || brushMode == BrushTarget.ValueA)
            {
                brushValue = (int)EditorGUILayout.Slider("Brush Value", (float)brushValue, 0.0f, 256.0f);
            }
            else
            {
                floatBrushValue = EditorGUILayout.FloatField("Brush Value", floatBrushValue);
                var oldUVRange = uvVisualizationRange;
                uvVisualizationRange = EditorGUILayout.Vector2Field("Visualize Range", uvVisualizationRange);
                if (oldUVRange != uvVisualizationRange)
                {
                    UpdateDisplayMode();
                }
            }

            DrawBrushSettingsGUI();

            //GUILayout.Box("", new GUILayoutOption[]{GUILayout.ExpandWidth(true), GUILayout.Height(1)});
            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button("Fill"))
            {
                if (OnBeginStroke != null)
                {
                    OnBeginStroke(jobs);
                }
                for (int i = 0; i < jobs.Length; ++i)
                {
                    Undo.RecordObject(jobs[i].stream, "Vertex Painter Fill");
                    FillMesh(jobs[i]);
                }
                if (OnEndStroke != null)
                {
                    OnEndStroke();
                }
                Undo.CollapseUndoOperations(Undo.GetCurrentGroup());
            }
            if (GUILayout.Button("Random"))
            {
                for (int i = 0; i < jobs.Length; ++i)
                {
                    Undo.RecordObject(jobs[i].stream, "Vertex Painter Fill");
                    RandomMesh(jobs[i]);
                }
            }
            EditorGUILayout.EndHorizontal();
        }