private void OnGUI()
        {
            _noiseType = (NoiseType)EditorGUILayout.EnumPopup("NoiseType", _noiseType);

            if (_texOutputOptions == null)
            {
                _texOutputOptions = new NoiseTextureOutputOptions();
            }

            _texOutputOptions.OnGUI();

            if (!_noiseOptions.ContainsKey(_noiseType))
            {
                _noiseOptions.Add(_noiseType, NoiseEditorUtil.CreateNoiseOptionsByType(_noiseType));
            }

            _noiseOptions[_noiseType].OnGUI();


            if (GUILayout.Button("Generate"))
            {
                var      noiseOptions = _noiseOptions[_noiseType];
                INoise2D noise        = noiseOptions.CreateNoise(_texOutputOptions);
                _generatedTexture = _texOutputOptions.ExportNoiseTo(noise);
            }

            if (_generatedTexture != null)
            {
                var rect = EditorGUILayout.GetControlRect(GUILayout.Width(256), GUILayout.Height(256));
                GUI.DrawTexture(rect, _generatedTexture);
            }
        }
Ejemplo n.º 2
0
        private void OnGUI()
        {
            if (_octaves == null)
            {
                _octaves = new List <IBaseNoiseGenerateOptions>();
            }

            for (var i = 0; i < _octaves.Count; i++)
            {
                var oc = _octaves[i];
                EditorGUILayout.BeginVertical(EditorStyles.helpBox);
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("Octave " + i);
                GUILayout.FlexibleSpace();
                if (GUILayout.Button("-", EditorStyles.miniButtonRight))
                {
                    _octaves.RemoveAt(i);
                    break;
                }
                EditorGUILayout.EndHorizontal();
                var type = (NoiseType)EditorGUILayout.EnumPopup("BaseNoiseType", oc.type);
                if (type != oc.type)
                {
                    _octaves.RemoveAt(i);
                    oc = NoiseEditorUtil.CreateNoiseOptionsByType(type);
                    _octaves.Insert(i, oc);
                }
                oc.OnGUI();
                EditorGUILayout.EndVertical();
            }

            if (GUILayout.Button("Add Octave"))
            {
                _octaves.Add(new ValueNoiseOptions());
            }

            if (_texOutputOptions == null)
            {
                _texOutputOptions = new NoiseTextureOutputOptions();
            }

            _texOutputOptions.OnGUI();


            if (GUILayout.Button("Generate"))
            {
                List <INoise2D> octaves = new List <INoise2D>();
                foreach (var o in _octaves)
                {
                    octaves.Add(o.CreateNoise(_texOutputOptions));
                }
                var noise = new FractalNoise2D(octaves.ToArray());
                _generatedNoiseTexture = _texOutputOptions.ExportNoiseTo(noise);
            }

            if (_generatedNoiseTexture)
            {
                var rect = EditorGUILayout.GetControlRect(GUILayout.Width(256), GUILayout.Height(256));
                GUI.DrawTexture(rect, _generatedNoiseTexture);
            }
        }