Skip to content

Handle Grabbing SerializedProperty on the Same Level #5

Description

@psuong

A lot of projects use encapsulation and the current ProgressBar can be considered a "Fixed" progress bar as you define the max within the attribute. So, if we wanted something more dynamic the progress bar should be enhanced to find a serializedProperty within the object/struct so you can manipulate the progress bar's max value on EditorTime/RunTime.

For a progress bar, let's say we have a health struct/class

[System.Serializable]
public struct Health {
    public float current, max;
}

public class Unit : MonoBehaviour {
    public Health configs;
}

When sticking [ProgressBar] on current, we can't referenced the max field automatically, so the default value of the progress bar is current/100f. When parsing a property.propertyPath the Editor will output configs.current as the entire path.

We can recursively/iteratively build and generate a path of serializedProperty/serializedObject to grab the correct serializedProperty so that the ProgressBar can be dynamic instead.

[ProgressBar(maxProperty = "max")]

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions