public static void CreateNoise2DObject()
    {
        Noise2DObject noise_obj = ScriptableObject.CreateInstance <Noise2DObject>();

        noise_obj.ResetObject();

        string path = AssetDatabase.GetAssetPath(Selection.activeObject);

        if (path.Length == 0)
        {
            path = "Assets";
        }
        else if (System.IO.Path.GetExtension(path).Length > 0)
        {
            path = path.Replace("/" + System.IO.Path.GetFileName(path), "");
        }

        path = AssetDatabase.GenerateUniqueAssetPath(path + "/noise_obj.asset");
        AssetDatabase.CreateAsset(noise_obj, path);
        AssetDatabase.SaveAssets();

        EditorUtility.FocusProjectWindow();

        Selection.activeObject = noise_obj;
    }
    public override void OnInspectorGUI()
    {
        //bool indicating if preview image should be updated at end
        bool update_previews = false;

        //case target as obj variable
        _obj = (Noise2DObject)target;

        //create styling for elements
        InitializeStyle();

        //draws the layer preview images
        DrawImagePreviews();

        //panel with options for selecting and modifying layers
        update_previews |= DrawLayerControlPanel();

        //panel with options for the noise in the layer
        update_previews |= DrawLayerSettingsPanel();

        //panel with options to generate and save images created
        DrawImageGenerationPanel();

        //update preview image and object
        if (update_previews)
        {
            UpdatePreviewTextures();
            EditorUtility.SetDirty(_obj);
        }
    }
    private void OnEnable()
    {
        _obj = (Noise2DObject)target;

        //editor controls logic
        _scale_lock      = true;
        _lacunarity_lock = true;
        _layer_index     = 0;
        _preview_mode    = 0;
        _png_dim         = new Vector2Int(256, 256);

        //preview textures
        _preview_total = _obj.GenerateNoiseImage(256, 256);
        _preview_layer = _obj.GenerateNoiseImage(_layer_index, 256, 256);
    }
Example #4
0
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        Noise2DObject noise_obj = fieldInfo.GetValue(property.serializedObject.targetObject) as Noise2DObject;

        EditorGUI.BeginProperty(position, label, property);
        float y      = position.y + PADDING;
        float x      = position.x;
        float width  = position.width - PADDING;
        float height = position.height - (2 * PADDING);

        float img_size = IMAGE_SIZE;

        if (IMAGE_SIZE > (width - VERTICAL_SPACE) * 0.35f)
        {
            img_size = (width - VERTICAL_SPACE) * 0.35f;
        }
        float img_x = x + width - img_size;

        //right column
        Rect      right_rect  = new Rect(img_x, y, img_size, img_size);
        Texture2D preview_img = Texture2D.blackTexture;

        if (noise_obj != null)
        {
            preview_img = noise_obj.GenerateNoiseImage(128, 128);
        }
        EditorGUI.DrawPreviewTexture(right_rect, preview_img);

        //left column
        Rect left_rect = new Rect(x, y, width - img_size - VERTICAL_SPACE, LINE_HEIGHT);

        label.text = "Perlin Noise Object";
        EditorGUI.PrefixLabel(left_rect, GUIUtility.GetControlID(FocusType.Passive), label);
        left_rect.y += LINE_HEIGHT + HORIZONTAL_SPACE;
        EditorGUI.PropertyField(left_rect, property, GUIContent.none);
        left_rect.y += LINE_HEIGHT + HORIZONTAL_SPACE;

        float ll_width = 0.5f * left_rect.width;
        float lr_width = left_rect.width - ll_width;
        Rect  ll_rect  = new Rect(left_rect.x, left_rect.y, ll_width, left_rect.height);
        Rect  lr_rect  = new Rect(ll_rect.x + ll_width, ll_rect.y, lr_width, ll_rect.height);

        EditorGUI.LabelField(ll_rect, "View:");
        EditorGUI.Popup(lr_rect, 0, new string[] { "Total", "Layers" });

        if (noise_obj != null)
        {
            int[]    value_options   = new int[noise_obj.layers];
            string[] display_options = new string[noise_obj.layers];
            for (int k = 0; k < display_options.Length; k++)
            {
                display_options[k] = k.ToString();
                value_options[k]   = k;
            }

            ll_rect.y += LINE_HEIGHT + HORIZONTAL_SPACE;
            lr_rect.y += LINE_HEIGHT + HORIZONTAL_SPACE;
            EditorGUI.LabelField(ll_rect, "Layer:");
            _layer_select = Mathf.Clamp(EditorGUI.IntPopup(lr_rect, _layer_select, display_options, value_options), 0, noise_obj.layers - 1);
        }

        EditorGUI.EndProperty();
    }