/// <summary>
 /// Inspector GUI shown in the Editor window.
 /// </summary>
 /// <param name="brushSettings"></param>
 internal virtual void DrawGUI(BrushSettings brushSettings)
 {
     if (PolyGUILayout.HeaderWithDocsLink(PolyGUI.TempContent(ModeSettingsHeader, "")))
     {
         Application.OpenURL(DocsLink);
     }
 }
Example #2
0
        internal static uint BitMaskField(uint value, string[] descriptions, string tooltip)
        {
            GUIContent gc = PolyGUI.TempContent("", tooltip);

            using (new GUILayout.HorizontalScope())
            {
                int l = descriptions.Length;

                for (int i = 1; i < l; i++)
                {
                    int s = i - 1;

                    bool toggled = (value & (1u << s)) > 0;

                    gc.text = descriptions[i];

                    bool newValue = GUILayout.Toggle(toggled, gc, "Button", GUILayout.Width(30));

                    if (toggled != newValue)
                    {
                        value ^= (1u << s);
                    }
                }
            }

            return(value);
        }
Example #3
0
        internal static Gradient GradientField(GUIContent gc, Gradient value)
        {
            GUILayout.Label(gc);

            object out_gradient = EditorGUILayout.GradientField(PolyGUI.TempContent("", gc.tooltip), value, null);

            return((Gradient)out_gradient);
        }
Example #4
0
        public static bool Foldout(bool state, GUIContent content, GUILayoutOption[] options)
        {
            if (GUILayout.Button(PolyGUI.TempContent(""), state ? "FoldoutOpen" : "FoldoutClosed", options))
            {
                state = !state;
            }

            GUILayout.Label(content, options);
            return(state);
        }
Example #5
0
        internal static Color ColorField(GUIContent gc, Color color)
        {
            if (gc != null && !string.IsNullOrEmpty(gc.text))
            {
                GUILayout.Label(gc);
            }

            var ret = EditorGUILayout.ColorField(PolyGUI.TempContent("", gc.tooltip), color);

            return(ret);
        }
        /// <summary>
        /// Copy/paste of Unity TextAssetInspector, since DrawDefaultInspector doesn't work with TextAssets.
        /// Not using reflection because this is such a small function that it makes more sense to just c/p
        /// and avoid the issues of Unity possibly changing names or signatures in the future.
        /// </summary>
        private void DrawTextAssetInspector()
        {
            if (m_TextStyle == null)
            {
                m_TextStyle = "ScriptText";
            }

            bool enabled = GUI.enabled;

            GUI.enabled = true;

            TextAsset textAsset = this.target as TextAsset;

            if (textAsset != null)
            {
                string text;

                if (base.targets.Length > 1)
                {
                    text = string.Format("{0} Text Assets", base.targets.Length);
                }
                else
                {
                    text = textAsset.ToString();
                    if (text.Length > 7000)
                    {
                        text = text.Substring(0, 7000) + "...\n\n<...etc...>";
                    }
                }
                Rect rect = GUILayoutUtility.GetRect(PolyGUI.TempContent(text), m_TextStyle);
                rect.x     = 0f;
                rect.y    -= 3f;
                rect.width = EditorGUIUtility.currentViewWidth - 1;                 // GUIClip.visibleRect.width + 1f;
                GUI.Box(rect, text, m_TextStyle);
            }
            GUI.enabled = enabled;
        }
Example #7
0
        /// <summary>
        /// Show the specific placement settings for a prefab in the palette
        /// </summary>
        /// <param name="prefab">The prefab whose settings we're showing</param>
        /// <param name="index">The index of the prefab in `prefabs`</param>
        private void DrawSinglePrefabPlacementSettings(SerializedProperty prefab, int index)
        {
            SerializedProperty go       = prefab.FindPropertyRelative("gameObject");
            SerializedProperty settings = prefab.FindPropertyRelative("settings");
            SerializedProperty name     = prefab.FindPropertyRelative("name");

            SerializedProperty uniformBool   = settings.FindPropertyRelative("m_UniformBool");
            SerializedProperty strength      = settings.FindPropertyRelative("m_Strength");
            SerializedProperty minRot        = settings.FindPropertyRelative("m_RotationRangeMin");
            SerializedProperty maxRot        = settings.FindPropertyRelative("m_RotationRangeMax");
            SerializedProperty minScale      = settings.FindPropertyRelative("m_ScaleRangeMin");
            SerializedProperty maxScale      = settings.FindPropertyRelative("m_ScaleRangeMax");
            SerializedProperty xScaleBool    = settings.FindPropertyRelative("m_XScaleBool");
            SerializedProperty yScaleBool    = settings.FindPropertyRelative("m_YScaleBool");
            SerializedProperty zScaleBool    = settings.FindPropertyRelative("m_ZScaleBool");
            SerializedProperty xRotationBool = settings.FindPropertyRelative("m_XRotationBool");
            SerializedProperty yRotationBool = settings.FindPropertyRelative("m_YRotationBool");
            SerializedProperty zRotationBool = settings.FindPropertyRelative("m_ZRotationBool");

            const int pad = 4;

            var settingsBackgroundStyle = new GUIStyle();

            settingsBackgroundStyle.normal.background = EditorGUIUtility.whiteTexture;
            settingsBackgroundStyle.padding           = new RectOffset(0, 0, 0, 0);
            PolyGUI.PushBackgroundColor(EditorGUIUtility.isProSkin ? PolyGUI.k_BoxBackgroundDark : PolyGUI.k_BoxBackgroundLight);

            EditorGUILayout.BeginVertical(settingsBackgroundStyle);

            GUILayout.Space(pad);

            PolyGUI.PopBackgroundColor();

            using (new GUILayout.HorizontalScope())
            {
                GUILayout.Space(pad);

                /// Name field And Strenght Slider
                using (new GUILayout.VerticalScope())
                {
                    GUILayout.Space(EditorGUIUtility.standardVerticalSpacing);
                    GUI.SetNextControlName("cancelbackspace1" + index);
                    name.stringValue = GUILayout.TextField(name.stringValue, GUILayout.ExpandWidth(true));
                    GUILayout.Space(EditorGUIUtility.standardVerticalSpacing);

                    using (new GUILayout.HorizontalScope())
                    {
                        GUI.SetNextControlName("cancelbackspace2" + index);
                        strength.floatValue = EditorGUILayout.Slider("Frequency (%)", strength.floatValue,
                                                                     BrushModePrefab.k_PrefabOccurrenceMin, BrushModePrefab.k_PrefabOccurrenceMax, GUILayout.ExpandWidth(true));
                    }
                }
                GUILayout.Space(pad);
            }

            GUILayout.BeginVertical();

            float floatfieldWidth = EditorGUIUtility.currentViewWidth / 10;

            GUILayoutOption[] floatFieldsOptions = new GUILayoutOption[] { GUILayout.Width(floatfieldWidth), GUILayout.MinWidth(40) };
            GUILayoutOption   widthConstraint    = GUILayout.Width(15);

            int slidersMargin = 15;

            EditorGUILayout.LabelField("Randomize Scale");

            EditorGUILayout.BeginHorizontal();
            GUILayout.Space(slidersMargin);
            EditorGUILayout.LabelField("Uniform Scale", GUILayout.Width(90));
            uniformBool.boolValue = EditorGUILayout.Toggle(uniformBool.boolValue, widthConstraint);
            GUILayout.FlexibleSpace();
            if (uniformBool.boolValue)
            {
                SerializedProperty uScale       = settings.FindPropertyRelative("m_UniformScale");
                Vector2            uniformScale = uScale.vector2Value;
                GUILayout.Space(slidersMargin);
                GUI.SetNextControlName("cancelbackspace3" + index);
                uniformScale.x = EditorGUILayout.FloatField(uniformScale.x, floatFieldsOptions);
                EditorGUILayout.MinMaxSlider(ref uniformScale.x, ref uniformScale.y, 0.0f, 10f);
                GUI.SetNextControlName("cancelbackspace4" + index);
                uniformScale.y = EditorGUILayout.FloatField(uniformScale.y, floatFieldsOptions);
                GUILayout.FlexibleSpace();
                uScale.vector2Value = uniformScale;
                EditorGUILayout.EndHorizontal();
            }
            else
            {
                EditorGUILayout.EndHorizontal();
                //Random Scale
                Vector3 scaleRangeMin = minScale.vector3Value;
                Vector3 scaleRangeMax = maxScale.vector3Value;

                using (new GUILayout.HorizontalScope())
                {
                    GUILayout.Space(slidersMargin);
                    xScaleBool.boolValue = EditorGUILayout.Toggle(xScaleBool.boolValue, widthConstraint);
                    EditorGUILayout.LabelField("X", widthConstraint);
                    GUI.SetNextControlName("cancelbackspace5" + index);
                    scaleRangeMin.x = EditorGUILayout.FloatField(scaleRangeMin.x, floatFieldsOptions);
                    EditorGUILayout.MinMaxSlider(ref scaleRangeMin.x, ref scaleRangeMax.x, 0.0f, 10f);
                    GUI.SetNextControlName("cancelbackspace6" + index);
                    scaleRangeMax.x = EditorGUILayout.FloatField(scaleRangeMax.x, floatFieldsOptions);
                }

                using (new GUILayout.HorizontalScope())
                {
                    GUILayout.Space(slidersMargin);
                    yScaleBool.boolValue = EditorGUILayout.Toggle(yScaleBool.boolValue, widthConstraint);
                    EditorGUILayout.LabelField("Y", widthConstraint);
                    GUI.SetNextControlName("cancelbackspace7" + index);
                    scaleRangeMin.y = EditorGUILayout.FloatField(scaleRangeMin.y, floatFieldsOptions);
                    EditorGUILayout.MinMaxSlider(ref scaleRangeMin.y, ref scaleRangeMax.y, 0.0f, 10f);
                    GUI.SetNextControlName("cancelbackspace8" + index);
                    scaleRangeMax.y = EditorGUILayout.FloatField(scaleRangeMax.y, floatFieldsOptions);
                }
                using (new GUILayout.HorizontalScope())
                {
                    GUILayout.Space(slidersMargin);
                    zScaleBool.boolValue = EditorGUILayout.Toggle(zScaleBool.boolValue, widthConstraint);
                    EditorGUILayout.LabelField("Z", widthConstraint);
                    GUI.SetNextControlName("cancelbackspace9" + index);
                    scaleRangeMin.z = EditorGUILayout.FloatField(scaleRangeMin.z, floatFieldsOptions);
                    EditorGUILayout.MinMaxSlider(ref scaleRangeMin.z, ref scaleRangeMax.z, 0.0f, 10f);
                    GUI.SetNextControlName("cancelbackspace10" + index);
                    scaleRangeMax.z = EditorGUILayout.FloatField(scaleRangeMax.z, floatFieldsOptions);
                }
                minScale.vector3Value = scaleRangeMin;
                maxScale.vector3Value = scaleRangeMax;
            }

            // Random Rotation
            Vector3 rotationRangeMin = minRot.vector3Value;
            Vector3 rotationRangeMax = maxRot.vector3Value;

            EditorGUILayout.LabelField("Randomize Rotation");

            using (new GUILayout.HorizontalScope())
            {
                GUILayout.Space(slidersMargin);
                xRotationBool.boolValue = EditorGUILayout.Toggle(xRotationBool.boolValue, widthConstraint);
                EditorGUILayout.LabelField("X", widthConstraint);
                GUI.SetNextControlName("cancelbackspace11" + index);
                rotationRangeMin.x = EditorGUILayout.FloatField(rotationRangeMin.x, floatFieldsOptions);
                EditorGUILayout.MinMaxSlider(ref rotationRangeMin.x, ref rotationRangeMax.x, 0.0f, 360f);
                GUI.SetNextControlName("cancelbackspace12" + index);
                rotationRangeMax.x = EditorGUILayout.FloatField(rotationRangeMax.x, floatFieldsOptions);
            }

            using (new GUILayout.HorizontalScope())
            {
                GUILayout.Space(slidersMargin);
                yRotationBool.boolValue = EditorGUILayout.Toggle(yRotationBool.boolValue, widthConstraint);
                EditorGUILayout.LabelField("Y", widthConstraint);
                GUI.SetNextControlName("cancelbackspace13" + index);
                rotationRangeMin.y = EditorGUILayout.FloatField(rotationRangeMin.y, floatFieldsOptions);
                EditorGUILayout.MinMaxSlider(ref rotationRangeMin.y, ref rotationRangeMax.y, 0.0f, 360f);
                GUI.SetNextControlName("cancelbackspace14" + index);
                rotationRangeMax.y = EditorGUILayout.FloatField(rotationRangeMax.y, floatFieldsOptions);
            }

            using (new GUILayout.HorizontalScope())
            {
                GUILayout.Space(slidersMargin);
                zRotationBool.boolValue = EditorGUILayout.Toggle(zRotationBool.boolValue, widthConstraint);
                EditorGUILayout.LabelField("Z", widthConstraint);
                GUI.SetNextControlName("cancelbackspace15" + index);
                rotationRangeMin.z = EditorGUILayout.FloatField(rotationRangeMin.z, floatFieldsOptions);
                EditorGUILayout.MinMaxSlider(ref rotationRangeMin.z, ref rotationRangeMax.z, 0.0f, 360f);
                GUI.SetNextControlName("cancelbackspace16" + index);
                rotationRangeMax.z = EditorGUILayout.FloatField(rotationRangeMax.z, floatFieldsOptions);
            }
            minRot.vector3Value = rotationRangeMin;
            maxRot.vector3Value = rotationRangeMax;
            GUILayout.EndVertical();

            GUILayout.Space(pad);
            GUILayout.EndVertical();
            GUILayout.Space(pad);
        }
Example #8
0
 /// <summary>
 /// Color field control
 /// </summary>
 /// <param name="text"></param>
 /// <param name="mask"></param>
 /// <returns></returns>
 internal static ColorMask ColorMaskField(string text, ColorMask mask)
 {
     return(ColorMaskField(string.IsNullOrEmpty(text) ? null : PolyGUI.TempContent(text), mask));
 }
Example #9
0
 /// <summary>
 /// Similar to EditorGUILayoutUtility.Slider, except this allows for values outside of the min/max bounds via the float field.
 /// </summary>
 /// <param name="content"></param>
 /// <param name="value"></param>
 /// <param name="min"></param>
 /// <param name="max"></param>
 /// <returns></returns>
 internal static float FreeSlider(string content, float value, float min, float max)
 {
     return(FreeSlider(PolyGUI.TempContent(content), value, min, max));
 }
Example #10
0
        void DrawBrushSettings()
        {
            // Brush preset selector
            using (new GUILayout.VerticalScope("box"))
            {
                // Show the settings header in PolyEditor so that the preset selector can be included in the block.
                // Can't move preset selector to BrushSettingsEditor because it's a CustomEditor for BrushSettings,
                // along with other issues.
                if (PolyGUILayout.HeaderWithDocsLink(PolyGUI.TempContent("Brush Settings")))
                {
                    Application.OpenURL(PrefUtility.documentationBrushSettingsLink);
                }

                using (new GUILayout.HorizontalScope())
                {
                    EditorGUI.BeginChangeCheck();

                    m_CurrentBrushIndex = EditorGUILayout.Popup(m_CurrentBrushIndex, m_AvailableBrushesStrings, "Popup");

                    if (EditorGUI.EndChangeCheck())
                    {
                        if (m_CurrentBrushIndex >= m_AvailableBrushes.Count)
                        {
                            SetBrushSettings(BrushSettingsEditor.AddNew(brushSettings));
                        }
                        else
                        {
                            SetBrushSettings(m_AvailableBrushes[m_CurrentBrushIndex]);
                        }
                    }

                    if (GUILayout.Button(m_GCSaveBrushSettings, GUILayout.Width(40)))
                    {
                        if (brushSettings != null && brushSettingsAsset != null)
                        {
                            // integer 0, 1 or 2 corresponding to ok, cancel and alt buttons
                            int res = EditorUtility.DisplayDialogComplex("Save Brush Settings", "Overwrite brush preset, or Create a New brush preset? ", "Overwrite", "Create New", "Cancel");

                            if (res == 0)
                            {
                                brushSettings.CopyTo(brushSettingsAsset);
                                EditorGUIUtility.PingObject(brushSettingsAsset);
                            }
                            else if (res == 1)
                            {
                                BrushSettings dup = BrushSettingsEditor.AddNew(brushSettings);
                                SetBrushSettings(dup);
                                EditorGUIUtility.PingObject(brushSettingsAsset);
                            }
                        }
                        else
                        {
                            Debug.LogWarning("Something went wrong saving brush settings.");
                        }
                    }
                }
                EditorGUI.BeginChangeCheck();

                brushEditor.OnInspectorGUI();
            }
        }
        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            EditorGUILayout.ObjectField("Shader", shader, typeof(Shader), false);

            for (int i = 0; i < p_attributes.arraySize; i++)
            {
                SerializedProperty attrib = p_attributes.GetArrayElementAtIndex(i);

                GUI.backgroundColor = i % 2 == 0 ? LIGHT_GRAY : DARK_GRAY;
                GUILayout.BeginVertical(PolyGUI.BackgroundColorStyle);
                GUI.backgroundColor = Color.white;

                SerializedProperty target  = attrib.FindPropertyRelative("propertyTarget");
                SerializedProperty channel = attrib.FindPropertyRelative("channel");
                SerializedProperty index   = attrib.FindPropertyRelative("index");
                SerializedProperty range   = attrib.FindPropertyRelative("range");
                SerializedProperty mask    = attrib.FindPropertyRelative("mask");

                EditorGUILayout.PropertyField(target);
                EditorGUILayout.PropertyField(channel);
                EditorGUILayout.IntPopup(index, ComponentIndexUtility.ComponentIndexPopupDescriptions, ComponentIndexUtility.ComponentIndexPopupValues);

                bool old = EditorGUIUtility.wideMode;
                EditorGUIUtility.wideMode = true;
                EditorGUILayout.PropertyField(range);
                EditorGUIUtility.wideMode = old;

                EditorGUILayout.IntPopup(mask, AttributeLayout.DefaultMaskDescriptions, AttributeLayout.DefaultMaskValues, PolyGUI.TempContent("Group"));

                GUILayout.BeginHorizontal();

                GUILayout.FlexibleSpace();

                if (GUILayout.Button("Delete", EditorStyles.miniButton))
                {
                    p_attributes.DeleteArrayElementAtIndex(i);
                }

                GUILayout.EndHorizontal();

                GUILayout.EndVertical();
            }

            if (GUILayout.Button("Add Attribute"))
            {
                p_attributes.arraySize++;
            }

            serializedObject.ApplyModifiedProperties();
        }