Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[change] public SensorComponent fields to properties, add custom editor #3564

Merged
merged 4 commits into from
Mar 6, 2020

Conversation

chriselion
Copy link
Contributor

@chriselion chriselion commented Mar 4, 2020

Proposed change(s)

For both CameraSensorComponent and RenderTextureSensorComponent:

  • Move fields to private
  • Add properties for the fields (public get, usually internal set)
  • CustomEditors

Useful links (Github issues, JIRA tickets, ML-Agents forum threads etc.)

Types of change(s)

  • Bug fix
  • New feature
  • Code refactor
  • Breaking change
  • Documentation update
  • Other (please describe)

Checklist

  • Added tests that prove my fix is effective or that my feature works
  • Updated the changelog (if applicable)
  • Updated the documentation (if applicable)
  • Updated the migration guide (if applicable)

Other comments

@chriselion chriselion changed the title [change] public fields to properties, add custom editor [change] public SensorComponent fields to properties, add custom editor Mar 4, 2020
EditorGUI.BeginDisabledGroup(Application.isPlaying);
{
EditorGUILayout.PropertyField(so.FindProperty("m_SensorName"), true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would make more sense to store "m_SensorName" and such in private const in case they are used somewhere else.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, not quite sure what you mean. The user needs to assign a unique name to each sensor so that we can sort them deterministically, so the name here can't be const.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think he means the string, make it a variable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here or in the component? We currently only use them in one place, and it's kinda redundant because of reflection.

We could do something like this:
https://stackoverflow.com/a/33059272/224264
although to use nameof we'd need to make the fields internal.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we only use it here, I think it is fine.


EditorGUI.EndDisabledGroup();

if (EditorGUI.EndChangeCheck())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not think it is useful to check for changes is nothing happens when something changed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revised based on feedback from @awjuliani - the Camera and compression type can now be changed during runtime (since they don't affect the observation shape).

[HideInInspector]
[SerializeField]
[FormerlySerializedAs("m_TeamID")]
[HideInInspector, SerializeField, FormerlySerializedAs("m_TeamID")]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can do that ?!
Should we try to be consistent and make it the same way everywhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did a simple find-and-replace for the ones for HideInInspector+ SerializeField+ FormerlySerializedAs. That's as much effort as I want to put into it for this PR.

@chriselion chriselion merged commit 7764863 into master Mar 6, 2020
@delete-merged-branch delete-merged-branch bot deleted the develop-camera-render-custom-editors branch March 6, 2020 01:06
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 15, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants