public override void DrawItem(Rect position, int index)
        {
            //To-be modified original-- caching original position
            Rect pos   = position;
            var  splat = this[index];

            //Insert top padding & set height
            pos.y     += 8f;
            pos.height = CTRL_HEIGHT * 2.5f;

            if (splat.Diffuse == null)
            {
                EditorGUI.HelpBox(pos, "This splat material does not have a selected diffuse texture.", MessageType.Warning);
                pos.y += CTRL_HEIGHT * 2.5f + PADDING_SM;
            }
            else
            {
                float texWidth = (pos.width / 2) - PADDING;

                Rect texPos   = new Rect(pos.x, pos.y, texWidth, TEX_HEIGHT);
                Rect labelPos = new Rect(texPos.x, texPos.y + TEX_HEIGHT + PADDING_SM, texWidth, TEX_CAPTION_HEIGHT);

                GUIStyle centeredStyle = GUI.skin.GetStyle("Label");
                centeredStyle.alignment = TextAnchor.UpperCenter;

                EditorGUI.ObjectField(texPos, splat.Diffuse, typeof(Texture2D), false);
                EditorGUI.LabelField(labelPos, "Diffuse", centeredStyle);

                if (splat.Normal != null)
                {
                    texPos.x   += texPos.width + 8;
                    labelPos.x += texPos.width + PADDING;

                    splat.Normal = (Texture2D)EditorGUI.ObjectField(texPos, splat.Normal, typeof(Texture2D), false);
                    EditorGUI.LabelField(labelPos, "Normal", centeredStyle);
                }

                //Update position
                pos.y += TEX_HEIGHT + labelPos.height + PADDING;
            }

            //Reset referenced height
            pos.height = CTRL_HEIGHT;

            if (GUI.Button(new Rect(pos.x, pos.y, pos.width, pos.height + 2), "Edit Material"))
            {
                AddTextureWindow.Init(ref splat);
            }
            pos.y += CTRL_HEIGHT + PADDING;

            //Blend factor
            splat.Blend = EditorGUI.FloatField(pos, "Blend Amount", splat.Blend);
            pos.y      += CTRL_HEIGHT + PADDING_SM;

            //Constrain Height
            splat.ConstrainHeight = EditorGUI.Toggle(pos, "Constrain Height", splat.ConstrainHeight);
            pos.y += CTRL_HEIGHT + PADDING_SM;
            if (splat.ConstrainHeight)
            {
                EditorGUI.indentLevel++;
                splat.HeightConstraint = EditorGUIExtension.DrawConstraintRange(pos, "Height", splat.HeightConstraint, 0, 1);

                pos.y += (CTRL_HEIGHT + PADDING_SM) * 2;

                float startX = pos.x;
                pos.x = EditorGUI.IndentedRect(pos).x;
                EditorGUI.indentLevel--;

                //Checkboxes for infinity & -infinity heights
                EditorGUI.BeginChangeCheck();
                if (splat.IsMaxHeight || !_detail.IsMaxHeightSelected)
                {
                    splat.IsMaxHeight = EditorGUI.Toggle(pos, "Is Highest Material", splat.IsMaxHeight);
                    pos.y            += CTRL_HEIGHT + PADDING_SM;
                }
                if (EditorGUI.EndChangeCheck())
                {
                    _detail.IsMaxHeightSelected = splat.IsMaxHeight;
                }

                EditorGUI.BeginChangeCheck();
                if (splat.IsMinHeight || !_detail.IsMinHeightSelected)
                {
                    splat.IsMinHeight = EditorGUI.Toggle(pos, "Is Lowest Material", splat.IsMinHeight);
                    pos.y            += CTRL_HEIGHT + PADDING_SM;
                }
                if (EditorGUI.EndChangeCheck())
                {
                    _detail.IsMinHeightSelected = splat.IsMinHeight;
                }

                pos.x = startX;
            }

            //Constrain Angle
            splat.ConstrainAngle = EditorGUI.Toggle(pos, "Constrain Angle", splat.ConstrainAngle);
            pos.y += CTRL_HEIGHT + PADDING_SM;
            if (splat.ConstrainAngle)
            {
                EditorGUI.indentLevel++;
                splat.AngleConstraint = EditorGUIExtension.DrawConstraintRange(pos, "Angle", splat.AngleConstraint, 0, 90);
                EditorGUI.indentLevel--;
            }
        }
    public override void DrawItem(Rect position, int index)
    {
        bool isRepaint = Event.current.type == EventType.Repaint;

        if (isRepaint)
        {
            _positions[index] = position;
        }

        //Resize area to fit within list gui
        var areaPos = _positions.ContainsKey(index) ? _positions[index] : new Rect();

        areaPos.x     += 6;
        areaPos.y     += 8;
        areaPos.width -= 6;

        //Cache object instance
        var obj = this[index];

        if (obj == null)
        {
            return;
        }

        int startIndent = EditorGUI.indentLevel;

        GUILayout.BeginArea(areaPos);

        //General
        obj.Prefab               = (GameObject)EditorGUILayout.ObjectField("Prefab", obj.Prefab, typeof(GameObject), false);
        obj.AllowsIntersection   = EditorGUILayout.Toggle("Can Intersect", obj.AllowsIntersection);
        obj.PlacementProbability = EditorGUILayout.IntSlider("Place Probability", obj.PlacementProbability, 0, 100);
        obj.Spread               = EditorGUILayout.Slider("Object Spread", obj.Spread, 5f, 50f);
        obj.MaxObjects           = EditorGUILayout.IntField("Max Objects", obj.MaxObjects);
        if (obj.MaxObjects < 1)
        {
            obj.MaxObjects = 1;
        }

        //Height
        obj.ConstrainHeight = EditorGUILayout.Toggle("Constrain Height", obj.ConstrainHeight);
        if (obj.ConstrainHeight)
        {
            EditorGUI.indentLevel = 1;

            obj.HeightConstraint = EditorGUIExtension.DrawConstraintRange("Height", obj.HeightConstraint, 0, 1);

            EditorGUILayout.BeginHorizontal();
            obj.HeightProbCurve = EditorGUILayout.CurveField("Probability", obj.HeightProbCurve, Color.green, new Rect(0, 0, 1, 1));
            if (GUILayout.Button("?", GUILayout.Width(25)))
            {
                const string msg = "This is the height probability curve. The X axis represents the " +
                                   "min to max height and the Y axis represents the probability an " +
                                   "object will spawn. By default, the curve is set to a 100% probability " +
                                   "meaning all objects will spawn.";
                EditorUtility.DisplayDialog("Help - Height Probability", msg, "Close");
            }
            EditorGUILayout.EndHorizontal();

            EditorGUI.indentLevel = 0;
        }

        //Angle
        obj.ConstrainAngle = EditorGUILayout.Toggle("Constrain Angle", obj.ConstrainAngle);
        if (obj.ConstrainAngle)
        {
            EditorGUI.indentLevel = 1;

            obj.AngleConstraint = EditorGUIExtension.DrawConstraintRange("Angle", obj.AngleConstraint, 0, 90);

            EditorGUILayout.BeginHorizontal();
            obj.AngleProbCurve = EditorGUILayout.CurveField("Probability", obj.AngleProbCurve, Color.green, new Rect(0, 0, 90, 1));
            if (GUILayout.Button("?", GUILayout.Width(25)))
            {
                const string msg = "This is the angle probability curve. The X axis represents " +
                                   "0 to 90 degrees and the Y axis represents the probability an " +
                                   "object will spawn. By default, the curve is set to a 100% probability " +
                                   "meaning all objects will spawn.";
                EditorUtility.DisplayDialog("Help - Angle Probability", msg, "Close");
            }
            EditorGUILayout.EndHorizontal();

            EditorGUI.indentLevel = 0;
        }

        //Translate
        EditorGUI.indentLevel    = 1;
        obj.ShowTranslateFoldout = EditorGUILayout.Foldout(obj.ShowTranslateFoldout, "Translate");
        if (obj.ShowTranslateFoldout)
        {
            obj.TranslationAmount = EditorGUILayout.Vector3Field("Translate", obj.TranslationAmount);

            EditorGUILayout.BeginHorizontal();
            obj.IsRandomTranslate = EditorGUILayout.Toggle("Random", obj.IsRandomTranslate);
            if (GUILayout.Button("?", GUILayout.Width(25)))
            {
                const string msg = "Optionally randomly translate the placed object. " +
                                   "Max and min extents for the random number generator can " +
                                   "be set.";
                EditorUtility.DisplayDialog("Help - Random Translate", msg, "Close");
            }
            EditorGUILayout.EndHorizontal();

            if (obj.IsRandomTranslate)
            {
                EditorGUI.indentLevel = 2;

                obj.RandomTranslateExtents.Min = EditorGUILayout.Vector3Field("Min", obj.RandomTranslateExtents.Min);
                obj.RandomTranslateExtents.Max = EditorGUILayout.Vector3Field("Max", obj.RandomTranslateExtents.Max);

                FitMinMax(ref obj.RandomTranslateExtents.Min, ref obj.RandomTranslateExtents.Max);
                EditorGUI.indentLevel = 1;
            }
        }

        //Rotate
        obj.ShowRotateFoldout = EditorGUILayout.Foldout(obj.ShowRotateFoldout, "Rotate");
        if (obj.ShowRotateFoldout)
        {
            obj.RotationAmount = EditorGUILayout.Vector3Field("Rotation", obj.RotationAmount);

            EditorGUILayout.BeginHorizontal();
            obj.IsRandomRotation = EditorGUILayout.Toggle("Random", obj.IsRandomRotation);
            if (GUILayout.Button("?", GUILayout.Width(25)))
            {
                const string msg = "Optionally randomly rotate the placed object. " +
                                   "Max and min extents for the random number generator can " +
                                   "be set.";
                EditorUtility.DisplayDialog("Help - Random Rotate", msg, "Close");
            }
            EditorGUILayout.EndHorizontal();

            if (obj.IsRandomRotation)
            {
                EditorGUI.indentLevel = 2;

                obj.RandomRotationExtents.Min = EditorGUILayout.Vector3Field("Min", obj.RandomRotationExtents.Min);
                obj.RandomRotationExtents.Max = EditorGUILayout.Vector3Field("Max", obj.RandomRotationExtents.Max);

                FitMinMax(ref obj.RandomRotationExtents.Min, ref obj.RandomRotationExtents.Max);
                EditorGUI.indentLevel = 1;
            }
        }

        //Scale
        obj.ShowScaleFoldout = EditorGUILayout.Foldout(obj.ShowScaleFoldout, "Scale");
        if (obj.ShowScaleFoldout)
        {
            obj.ScaleAmount = EditorGUILayout.Vector3Field("Scale", obj.ScaleAmount);

            EditorGUILayout.BeginHorizontal();
            obj.IsRandomScale = EditorGUILayout.Toggle("Random", obj.IsRandomScale);
            if (GUILayout.Button("?", GUILayout.Width(25)))
            {
                const string msg = "Optionally randomly scale the placed object. " +
                                   "Max and min extents for the random number generator can " +
                                   "be set.";
                EditorUtility.DisplayDialog("Help - Random Scale", msg, "Close");
            }
            EditorGUILayout.EndHorizontal();

            if (obj.IsRandomScale)
            {
                obj.IsUniformScale = EditorGUILayout.Toggle("Scale Uniformly", obj.IsUniformScale);

                EditorGUI.indentLevel = 2;

                if (obj.IsUniformScale)
                {
                    obj.UniformScaleMin = EditorGUILayout.FloatField("Min", obj.UniformScaleMin);
                    obj.UniformScaleMax = EditorGUILayout.FloatField("Max", obj.UniformScaleMax);
                }
                else
                {
                    obj.RandomScaleExtents.Min = EditorGUILayout.Vector3Field("Min", obj.RandomScaleExtents.Min);
                    obj.RandomScaleExtents.Max = EditorGUILayout.Vector3Field("Max", obj.RandomScaleExtents.Max);

                    FitMinMax(ref obj.RandomScaleExtents.Min, ref obj.RandomScaleExtents.Max);
                }
                EditorGUI.indentLevel = 1;
            }
        }

        GUILayout.EndArea();

        EditorGUI.indentLevel = startIndent;
    }
Exemplo n.º 3
0
        public override void OnBodyGUI()
        {
            //Output / Mask Input
            NodeEditorGUILayout.PropertyField(serializedObject.FindProperty("Output"));
            NodeEditorGUILayout.PropertyField(serializedObject.FindProperty("Mask"));

            EditorGUI.BeginChangeCheck();

            if (Constraint.GetMaskValue() != null) {
                Constraint.Tolerance = EditorGUIExtension.MinMaxFloatField("Tolerance", Constraint.Tolerance, 0f, 1f);
            }

            //Height Constraint
            ConstraintNode cons = Constraint;
            cons.ConstrainHeight = EditorGUILayout.Toggle("Height", cons.ConstrainHeight);

            if (cons.ConstrainHeight) {
                EditorGUI.indentLevel = 1;

                cons.HeightConstraint = EditorGUIExtension.DrawConstraintRange("Height", cons.HeightConstraint, 0, 1);

                EditorGUILayout.BeginHorizontal();
                cons.HeightProbCurve = EditorGUILayout.CurveField("Probability", cons.HeightProbCurve, Color.green, new Rect(0, 0, 1, 1));
                if (GUILayout.Button("?", GUILayout.Width(25))) {
                    const string msg = "This is the height probability curve. The X axis represents the " +
                                        "min to max height and the Y axis represents the probability an " +
                                        "object will spawn. By default, the curve is set to a 100% probability " +
                                        "meaning all objects will spawn.";
                    EditorUtility.DisplayDialog("Help - Height Probability", msg, "Close");
                }
                EditorGUILayout.EndHorizontal();

                EditorGUI.indentLevel = 0;
            }

            //Angle Constraint
            cons.ConstrainAngle = EditorGUILayout.Toggle("Angle", cons.ConstrainAngle);

            if (cons.ConstrainAngle) {
                EditorGUI.indentLevel = 1;

                cons.AngleConstraint = EditorGUIExtension.DrawConstraintRange("Angle", cons.AngleConstraint, 0, 1, 90);

                EditorGUILayout.BeginHorizontal();
                cons.AngleProbCurve = EditorGUILayout.CurveField("Probability", cons.AngleProbCurve, Color.green, new Rect(0, 0, 1, 1));
                if (GUILayout.Button("?", GUILayout.Width(25))) {
                    const string msg = "This is the angle probability curve. The X axis represents " +
                                        "0 to 90 degrees and the Y axis represents the probability an " +
                                        "object will spawn. By default, the curve is set to a 100% probability " +
                                        "meaning all objects will spawn.";
                    EditorUtility.DisplayDialog("Help - Angle Probability", msg, "Close");
                }
                EditorGUILayout.EndHorizontal();

                EditorGUI.indentLevel = 0;
            }

            Constraint.PlacementProbability = EditorGUIExtension.MinMaxIntField("Place Prob.", Constraint.PlacementProbability, 0, 100);

            if (EditorGUI.EndChangeCheck()) {
                serializedObject.ApplyModifiedProperties();
            }
        }
    public override void DrawItem(Rect position, int index)
    {
        bool isRepaint = Event.current.type == EventType.Repaint;

        if (isRepaint)
        {
            _positions[index] = position;
        }

        //Resize area to fit within list gui
        var areaPos = _positions.ContainsKey(index) ? _positions[index] : new Rect();

        areaPos.x     += 6;
        areaPos.y     += 8;
        areaPos.width -= 6;

        //Cache biome instance
        var biome = this[index];

        if (biome == null)
        {
            return;
        }

        //Init sublists for biome if they don't exist yet
        if (GetMaterialList(biome) == null)
        {
            _materialList.Add(new KeyValuePair <BiomeData, ReorderableMaterialList>(biome, new ReorderableMaterialList(_config, biome.Details)));
        }
        if (GetObjectList(biome) == null)
        {
            _objectList.Add(new KeyValuePair <BiomeData, ReorderableObjectList>(biome, new ReorderableObjectList(_config, biome.Details)));
        }

        GUILayout.BeginArea(areaPos);

        string name = string.IsNullOrEmpty(biome.Name) ? "Biome " + (index + 1) : biome.Name;

        biome.Name = EditorGUILayout.TextField("Name", name, GUILayout.ExpandWidth(true));

        if (biome.Color == default(Color))
        {
            biome.Color = Random.ColorHSV();
        }
        biome.Color = EditorGUILayout.ColorField(new GUIContent("Preview Color"), biome.Color, false, false, false, new ColorPickerHDRConfig(0, 1, 0, 1));

        //Constraints
        EditorGUILayout.Space();
        EditorGUILayout.LabelField("Constraints", EditorGUIExtension.TerraStyle.TextBold);
        GUILayout.Space(-2);

        biome.MixMethod = (BiomeData.ConstraintMixMethod)EditorGUIExtension.EnumToolbar(biome.MixMethod);

        //height
        biome.IsHeightConstrained = EditorGUILayout.Toggle("Height", biome.IsHeightConstrained);
        if (biome.IsHeightConstrained)
        {
            EditorGUI.indentLevel++;
            biome.HeightConstraint = EditorGUIExtension.DrawConstraintRange("Min/Max", biome.HeightConstraint, 0f, 1f);
            EditorGUI.indentLevel--;
        }

        //temperature
        biome.IsTemperatureConstrained = EditorGUILayout.Toggle("Temperature", biome.IsTemperatureConstrained);
        if (biome.IsTemperatureConstrained)
        {
            EditorGUI.indentLevel++;
            biome.TemperatureConstraint = EditorGUIExtension.DrawConstraintRange("Min/Max", biome.TemperatureConstraint, 0f, 1f);
            EditorGUI.indentLevel--;
        }

        //moisture
        biome.IsMoistureConstrained = EditorGUILayout.Toggle("Moisture", biome.IsMoistureConstrained);
        if (biome.IsMoistureConstrained)
        {
            EditorGUI.indentLevel++;
            biome.MoistureConstraint = EditorGUIExtension.DrawConstraintRange("Min/Max", biome.MoistureConstraint, 0f, 1f);
            EditorGUI.indentLevel--;
        }

        GUILayout.EndArea();
    }