/// Copy constructor.
 public e2dGrassTexture(e2dGrassTexture other)
 {
     texture        = other.texture;
     size           = other.size;
     sizeRandomness = other.sizeRandomness;
     waveAmplitude  = other.waveAmplitude;
 }
Пример #2
0
 /// Copy constructor.
 public e2dGrassTexture(e2dGrassTexture other)
 {
     texture = other.texture;
     size = other.size;
     sizeRandomness = other.sizeRandomness;
     waveAmplitude = other.waveAmplitude;
 }
Пример #3
0
    /// Tool for drawing grass using a brush.
    private void DrawGrassTool()
    {
        // brush
        GUILayout.Label(e2dStrings.LABEL_BRUSH, e2dStyles.Header);

        DrawBrush(true, false);

        bool rebuildMaterial = false;
        bool rebuildMesh     = false;


        // global parameters
        GUILayout.Label(e2dStrings.LABEL_GLOBAL_PARAMETERS, e2dStyles.Header);
        GUI.changed = false;
        Terrain.GrassScatterRatio = EditorGUILayout.Slider(e2dStrings.LABEL_GRASS_SCATTER_RATIO, Terrain.GrassScatterRatio, e2dConstants.GRASS_SCATTER_RATIO_MIN, e2dConstants.GRASS_SCATTER_RATIO_MAX);
        Terrain.GrassWaveSpeed    = EditorGUILayout.Slider(e2dStrings.LABEL_GRASS_WAVE_SPEED, Terrain.GrassWaveSpeed, e2dConstants.GRASS_WAVE_SPEED_MIN, e2dConstants.GRASS_WAVE_SPEED_MAX);
        if (GUI.changed)
        {
            rebuildMesh = rebuildMaterial = true;
        }


        // texture settings
        GUILayout.Label(e2dStrings.LABEL_TEXTURE_SETTINGS, e2dStyles.Header);

        DrawGrassTextureSelector();
        e2dGrassTexture selectedTexture = new e2dGrassTexture(Terrain.GrassTextures[SelectedTexture]);

        // texture
        EditorGUILayout.BeginHorizontal(e2dStyles.TextureField);
        GUI.changed = false;
        EditorGUILayout.PrefixLabel(e2dStrings.LABEL_TEXTURE);
        selectedTexture.texture = (Texture)EditorGUILayout.ObjectField(selectedTexture.texture, typeof(Texture), !EditorUtility.IsPersistent(target));
        GUILayoutUtility.GetRect(70, 0, GUI.skin.label);
        if (GUI.changed)
        {
            rebuildMaterial = true;
        }
        EditorGUILayout.EndHorizontal();

        // params
        GUI.changed = false;
        selectedTexture.waveAmplitude    = EditorGUILayout.Slider(e2dStrings.LABEL_GRASS_WAVE_AMPLITUDE, selectedTexture.waveAmplitude, e2dConstants.GRASS_WAVE_AMPLITUDE_MIN, e2dConstants.GRASS_WAVE_AMPLITUDE_MAX);
        selectedTexture.sizeRandomness.x = EditorGUILayout.Slider(e2dStrings.LABEL_GRASS_WIDTH_RANDOMNESS, selectedTexture.sizeRandomness.x, e2dConstants.GRASS_SIZE_RANDOMNESS_MIN, e2dConstants.GRASS_SIZE_RANDOMNESS_MAX);
        selectedTexture.sizeRandomness.y = EditorGUILayout.Slider(e2dStrings.LABEL_GRASS_HEIGHT_RANDOMNESS, selectedTexture.sizeRandomness.y, e2dConstants.GRASS_SIZE_RANDOMNESS_MIN, e2dConstants.GRASS_SIZE_RANDOMNESS_MAX);
        selectedTexture.size             = e2dEditorUtils.Vector2Field(e2dStrings.LABEL_GRASS_SIZE, selectedTexture.size);
        selectedTexture.size.x           = Mathf.Max(0, selectedTexture.size.x);
        selectedTexture.size.y           = Mathf.Max(0, selectedTexture.size.y);
        if (GUI.changed)
        {
            rebuildMesh = true;
        }

        // update the structure
        if (rebuildMaterial || rebuildMesh)
        {
            Undo.RegisterUndo(Terrain, e2dStrings.UNDO_GRASS_TEXTURE);
            Terrain.GrassTextures[SelectedTexture] = selectedTexture;
        }

        if (rebuildMaterial)
        {
            Terrain.GrassMesh.RebuildMaterial();
            EditorUtility.SetDirty(Terrain);
        }
        if (rebuildMesh)
        {
            Terrain.GrassMesh.RebuildMesh();
            EditorUtility.SetDirty(Terrain);
        }
    }
Пример #4
0
    /// Tool for drawing grass using a brush.
    private void DrawGrassTool()
    {
        // brush
        GUILayout.Label(e2dStrings.LABEL_BRUSH, e2dStyles.Header);

        DrawBrush(true, false);

        bool rebuildMaterial = false;
        bool rebuildMesh = false;

        // global parameters
        GUILayout.Label(e2dStrings.LABEL_GLOBAL_PARAMETERS, e2dStyles.Header);
        GUI.changed = false;
        Terrain.GrassScatterRatio = EditorGUILayout.Slider(e2dStrings.LABEL_GRASS_SCATTER_RATIO, Terrain.GrassScatterRatio, e2dConstants.GRASS_SCATTER_RATIO_MIN, e2dConstants.GRASS_SCATTER_RATIO_MAX);
        Terrain.GrassWaveSpeed = EditorGUILayout.Slider(e2dStrings.LABEL_GRASS_WAVE_SPEED, Terrain.GrassWaveSpeed, e2dConstants.GRASS_WAVE_SPEED_MIN, e2dConstants.GRASS_WAVE_SPEED_MAX);
        if (GUI.changed) rebuildMesh = rebuildMaterial = true;

        // texture settings
        GUILayout.Label(e2dStrings.LABEL_TEXTURE_SETTINGS, e2dStyles.Header);

        DrawGrassTextureSelector();
        e2dGrassTexture selectedTexture = new e2dGrassTexture(Terrain.GrassTextures[SelectedTexture]);

        // texture
        EditorGUILayout.BeginHorizontal(e2dStyles.TextureField);
        GUI.changed = false;
        EditorGUILayout.PrefixLabel(e2dStrings.LABEL_TEXTURE);
        selectedTexture.texture = (Texture)EditorGUILayout.ObjectField(selectedTexture.texture, typeof(Texture), !EditorUtility.IsPersistent(target));
        GUILayoutUtility.GetRect(70, 0, GUI.skin.label);
        if (GUI.changed) rebuildMaterial = true;
        EditorGUILayout.EndHorizontal();

        // params
        GUI.changed = false;
        selectedTexture.waveAmplitude = EditorGUILayout.Slider(e2dStrings.LABEL_GRASS_WAVE_AMPLITUDE, selectedTexture.waveAmplitude, e2dConstants.GRASS_WAVE_AMPLITUDE_MIN, e2dConstants.GRASS_WAVE_AMPLITUDE_MAX);
        selectedTexture.sizeRandomness.x = EditorGUILayout.Slider(e2dStrings.LABEL_GRASS_WIDTH_RANDOMNESS, selectedTexture.sizeRandomness.x, e2dConstants.GRASS_SIZE_RANDOMNESS_MIN, e2dConstants.GRASS_SIZE_RANDOMNESS_MAX);
        selectedTexture.sizeRandomness.y = EditorGUILayout.Slider(e2dStrings.LABEL_GRASS_HEIGHT_RANDOMNESS, selectedTexture.sizeRandomness.y, e2dConstants.GRASS_SIZE_RANDOMNESS_MIN, e2dConstants.GRASS_SIZE_RANDOMNESS_MAX);
        selectedTexture.size = e2dEditorUtils.Vector2Field(e2dStrings.LABEL_GRASS_SIZE, selectedTexture.size);
        selectedTexture.size.x = Mathf.Max(0, selectedTexture.size.x);
        selectedTexture.size.y = Mathf.Max(0, selectedTexture.size.y);
        if (GUI.changed) rebuildMesh = true;

        // update the structure
        if (rebuildMaterial || rebuildMesh)
        {
            Undo.RegisterUndo(Terrain, e2dStrings.UNDO_GRASS_TEXTURE);
            Terrain.GrassTextures[SelectedTexture] = selectedTexture;
        }

        if (rebuildMaterial)
        {
            Terrain.GrassMesh.RebuildMaterial();
            EditorUtility.SetDirty(Terrain);
        }
        if (rebuildMesh)
        {
            Terrain.GrassMesh.RebuildMesh();
            EditorUtility.SetDirty(Terrain);
        }
    }
 /// Returns the default texture used when no other is defined by the user.
 public e2dGrassTexture GetDefaultGrassTexture()
 {
     e2dGrassTexture result = new e2dGrassTexture((Texture)Resources.Load("defaultCurveTexture", typeof(Texture)));
     return result;
 }
    /// Returns the default texture used when no other is defined by the user.
    public e2dGrassTexture GetDefaultGrassTexture()
    {
        e2dGrassTexture result = new e2dGrassTexture((Texture)Resources.Load("defaultCurveTexture", typeof(Texture)));

        return(result);
    }