Example #1
0
    void DrawRulesUI(FoilageRules r)
    {
        rulesUIFoldout = EditorUtils.Foldout("Properties", rulesUIFoldout, 15, 15);
        if (rulesUIFoldout)
        {
            GUILayout.Space(10);

            GUILayout.BeginHorizontal();
            GUILayout.Space(30);
            GUILayout.Label("Min Slope", GUILayout.MinWidth(100));
            r.minSlopeVal = EditorGUILayout.FloatField(r.minSlopeVal, GUILayout.MinWidth(50));
            GUILayout.Space(15);
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Space(30);
            GUILayout.Label("Max Slope", GUILayout.MinWidth(100));
            r.maxSlopeVal = EditorGUILayout.FloatField(r.maxSlopeVal, GUILayout.MinWidth(50));
            GUILayout.Space(15);
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Space(30);
            GUILayout.Label("Min Altitude", GUILayout.MinWidth(100));
            r.minAltitudeVal = EditorGUILayout.FloatField(r.minAltitudeVal, GUILayout.MinWidth(50));
            GUILayout.Space(15);
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Space(30);
            GUILayout.Label("Max Altitude", GUILayout.MinWidth(100));
            r.maxAltitudeVal = EditorGUILayout.FloatField(r.maxAltitudeVal, GUILayout.MinWidth(50));
            GUILayout.Space(15);
            GUILayout.EndHorizontal();

            GUILayout.Space(10);

            GUILayout.BeginHorizontal();
            GUILayout.Space(30);
            GUILayout.Label("Use Normal", GUILayout.MinWidth(150));
            r.useNormal = EditorGUILayout.Toggle(r.useNormal, GUILayout.MinWidth(50));
            GUILayout.Space(15);
            GUILayout.EndHorizontal();

            GUILayout.Space(10);
        }
    }
Example #2
0
    public void Randomize(GameObject obj, FoilageRules r)
    {
        // Position
        var tmpPosX = r.posOffset.x + UnityEngine.Random.Range(r.minPosOffset.x, r.maxPosOffset.x);
        var tmpPosY = r.posOffset.y + UnityEngine.Random.Range(r.minPosOffset.y, r.maxPosOffset.y);
        var tmpPosZ = r.posOffset.z + UnityEngine.Random.Range(r.minPosOffset.z, r.maxPosOffset.z);

        obj.transform.Translate(tmpPosX, tmpPosY, tmpPosZ);

        // Rotation
        var tmpRotX = r.rotOffset.x + UnityEngine.Random.Range(r.minRotOffset.x, r.maxRotOffset.x);
        var tmpRotY = r.rotOffset.y + UnityEngine.Random.Range(r.minRotOffset.y, r.maxRotOffset.y);
        var tmpRotZ = r.rotOffset.z + UnityEngine.Random.Range(r.minRotOffset.z, r.maxRotOffset.z);

        obj.transform.Rotate(tmpRotX, tmpRotY, tmpRotZ);

        // Scale
        var scaleOffset = UnityEngine.Random.Range(r.minScaleOffset, r.maxScaleOffset);

        obj.transform.localScale += new Vector3(scaleOffset, scaleOffset, scaleOffset);
    }
Example #3
0
    void DrawScatterSettingsUI(FoilageRules r)
    {
        scatterUIFoldout = EditorUtils.Foldout("Scatter Settings", scatterUIFoldout, 15, 15);
        if (scatterUIFoldout)
        {
            GUILayout.Space(10);

            // position offsets
            EditorUtils.BoldLabel("Position Offset", 30, 15);
            r.posOffset    = EditorUtils.VectorField(r.posOffset, "Offset Pos    ", 30, 15);
            r.minPosOffset = EditorUtils.VectorField(r.minPosOffset, "Random Min", 30, 15);
            r.maxPosOffset = EditorUtils.VectorField(r.maxPosOffset, "Random Max", 30, 15);

            GUILayout.Space(10);

            // rotation offsets
            EditorUtils.BoldLabel("Rotation Offset", 30, 15);
            r.rotOffset    = EditorUtils.VectorField(r.rotOffset, "Offset Angle", 30, 15);
            r.minRotOffset = EditorUtils.VectorField(r.minRotOffset, "Random Min", 30, 15);
            r.maxRotOffset = EditorUtils.VectorField(r.maxRotOffset, "Random Max", 30, 15);

            GUILayout.Space(10);

            // scale offsets
            EditorUtils.BoldLabel("Scale Offset", 30, 15);

            GUILayout.BeginHorizontal();
            EditorUtils.Label("Random Min ", 30, 0);
            r.minScaleOffset = EditorUtils.Float(ref r.minScaleOffset, "", 30, 15, minWidth: 50);
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            EditorUtils.Label("Random Max", 30, 0);
            r.maxScaleOffset = EditorUtils.Float(ref r.maxScaleOffset, "", 30, 15, minWidth: 50);
            GUILayout.EndHorizontal();

            GUILayout.Space(10);
        }
    }
Example #4
0
    public void UpdateUI()
    {
        mainfoldOut = EditorUtils.Foldout("Foilage Groups", mainfoldOut, 5, 15);

        if (mainfoldOut)
        {
            for (int j = 0; j < groups.groupObjects.Count; j++)
            {
                GUILayout.BeginHorizontal();
                GUILayout.Space(18);

                EditorUtils.Label(j.ToString(), 0, 0);

                groups.groupObjects[j] = (GameObject)EditorGUILayout.ObjectField(groups.groupObjects[j], typeof(GameObject), true);

                // if the user drags an object from the scene and if it;s not a GrassPatch
                if (groups.groupObjects[j] != null && !groups.groupObjects[j].GetComponent <GrassPatch>())
                {
                    groups.groupObjects[j] = null;
                }
                else
                {
                    groups.AddEntry(j);
                }

                if (EditorUtils.Button("Remove", 0, 0))
                {
                    groups.Remove(j); groups.selectedIndex = -1; return;
                }
                if (EditorUtils.Button("Select", 0, 0))
                {
                    groups.Select(j);
                }

                GUILayout.Space(15);
                GUILayout.EndHorizontal();
            }

            GUILayout.Space(5f);
            FoilageRules r = null;

            if (groups.selectedIndex != -1 && groups.foilageRules.ContainsKey(groups.selectedIndex))
            {
                r = groups.foilageRules[groups.selectedIndex];
            }

            if (r != null)
            {
                DrawScatterSettingsUI(r);
                DrawRulesUI(r);
            }

            GUILayout.Space(5f);
            GUILayout.BeginHorizontal();

            if (EditorUtils.Button("Add Foilage group", 20, 0))
            {
                groups.Add();
            }

            if (EditorUtils.Button("Clear", 0, 15))
            {
            }

            GUILayout.EndHorizontal();

            GUILayout.Space(5f);
        }
    }