比较提交
合并到: unity-tech-cn:main
unity-tech-cn:/main
unity-tech-cn:/readback_mode
unity-tech-cn:/fix-editor-pause
unity-tech-cn:/docs
unity-tech-cn:/format
unity-tech-cn:/dr-test1
unity-tech-cn:/fix-compile
unity-tech-cn:/fix-links
unity-tech-cn:/fix_startup_exception
unity-tech-cn:/fix-docs
unity-tech-cn:/fix_label_id_report
unity-tech-cn:/update-setup-steps
unity-tech-cn:/labeler_mock
unity-tech-cn:/publish-fix
unity-tech-cn:/result_visualization
unity-tech-cn:/labeler_mock_mb
unity-tech-cn:/labeler_mock_on_camera
unity-tech-cn:/0.1.0-staging
unity-tech-cn:/dr-test2
unity-tech-cn:/release_cleanup
unity-tech-cn:/RC_0.2.0-preview.1
unity-tech-cn:/aisv614_0.2.0
unity-tech-cn:/aisv614_fix
unity-tech-cn:/aisv647_visualizations
unity-tech-cn:/RC-0.2.0-preview.1
unity-tech-cn:/fix_seg_colors
unity-tech-cn:/test
unity-tech-cn:/0.3.0-staging
unity-tech-cn:/aisv565_bbox3d
unity-tech-cn:/aisv749_viz_mem_leak_bug
unity-tech-cn:/aisv754_seg_alpha_bug
unity-tech-cn:/test_request_tracking_completion
unity-tech-cn:/test_new_versions
unity-tech-cn:/usim-randomization
unity-tech-cn:/with_cloud_tests
unity-tech-cn:/0.2.0-staging
unity-tech-cn:/parameter-bahaviours
unity-tech-cn:/upgrade_deps
unity-tech-cn:/0.4.0-staging
unity-tech-cn:/0.5.0-staging-2020.1
unity-tech-cn:/0.5.0-staging
unity-tech-cn:/resint_updates
unity-tech-cn:/tutorial-spelling-fix
unity-tech-cn:/priyesh-urp-dist-render
unity-tech-cn:/multiple-perception-cameras
unity-tech-cn:/pre_release_tests_nov2020
unity-tech-cn:/0.6.0-staging
unity-tech-cn:/fix_performance_tests
unity-tech-cn:/manual_capture
unity-tech-cn:/fod_generator_randomization_changes
unity-tech-cn:/multipleCameras
unity-tech-cn:/Labelbug1101
unity-tech-cn:/replace_index_md
unity-tech-cn:/depth_occlusion
unity-tech-cn:/0.8.0-preview.1_staging
unity-tech-cn:/validation-tool
unity-tech-cn:/addressables-test
unity-tech-cn:/int_tests_on_hdrp
unity-tech-cn:/keypoint_self_occlusion
unity-tech-cn:/seg_opacity
unity-tech-cn:/foreground_object_bounds_normalization
unity-tech-cn:/generic-asset-sources
unity-tech-cn:/local-position-labeler
unity-tech-cn:/pyrception-integration
unity-tech-cn:/fix_sampler_rounding_issue
unity-tech-cn:/h-i
unity-tech-cn:/0.7.0-staging
unity-tech-cn:/Released-0.6.0-preview.1
unity-tech-cn:/moved-from-attribute
unity-tech-cn:/frontpage_shuffle
unity-tech-cn:/coco_export
unity-tech-cn:/public-spec
unity-tech-cn:/fix-3Dexception-typo
unity-tech-cn:/feat-light-randomizer
unity-tech-cn:/schema-0.1.0
unity-tech-cn:/data-cap-update
unity-tech-cn:/0.8.0.preview.4_staging
unity-tech-cn:/faq-page
unity-tech-cn:/orthographic-camera-metadata
unity-tech-cn:/update-docs-0.8.0.preview.4
unity-tech-cn:/priyesh-cloudrendering-test
unity-tech-cn:/Release_0.8.0-preview.4
unity-tech-cn:/tutorial_patch
unity-tech-cn:/add_imageLink_field
unity-tech-cn:/fix_label_config_editor_indexing
unity-tech-cn:/coco_perception_output_hybrid
unity-tech-cn:/fxaa-clarification
unity-tech-cn:/no_editor_coverage
unity-tech-cn:/keypoint_self_occlusion_2020_3
unity-tech-cn:/for_vulkan_mem_test
unity-tech-cn:/solo_support
unity-tech-cn:/fix_multi_cam
unity-tech-cn:/randomizer-serialization-update
unity-tech-cn:/semantic_shader_tests
unity-tech-cn:/revert-sample-scene
unity-tech-cn:/package-analytics
unity-tech-cn:/github-action
unity-tech-cn:/fix-one-extra-frame-before-scenario-starts
unity-tech-cn:/scene_gen
unity-tech-cn:/0.9.0.preview.1_staging
unity-tech-cn:/tag-RC-0.9.0.preview.2
unity-tech-cn:/remove-usim-from-docs
unity-tech-cn:/docs/fix-readme-image-names
unity-tech-cn:/fix-links/jonh
unity-tech-cn:/addressables-test/scheduledcapture
unity-tech-cn:/orthographic-camera-metadata/additions
unity-tech-cn:/github-action/test
拉取从: unity-tech-cn:parameter-bahaviours
unity-tech-cn:/main
unity-tech-cn:/readback_mode
unity-tech-cn:/fix-editor-pause
unity-tech-cn:/docs
unity-tech-cn:/format
unity-tech-cn:/dr-test1
unity-tech-cn:/fix-compile
unity-tech-cn:/fix-links
unity-tech-cn:/fix_startup_exception
unity-tech-cn:/fix-docs
unity-tech-cn:/fix_label_id_report
unity-tech-cn:/update-setup-steps
unity-tech-cn:/labeler_mock
unity-tech-cn:/publish-fix
unity-tech-cn:/result_visualization
unity-tech-cn:/labeler_mock_mb
unity-tech-cn:/labeler_mock_on_camera
unity-tech-cn:/0.1.0-staging
unity-tech-cn:/dr-test2
unity-tech-cn:/release_cleanup
unity-tech-cn:/RC_0.2.0-preview.1
unity-tech-cn:/aisv614_0.2.0
unity-tech-cn:/aisv614_fix
unity-tech-cn:/aisv647_visualizations
unity-tech-cn:/RC-0.2.0-preview.1
unity-tech-cn:/fix_seg_colors
unity-tech-cn:/test
unity-tech-cn:/0.3.0-staging
unity-tech-cn:/aisv565_bbox3d
unity-tech-cn:/aisv749_viz_mem_leak_bug
unity-tech-cn:/aisv754_seg_alpha_bug
unity-tech-cn:/test_request_tracking_completion
unity-tech-cn:/test_new_versions
unity-tech-cn:/usim-randomization
unity-tech-cn:/with_cloud_tests
unity-tech-cn:/0.2.0-staging
unity-tech-cn:/parameter-bahaviours
unity-tech-cn:/upgrade_deps
unity-tech-cn:/0.4.0-staging
unity-tech-cn:/0.5.0-staging-2020.1
unity-tech-cn:/0.5.0-staging
unity-tech-cn:/resint_updates
unity-tech-cn:/tutorial-spelling-fix
unity-tech-cn:/priyesh-urp-dist-render
unity-tech-cn:/multiple-perception-cameras
unity-tech-cn:/pre_release_tests_nov2020
unity-tech-cn:/0.6.0-staging
unity-tech-cn:/fix_performance_tests
unity-tech-cn:/manual_capture
unity-tech-cn:/fod_generator_randomization_changes
unity-tech-cn:/multipleCameras
unity-tech-cn:/Labelbug1101
unity-tech-cn:/replace_index_md
unity-tech-cn:/depth_occlusion
unity-tech-cn:/0.8.0-preview.1_staging
unity-tech-cn:/validation-tool
unity-tech-cn:/addressables-test
unity-tech-cn:/int_tests_on_hdrp
unity-tech-cn:/keypoint_self_occlusion
unity-tech-cn:/seg_opacity
unity-tech-cn:/foreground_object_bounds_normalization
unity-tech-cn:/generic-asset-sources
unity-tech-cn:/local-position-labeler
unity-tech-cn:/pyrception-integration
unity-tech-cn:/fix_sampler_rounding_issue
unity-tech-cn:/h-i
unity-tech-cn:/0.7.0-staging
unity-tech-cn:/Released-0.6.0-preview.1
unity-tech-cn:/moved-from-attribute
unity-tech-cn:/frontpage_shuffle
unity-tech-cn:/coco_export
unity-tech-cn:/public-spec
unity-tech-cn:/fix-3Dexception-typo
unity-tech-cn:/feat-light-randomizer
unity-tech-cn:/schema-0.1.0
unity-tech-cn:/data-cap-update
unity-tech-cn:/0.8.0.preview.4_staging
unity-tech-cn:/faq-page
unity-tech-cn:/orthographic-camera-metadata
unity-tech-cn:/update-docs-0.8.0.preview.4
unity-tech-cn:/priyesh-cloudrendering-test
unity-tech-cn:/Release_0.8.0-preview.4
unity-tech-cn:/tutorial_patch
unity-tech-cn:/add_imageLink_field
unity-tech-cn:/fix_label_config_editor_indexing
unity-tech-cn:/coco_perception_output_hybrid
unity-tech-cn:/fxaa-clarification
unity-tech-cn:/no_editor_coverage
unity-tech-cn:/keypoint_self_occlusion_2020_3
unity-tech-cn:/for_vulkan_mem_test
unity-tech-cn:/solo_support
unity-tech-cn:/fix_multi_cam
unity-tech-cn:/randomizer-serialization-update
unity-tech-cn:/semantic_shader_tests
unity-tech-cn:/revert-sample-scene
unity-tech-cn:/package-analytics
unity-tech-cn:/github-action
unity-tech-cn:/fix-one-extra-frame-before-scenario-starts
unity-tech-cn:/scene_gen
unity-tech-cn:/0.9.0.preview.1_staging
unity-tech-cn:/tag-RC-0.9.0.preview.2
unity-tech-cn:/remove-usim-from-docs
unity-tech-cn:/docs/fix-readme-image-names
unity-tech-cn:/fix-links/jonh
unity-tech-cn:/addressables-test/scheduledcapture
unity-tech-cn:/orthographic-camera-metadata/additions
unity-tech-cn:/github-action/test
此合并请求有变更与目标分支冲突。
/com.unity.perception/Runtime/Randomization/Samplers/SamplerTypes/ConstantSampler.cs
/com.unity.perception/Runtime/Randomization/Samplers/SamplerTypes/NormalSampler.cs
/com.unity.perception/Runtime/Randomization/Samplers/SamplerTypes/UniformSampler.cs
/com.unity.perception/Runtime/Randomization/Samplers/SamplerUtility.cs
/com.unity.perception/Runtime/Randomization/Parameters/NumericParameter.cs
/com.unity.perception/Runtime/Randomization/Parameters/Parameter.cs
/com.unity.perception/Runtime/Randomization/Parameters/CategoricalParameter.cs
/com.unity.perception/Runtime/Randomization/Scenarios/FixedLengthScenario.cs
/com.unity.perception/Runtime/Randomization/Scenarios/ScenarioBase.cs
/com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/BooleanParameter.cs
/com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/FloatParameter.cs
/com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/IntegerParameter.cs
/com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/Vector2Parameter.cs
/com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/Vector3Parameter.cs
/com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/Vector4Parameter.cs
/com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/ColorParameters/ColorHsvaParameter.cs.meta
/com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/ColorParameters/ColorHsva.cs.meta
/com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/ColorParameters/ColorHsvaCategoricalParameter.cs.meta
/com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/ColorParameters/ColorRgbCategoricalParameter.cs.meta
/com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/ColorParameters/ColorRgbParameter.cs.meta
/com.unity.perception/Editor/Randomization/Editors.meta
/com.unity.perception/Editor/Randomization/PropertyDrawers.meta
/com.unity.perception/Editor/Randomization/PropertyDrawers
/com.unity.perception/Editor/Randomization/VisualElements.meta
/com.unity.perception/Editor/Randomization/Editors
/com.unity.perception/Editor/Randomization/VisualElements
/com.unity.perception/Editor/Randomization/StaticData.cs
/com.unity.perception/Editor/Randomization/Uxml/CategoricalOptionElement.uxml
/com.unity.perception/Editor/Randomization/Uxml/ParameterElement.uxml
/com.unity.perception/Editor/Randomization/Uxml/SamplerElement.uxml
/com.unity.perception/Tests/Runtime/Randomization/ScenarioTests.cs
/com.unity.perception/Tests/Runtime/Randomization/ParameterConfigurationTests.cs
/com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/ColorParameters/ColorHsvaParameter.cs
/com.unity.perception/Runtime/Randomization/ParameterBehaviours/Configuration/ParameterTarget.cs
/com.unity.perception/Editor/Randomization/Uxml/ParameterAssetEditor.uxml.meta
/com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/ColorParameters/ColorHsvaParameter.cs
/com.unity.perception/Runtime/Randomization/ParameterBehaviours/Configuration/ParameterTarget.cs.meta
/com.unity.perception/Runtime/Randomization/ParameterBehaviours/Configuration/ParameterTarget.cs
/com.unity.perception/Editor/Randomization/Uss/Styles.uss
/com.unity.perception/Runtime/Randomization/ParameterBehaviours/Configuration/ParameterList.cs.meta
/com.unity.perception/Runtime/Randomization/ParameterBehaviours/Configuration/ParameterListException.cs.meta
10 次代码提交
作者 | SHA1 | 备注 | 提交日期 |
---|---|---|---|
Steven Leal | b7091e4e | experimenting with ECS workflow | 4 年前 |
Steven Leal | 7d0ec48a | working on new workflow | 4 年前 |
Steven Leal | d6860f5a | moved reset | 4 年前 |
Steven Leal | 7161dc3e | properly shutdown manager instance | 4 年前 |
Steven Leal | f8b317a9 | added random parameters scriptable object | 4 年前 |
Steven Leal | f1666ab3 | Added xml documentation | 4 年前 |
Steven Leal | 228032f4 | renamed ParameterConfiguration to ParameterList | 4 年前 |
Steven Leal | b9a6af2c | ParameterConfigurations now derive from ParameterBehaviour | 4 年前 |
Steven Leal | 0c713aff | implemented parameter behaviours | 4 年前 |
Steven Leal | 9baa72fc | changed samplers property from array to IEnumerable | 4 年前 |
共有 107 个文件被更改,包括 1656 次插入 和 1118 次删除
-
49com.unity.perception/Editor/Randomization/StaticData.cs
-
2com.unity.perception/Editor/Randomization/Uxml/CategoricalOptionElement.uxml
-
33com.unity.perception/Editor/Randomization/Uxml/ParameterElement.uxml
-
1com.unity.perception/Editor/Randomization/Uxml/SamplerElement.uxml
-
21com.unity.perception/Runtime/Randomization/Parameters/CategoricalParameter.cs
-
67com.unity.perception/Runtime/Randomization/Parameters/Parameter.cs
-
15com.unity.perception/Runtime/Randomization/Parameters/NumericParameter.cs
-
22com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/BooleanParameter.cs
-
8com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/FloatParameter.cs
-
8com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/IntegerParameter.cs
-
12com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/Vector2Parameter.cs
-
13com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/Vector3Parameter.cs
-
14com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/Vector4Parameter.cs
-
2com.unity.perception/Runtime/Randomization/Samplers/SamplerUtility.cs
-
16com.unity.perception/Runtime/Randomization/Samplers/SamplerTypes/ConstantSampler.cs
-
21com.unity.perception/Runtime/Randomization/Samplers/SamplerTypes/NormalSampler.cs
-
21com.unity.perception/Runtime/Randomization/Samplers/SamplerTypes/UniformSampler.cs
-
12com.unity.perception/Runtime/Randomization/Scenarios/ScenarioBase.cs.meta
-
4com.unity.perception/Runtime/Randomization/Scenarios/FixedLengthScenario.cs
-
158com.unity.perception/Runtime/Randomization/Scenarios/ScenarioBase.cs
-
20com.unity.perception/Tests/Runtime/Randomization/ScenarioTests.cs
-
30com.unity.perception/Tests/Runtime/Randomization/ParameterConfigurationTests.cs
-
83com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/ColorParameters/ColorHsvaParameter.cs
-
24com.unity.perception/Runtime/Randomization/ParameterBehaviours/Configuration/ParameterTarget.cs
-
3com.unity.perception/Editor/Randomization/Editors.meta
-
3com.unity.perception/Editor/Randomization/PropertyDrawers.meta
-
3com.unity.perception/Editor/Randomization/VisualElements.meta
-
3com.unity.perception/Editor/Randomization/Uss/ParameterStyles.uss.meta
-
17com.unity.perception/Editor/Randomization/Uss/SamplerStyles.uss
-
3com.unity.perception/Editor/Randomization/Uss/SamplerStyles.uss.meta
-
46com.unity.perception/Editor/Randomization/Uss/ParameterAssetStyles.uss
-
110com.unity.perception/Editor/Randomization/Uss/ParameterStyles.uss
-
10com.unity.perception/Editor/Randomization/Uxml/ParameterDrawer.uxml
-
3com.unity.perception/Editor/Randomization/Uxml/ParameterDrawer.uxml.meta
-
3com.unity.perception/Editor/Randomization/Uxml/ParameterListItemElement.uxml.meta
-
21com.unity.perception/Editor/Randomization/Uxml/ParameterAssetEditor.uxml
-
20com.unity.perception/Editor/Randomization/Uxml/ParameterListItemElement.uxml
-
3com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/ColorParameters.meta
-
3com.unity.perception/Runtime/Randomization/ParameterBehaviours.meta
-
3com.unity.perception/Editor/Randomization/PropertyDrawers/ColorHsvaDrawer.cs.meta
-
3com.unity.perception/Editor/Randomization/PropertyDrawers/ParameterDrawer.cs.meta
-
25com.unity.perception/Editor/Randomization/PropertyDrawers/ColorHsvaDrawer.cs
-
26com.unity.perception/Editor/Randomization/PropertyDrawers/ParameterDrawer.cs
-
73com.unity.perception/Editor/Randomization/Editors/ParametersAssetEditor.cs
-
3com.unity.perception/Editor/Randomization/Editors/ParametersAssetEditor.cs.meta
-
39com.unity.perception/Editor/Randomization/VisualElements/ColorHsvaField.cs
-
3com.unity.perception/Editor/Randomization/VisualElements/ColorHsvaField.cs.meta
-
47com.unity.perception/Editor/Randomization/VisualElements/DrawerParameterElement.cs
-
3com.unity.perception/Editor/Randomization/VisualElements/DrawerParameterElement.cs.meta
-
193com.unity.perception/Editor/Randomization/VisualElements/ParameterElement.cs
-
3com.unity.perception/Editor/Randomization/VisualElements/ParameterListItemElement.cs.meta
-
67com.unity.perception/Editor/Randomization/VisualElements/ParameterListItemElement.cs
-
107com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/ColorParameters/ColorHsva.cs
-
3com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/ColorParameters/ColorHsva.cs.meta
-
10com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/ColorParameters/ColorHsvaCategoricalParameter.cs
-
10com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/ColorParameters/ColorRgbCategoricalParameter.cs
-
3com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/ColorParameters/ColorHsvaCategoricalParameter.cs.meta
-
3com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/ColorParameters/ColorRgbCategoricalParameter.cs.meta
-
3com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/ColorParameters/ColorRgbParameter.cs.meta
-
111com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/ColorParameters/ColorRgbParameter.cs
-
3com.unity.perception/Runtime/Randomization/ParameterBehaviours/ParameterBehaviour.cs.meta
-
3com.unity.perception/Runtime/Randomization/ParameterBehaviours/Configuration.meta
-
3com.unity.perception/Runtime/Randomization/ParameterBehaviours/ParameterAsset.cs.meta
-
11com.unity.perception/Runtime/Randomization/ParameterBehaviours/Configuration/ParameterListException.cs
-
28com.unity.perception/Runtime/Randomization/ParameterBehaviours/Configuration/ParameterListItem.cs
-
3com.unity.perception/Runtime/Randomization/ParameterBehaviours/Configuration/ParameterListItem.cs.meta
-
118com.unity.perception/Runtime/Randomization/ParameterBehaviours/Configuration/ParameterList.cs
-
41com.unity.perception/Runtime/Randomization/ParameterBehaviours/ParameterAsset.cs
-
44com.unity.perception/Runtime/Randomization/ParameterBehaviours/ParameterBehaviour.cs
-
213com.unity.perception/Editor/Randomization/Uss/Styles.uss
-
21com.unity.perception/Editor/Randomization/Uxml/ParameterConfiguration.uxml
-
6com.unity.perception/Editor/Randomization/Uxml/ParameterDrawerElement.uxml
-
3com.unity.perception/Editor/Randomization/Uxml/ParameterDrawerElement.uxml.meta
-
125com.unity.perception/Editor/Randomization/ParameterConfigurationEditor.cs
-
11com.unity.perception/Editor/Randomization/ParameterConfigurationEditor.cs.meta
-
12com.unity.perception/Editor/Randomization/ParameterDragBar.cs
-
3com.unity.perception/Editor/Randomization/ParameterDragBar.cs.meta
-
101com.unity.perception/Editor/Randomization/ParameterDragManipulator.cs
-
3com.unity.perception/Editor/Randomization/ParameterDragManipulator.cs.meta
-
374com.unity.perception/Editor/Randomization/ParameterElement.cs
-
3com.unity.perception/Runtime/Randomization/Configuration.meta
-
0/com.unity.perception/Editor/Randomization/Uss/ParameterAssetStyles.uss.meta
-
0/com.unity.perception/Editor/Randomization/Uxml/ParameterAssetEditor.uxml.meta
-
0/com.unity.perception/Editor/Randomization/VisualElements/CategoricalOptionElement.cs
-
0/com.unity.perception/Editor/Randomization/VisualElements/CategoricalOptionElement.cs.meta
-
0/com.unity.perception/Editor/Randomization/VisualElements/FloatRangeElement.cs
-
0/com.unity.perception/Editor/Randomization/VisualElements/FloatRangeElement.cs.meta
-
0/com.unity.perception/Editor/Randomization/VisualElements/ParameterElement.cs.meta
-
0/com.unity.perception/Editor/Randomization/VisualElements/RandomSeedField.cs
-
0/com.unity.perception/Editor/Randomization/VisualElements/RandomSeedField.cs.meta
-
0/com.unity.perception/Editor/Randomization/VisualElements/SamplerElement.cs
-
0/com.unity.perception/Editor/Randomization/VisualElements/SamplerElement.cs.meta
-
0/com.unity.perception/Editor/Randomization/Editors/ScenarioBaseEditor.cs
|
|||
<UXML xmlns="UnityEngine.UIElements" xmlns:editor="UnityEditor.UIElements"> |
|||
<Box name="parameter-container" class="parameter-container"> |
|||
<VisualElement name="drag-handle" class="move-buttons-container"> |
|||
<VisualElement class="drag-handle"/> |
|||
</VisualElement> |
|||
<VisualElement style="flex-grow: 1; justify-content: center; margin-right: 6px;"> |
|||
<VisualElement class="parameter-type-label-container"> |
|||
<Box class="parameter-type-label-box"> |
|||
<VisualElement name="collapse" class="collapse-parameter-toggle foldout-open"/> |
|||
<Label name="parameter-type-label" text="Type:" class="parameter-type-label"/> |
|||
<TextField name="name" text="Parameter Name"/> |
|||
</Box> |
|||
<Button name="remove-parameter" class="remove-parameter-button"/> |
|||
</VisualElement> |
|||
|
|||
<VisualElement name="properties" class="parameter-properties-container" style="margin-bottom: 2px;"> |
|||
<Box> |
|||
<editor:ObjectField label="Target GameObject" name="target"/> |
|||
<VisualElement name="target-container"> |
|||
<VisualElement class="unity-base-field"> |
|||
<Label text="Target Property" class="unity-base-field__label"/> |
|||
<editor:ToolbarMenu text="Select A Property" name="property-select-menu" class="property-select-menu"/> |
|||
</VisualElement> |
|||
<editor:EnumField label="Application Frequency" name="application-frequency"/> |
|||
</VisualElement> |
|||
</Box> |
|||
<Box name="extra-properties" style="padding-left: 4px; border-top-width: 0px;"/> |
|||
</VisualElement> |
|||
</VisualElement> |
|||
</Box> |
|||
<VisualElement> |
|||
<Style src="../Uss/ParameterStyles.uss"/> |
|||
<VisualElement name="properties"/> |
|||
</VisualElement> |
|||
</UXML> |
|
|||
fileFormatVersion: 2 |
|||
fileFormatVersion: 2 |
|||
timeCreated: 1589772146 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 0b17046409af4c22bf74eec2a5965984 |
|||
timeCreated: 1598135707 |
|
|||
fileFormatVersion: 2 |
|||
guid: d3107e026b2943c1868c9b3f8c6480d3 |
|||
timeCreated: 1598135730 |
|
|||
fileFormatVersion: 2 |
|||
guid: 7f8f95a1bb144a96b9310164f5560387 |
|||
timeCreated: 1598135666 |
|
|||
fileFormatVersion: 2 |
|||
guid: def81fa16f8b41aca393a30c3b1fac72 |
|||
timeCreated: 1598222679 |
|
|||
.sampler-type-menu { |
|||
flex-grow: 1.5; |
|||
border-radius: 3px; |
|||
border-width: 1px; |
|||
margin-top: 2px; |
|||
margin-right: 3px; |
|||
} |
|||
|
|||
.sampler-name { |
|||
/*color: lightgreen;*/ |
|||
-unity-font-style: bold; |
|||
} |
|||
|
|||
.float-range .unity-base-field__label { |
|||
min-width: auto; |
|||
margin-right: 4px; |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 85ff041b142f41798a7703bda9bb1ba7 |
|||
timeCreated: 1598222791 |
|
|||
.dark-viewport { |
|||
border-radius: 5px; |
|||
background-color: #191919; |
|||
padding: 2px; |
|||
} |
|||
|
|||
.unity-toggle { |
|||
margin-left: 0; |
|||
} |
|||
|
|||
.remove-parameter-button { |
|||
background-image: resource("Packages/com.unity.perception/Editor/Randomization/Icons/X.png"); |
|||
width: 16px; |
|||
height: 16px; |
|||
} |
|||
|
|||
.move-buttons-container { |
|||
width: auto; |
|||
margin-right: 6px; |
|||
border-color: black; |
|||
border-top-left-radius: 3px; |
|||
border-bottom-left-radius: 3px; |
|||
background-color: #2A2A2A; |
|||
padding: 3px 2px; |
|||
justify-content: center; |
|||
} |
|||
|
|||
.drag-handle { |
|||
width: 16px; |
|||
height: 70%; |
|||
min-height: 20px; |
|||
background-image: resource("Packages/com.unity.perception/Editor/Randomization/Icons/DragHandle.png"); |
|||
} |
|||
|
|||
.unity-imgui-container { |
|||
margin-left: 1px; |
|||
margin-right: 3px; |
|||
} |
|||
|
|||
.search-icon { |
|||
width: 16px; |
|||
height: 16px; |
|||
margin-top: 2px; |
|||
flex-shrink: 0; |
|||
background-image: resource("Packages/com.unity.perception/Editor/Randomization/Icons/Search.png"); |
|||
} |
|
|||
.parameter-container { |
|||
border-width: 2px; |
|||
border-radius: 5px; |
|||
flex-direction: row; |
|||
margin: 2px 1px; |
|||
} |
|||
|
|||
.parameter-type-label-container { |
|||
flex-direction: row; |
|||
justify-content: space-between; |
|||
align-items: center; |
|||
margin-bottom: 1px; |
|||
} |
|||
|
|||
.parameter-type-label-box { |
|||
flex-direction: row; |
|||
align-items: center; |
|||
justify-content: flex-start; |
|||
flex-grow: 0; |
|||
-unity-text-align: middle-center; |
|||
border-width: 0; |
|||
padding: 1px; |
|||
font-size: 13px; |
|||
-unity-font-style: bold; |
|||
} |
|||
|
|||
.parameter-type-label { |
|||
color: cornflowerblue; |
|||
-unity-text-align: middle-left; |
|||
margin-right: 4px; |
|||
} |
|||
|
|||
.parameter-type-label-box .unity-base-text-field__input { |
|||
padding-left: 6px; |
|||
padding-right: 6px; |
|||
} |
|||
|
|||
.collapse-parameter-toggle { |
|||
flex-shrink: 0; |
|||
margin-right: 3px; |
|||
margin-left: 3px; |
|||
width: 12px; |
|||
height: 12px; |
|||
background-image: resource("Packages/com.unity.perception/Editor/Randomization/Icons/FoldoutOpen.png"); |
|||
} |
|||
|
|||
.collapsed-parameter .collapse-parameter-toggle { |
|||
background-image: resource("Packages/com.unity.perception/Editor/Randomization/Icons/FoldoutClosed.png"); |
|||
} |
|||
|
|||
.collapsed-parameter .parameter-properties-container { |
|||
display: none; |
|||
} |
|||
|
|||
.collapsed-parameter .move-buttons-container { |
|||
flex-direction: row; |
|||
} |
|||
|
|||
.collapsed-parameter .move-button { |
|||
width: 16px; |
|||
} |
|||
|
|||
.categorical-option { |
|||
flex-direction: row; |
|||
background-color: #3F3F3F; |
|||
margin: 1px; |
|||
border-radius: 4px; |
|||
} |
|||
|
|||
.options-list-view { |
|||
background-color: #191919; |
|||
border-radius: 4px; |
|||
margin-right: 2px; |
|||
padding: 3px; |
|||
border-bottom-right-radius: 0; |
|||
} |
|||
|
|||
.option-property-field { |
|||
width: 0; |
|||
flex-grow: 1; |
|||
flex-shrink: 0; |
|||
} |
|||
|
|||
.uniform-probability .hide-when-uniform { |
|||
display: none; |
|||
} |
|||
|
|||
.add-option-button { |
|||
align-self: flex-end; |
|||
border-width: 0; |
|||
border-top-right-radius: 0; |
|||
border-top-left-radius: 0; |
|||
background-color: #191919; |
|||
margin-top: 0; |
|||
margin-right: 2px; |
|||
} |
|||
|
|||
.add-option-button:hover { |
|||
background-color: #2A2A2A; |
|||
} |
|||
|
|||
.add-option-button:active { |
|||
color: cornflowerblue; |
|||
} |
|||
|
|||
.remove-option-button { |
|||
width: 12px; |
|||
height: 14px; |
|||
background-image: resource("Packages/com.unity.perception/Editor/Randomization/Icons/X.png"); |
|||
} |
|
|||
<UXML xmlns="UnityEngine.UIElements" xmlns:editor="UnityEditor.UIElements"> |
|||
<VisualElement> |
|||
<Style src="../Uss/ParameterStyles.uss"/> |
|||
<VisualElement style="flex-direction: row; align-items: center;"> |
|||
<VisualElement name="collapse" class="collapse-parameter-toggle foldout-open"/> |
|||
<Label name="field-name" style="-unity-font-style: bold; font-size: 12px;"/> |
|||
</VisualElement> |
|||
<VisualElement name="drawer" class="parameter-properties-container" style="padding-left: 18px;"/> |
|||
</VisualElement> |
|||
</UXML> |
|
|||
fileFormatVersion: 2 |
|||
guid: 6a4bb3efae29429292ccdfa63e661872 |
|||
timeCreated: 1598240583 |
|
|||
fileFormatVersion: 2 |
|||
guid: bb5d8b14dfb1488388860c0437274b7c |
|||
timeCreated: 1598232124 |
|
|||
<UXML xmlns="UnityEngine.UIElements" xmlns:editor="UnityEditor.UIElements"> |
|||
<VisualElement style="height: 100%;"> |
|||
<Style src="../Uss/ParameterAssetStyles.uss"/> |
|||
|
|||
<VisualElement style="flex-direction: row; align-items: center; margin-bottom: 2px; margin-top: 2px;"> |
|||
<VisualElement class="search-icon" style="margin-left: 3px; margin-right: 2px;"/> |
|||
<TextField name="filter-parameters" style="flex-grow: 1; flex-shrink: 1;"/> |
|||
</VisualElement> |
|||
|
|||
<VisualElement class="dark-viewport" style="min-height: 100px;"> |
|||
<VisualElement name="parameters-container" style="flex-shrink: 0;"/> |
|||
</VisualElement> |
|||
|
|||
<VisualElement style="flex-direction: row; justify-content: center;"> |
|||
<VisualElement style="flex-grow: 1"/> |
|||
<Button name="collapse-all" text="Collapse All" style="font-size: 13px; padding: 4px;"/> |
|||
<Button name="expand-all" text="Expand All" style="font-size: 13px; padding: 4px;"/> |
|||
<VisualElement style="flex-grow: 1"/> |
|||
</VisualElement> |
|||
</VisualElement> |
|||
</UXML> |
|
|||
<UXML xmlns="UnityEngine.UIElements" xmlns:editor="UnityEditor.UIElements"> |
|||
<Box name="parameter-container" class="parameter-container"> |
|||
<Style src="../Uss/ParameterStyles.uss"/> |
|||
<VisualElement name="drag-handle" class="move-buttons-container"> |
|||
<VisualElement class="drag-handle"/> |
|||
</VisualElement> |
|||
<VisualElement style="flex-grow: 1; justify-content: center;"> |
|||
<VisualElement class="parameter-type-label-container"> |
|||
<Box class="parameter-type-label-box"> |
|||
<VisualElement name="collapse" class="collapse-parameter-toggle foldout-open"/> |
|||
<Label name="parameter-type-label" text="Type:" class="parameter-type-label"/> |
|||
<TextElement name="name" text="Field Name"/> |
|||
</Box> |
|||
</VisualElement> |
|||
|
|||
<VisualElement name="properties" class="parameter-properties-container"> |
|||
</VisualElement> |
|||
</VisualElement> |
|||
</Box> |
|||
</UXML> |
|
|||
fileFormatVersion: 2 |
|||
guid: ce91e289cdaa4ccc849a0c287aefd34d |
|||
timeCreated: 1598326361 |
|
|||
fileFormatVersion: 2 |
|||
guid: 2dd2a5a912ed49ab8356572e5ca6d950 |
|||
timeCreated: 1598132657 |
|
|||
fileFormatVersion: 2 |
|||
guid: 5e8094c28dd142a09fbbd38ca560164b |
|||
timeCreated: 1598250942 |
|
|||
fileFormatVersion: 2 |
|||
guid: d389620d3aa3471ca1877eb59cdfb465 |
|||
timeCreated: 1598135745 |
|
|||
using UnityEditor; |
|||
using UnityEngine.Perception.Randomization.Parameters; |
|||
using UnityEngine.UIElements; |
|||
|
|||
namespace UnityEngine.Perception.Randomization.Editor.PropertyDrawers |
|||
{ |
|||
[CustomPropertyDrawer(typeof(ColorHsva), true)] |
|||
class ColorHsvaDrawer : PropertyDrawer |
|||
{ |
|||
public override VisualElement CreatePropertyGUI(SerializedProperty property) |
|||
{ |
|||
return new ColorHsvaField(property); |
|||
} |
|||
|
|||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) |
|||
{ |
|||
EditorGUI.PropertyField(position, property, label, true); |
|||
} |
|||
|
|||
public override float GetPropertyHeight(SerializedProperty property, GUIContent label) |
|||
{ |
|||
return EditorGUI.GetPropertyHeight(property); |
|||
} |
|||
} |
|||
} |
|
|||
using System; |
|||
using UnityEditor; |
|||
using UnityEngine.Perception.Randomization.Parameters; |
|||
using UnityEngine.UIElements; |
|||
|
|||
namespace UnityEngine.Perception.Randomization.Editor.PropertyDrawers |
|||
{ |
|||
[CustomPropertyDrawer(typeof(Parameter), true)] |
|||
class ParameterDrawer : PropertyDrawer |
|||
{ |
|||
public override VisualElement CreatePropertyGUI(SerializedProperty property) |
|||
{ |
|||
return new DrawerParameterElement(property); |
|||
} |
|||
|
|||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) |
|||
{ |
|||
EditorGUI.PropertyField(position, property, label, true); |
|||
} |
|||
|
|||
public override float GetPropertyHeight(SerializedProperty property, GUIContent label) |
|||
{ |
|||
return EditorGUI.GetPropertyHeight(property); |
|||
} |
|||
} |
|||
} |
|
|||
using System; |
|||
using Randomization.ParameterBehaviours; |
|||
using UnityEditor; |
|||
using UnityEngine.Perception.Randomization.Parameters; |
|||
using UnityEngine.UIElements; |
|||
|
|||
namespace UnityEngine.Perception.Randomization.Editor |
|||
{ |
|||
[CustomEditor(typeof(ParameterAsset), true)] |
|||
public class ParametersAssetEditor : UnityEditor.Editor |
|||
{ |
|||
VisualElement m_Root; |
|||
VisualElement m_ParameterContainer; |
|||
SerializedProperty m_Parameters; |
|||
|
|||
string m_FilterString = string.Empty; |
|||
string FilterString |
|||
{ |
|||
set |
|||
{ |
|||
m_FilterString = value; |
|||
var lowerFilter = m_FilterString.ToLower(); |
|||
foreach (var child in m_ParameterContainer.Children()) |
|||
{ |
|||
var param = (ParameterListItemElement)child; |
|||
param.filtered = param.displayName.ToLower().Contains(lowerFilter); |
|||
} |
|||
} |
|||
} |
|||
|
|||
public override VisualElement CreateInspectorGUI() |
|||
{ |
|||
m_Root = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>( |
|||
$"{StaticData.uxmlDir}/ParameterAssetEditor.uxml").CloneTree(); |
|||
|
|||
m_ParameterContainer = m_Root.Q<VisualElement>("parameters-container"); |
|||
|
|||
var filter = m_Root.Q<TextField>("filter-parameters"); |
|||
filter.RegisterValueChangedCallback((e) => { FilterString = e.newValue; }); |
|||
|
|||
var collapseAllButton = m_Root.Q<Button>("collapse-all"); |
|||
collapseAllButton.clicked += () => CollapseParameters(true); |
|||
|
|||
var expandAllButton = m_Root.Q<Button>("expand-all"); |
|||
expandAllButton.clicked += () => CollapseParameters(false); |
|||
|
|||
RefreshParameterElements(); |
|||
|
|||
return m_Root; |
|||
} |
|||
|
|||
void RefreshParameterElements() |
|||
{ |
|||
m_ParameterContainer.Clear(); |
|||
var properties = serializedObject.GetIterator(); |
|||
if (properties.NextVisible(true)) |
|||
{ |
|||
do |
|||
{ |
|||
var propertyValue = StaticData.GetManagedReferenceValue(properties); |
|||
if (propertyValue != null && propertyValue.GetType().IsSubclassOf(typeof(Parameter))) |
|||
m_ParameterContainer.Add(new ParameterListItemElement(properties.Copy())); |
|||
} while (properties.NextVisible(false)); |
|||
} |
|||
} |
|||
|
|||
void CollapseParameters(bool collapsed) |
|||
{ |
|||
foreach (var child in m_ParameterContainer.Children()) |
|||
((ParameterListItemElement)child).collapsed = collapsed; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 012ed5df9c884c2dbf47886b520af29a |
|||
timeCreated: 1598378710 |
|
|||
using UnityEditor; |
|||
using UnityEditor.UIElements; |
|||
using UnityEngine.Perception.Randomization.Parameters; |
|||
using UnityEngine.UIElements; |
|||
|
|||
namespace UnityEngine.Perception.Randomization.Editor |
|||
{ |
|||
class ColorHsvaField : ColorField |
|||
{ |
|||
SerializedProperty m_Property; |
|||
SerializedProperty m_H; |
|||
SerializedProperty m_S; |
|||
SerializedProperty m_V; |
|||
SerializedProperty m_A; |
|||
|
|||
public ColorHsvaField(SerializedProperty property) |
|||
{ |
|||
m_Property = property; |
|||
label = m_Property.displayName; |
|||
|
|||
m_H = m_Property.FindPropertyRelative("h"); |
|||
m_S = m_Property.FindPropertyRelative("s"); |
|||
m_V = m_Property.FindPropertyRelative("v"); |
|||
m_A = m_Property.FindPropertyRelative("a"); |
|||
|
|||
rawValue = (Color)new ColorHsva(m_H.floatValue, m_S.floatValue, m_V.floatValue, m_A.floatValue); |
|||
|
|||
this.RegisterValueChangedCallback(evt => |
|||
{ |
|||
var color = (ColorHsva)evt.newValue; |
|||
m_H.floatValue = color.h; |
|||
m_S.floatValue = color.s; |
|||
m_V.floatValue = color.v; |
|||
m_A.floatValue = color.a; |
|||
m_Property.serializedObject.ApplyModifiedProperties(); |
|||
}); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 103b163a2467415ab86b0df8175b12a6 |
|||
timeCreated: 1598254290 |
|
|||
using UnityEditor; |
|||
using UnityEngine.Perception.Randomization.Parameters; |
|||
using UnityEngine.UIElements; |
|||
|
|||
namespace UnityEngine.Perception.Randomization.Editor |
|||
{ |
|||
class DrawerParameterElement : VisualElement |
|||
{ |
|||
Parameter m_Parameter; |
|||
SerializedProperty m_Collapsed; |
|||
SerializedProperty m_Property; |
|||
const string k_CollapsedParameterClass = "collapsed-parameter"; |
|||
|
|||
bool collapsed |
|||
{ |
|||
get => m_Collapsed.boolValue; |
|||
set |
|||
{ |
|||
m_Collapsed.boolValue = value; |
|||
m_Property.serializedObject.ApplyModifiedPropertiesWithoutUndo(); |
|||
if (value) |
|||
AddToClassList(k_CollapsedParameterClass); |
|||
else |
|||
RemoveFromClassList(k_CollapsedParameterClass); |
|||
} |
|||
} |
|||
|
|||
public DrawerParameterElement(SerializedProperty property) |
|||
{ |
|||
m_Property = property; |
|||
m_Collapsed = property.FindPropertyRelative("collapsed"); |
|||
|
|||
AssetDatabase.LoadAssetAtPath<VisualTreeAsset>( |
|||
$"{StaticData.uxmlDir}/ParameterDrawer.uxml").CloneTree(this); |
|||
|
|||
var collapseToggle = this.Q<VisualElement>("collapse"); |
|||
collapseToggle.RegisterCallback<MouseUpEvent>(evt => collapsed = !collapsed); |
|||
collapsed = m_Collapsed.boolValue; |
|||
|
|||
var fieldNameField = this.Q<Label>("field-name"); |
|||
fieldNameField.text = property.displayName; |
|||
|
|||
var drawer = this.Q<VisualElement>("drawer"); |
|||
drawer.Add(new ParameterElement(property)); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: e2eb905ca8c14b5cbe43e48418948be0 |
|||
timeCreated: 1598255728 |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using UnityEditor; |
|||
using UnityEditor.UIElements; |
|||
using UnityEngine.Perception.Randomization.Parameters; |
|||
using UnityEngine.UIElements; |
|||
|
|||
namespace UnityEngine.Perception.Randomization.Editor |
|||
{ |
|||
class ParameterElement : VisualElement |
|||
{ |
|||
VisualElement m_PropertiesContainer; |
|||
SerializedProperty m_SerializedProperty; |
|||
|
|||
Parameter parameter => (Parameter)StaticData.GetManagedReferenceValue(m_SerializedProperty); |
|||
CategoricalParameterBase categoricalParameter => (CategoricalParameterBase)parameter; |
|||
|
|||
public ParameterElement(SerializedProperty property) |
|||
{ |
|||
var template = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>( |
|||
$"{StaticData.uxmlDir}/ParameterElement.uxml"); |
|||
template.CloneTree(this); |
|||
m_SerializedProperty = property; |
|||
m_PropertiesContainer = this.Q<VisualElement>("properties"); |
|||
CreatePropertyFields(); |
|||
} |
|||
|
|||
void CreatePropertyFields() |
|||
{ |
|||
m_PropertiesContainer.Clear(); |
|||
|
|||
if (parameter is CategoricalParameterBase) |
|||
{ |
|||
CreateCategoricalParameterFields(); |
|||
return; |
|||
} |
|||
|
|||
var currentProperty = m_SerializedProperty.Copy(); |
|||
var nextSiblingProperty = m_SerializedProperty.Copy(); |
|||
nextSiblingProperty.NextVisible(false); |
|||
currentProperty.NextVisible(true); |
|||
do |
|||
{ |
|||
if (SerializedProperty.EqualContents(currentProperty, nextSiblingProperty)) |
|||
break; |
|||
if (currentProperty.type.Contains("managedReference") && |
|||
currentProperty.managedReferenceFieldTypename == StaticData.samplerSerializedFieldType) |
|||
m_PropertiesContainer.Add(new SamplerElement(currentProperty.Copy(), parameter)); |
|||
else |
|||
{ |
|||
var propertyField = new PropertyField(currentProperty.Copy()); |
|||
propertyField.Bind(currentProperty.serializedObject); |
|||
m_PropertiesContainer.Add(propertyField); |
|||
} |
|||
} while (currentProperty.NextVisible(false)); |
|||
} |
|||
|
|||
void CreateCategoricalParameterFields() |
|||
{ |
|||
var template = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>( |
|||
$"{StaticData.uxmlDir}/CategoricalParameterTemplate.uxml").CloneTree(); |
|||
|
|||
var optionsProperty = m_SerializedProperty.FindPropertyRelative("m_Categories"); |
|||
var probabilitiesProperty = m_SerializedProperty.FindPropertyRelative("probabilities"); |
|||
var probabilities = categoricalParameter.probabilities; |
|||
|
|||
var listView = template.Q<ListView>("options"); |
|||
listView.itemsSource = probabilities; |
|||
listView.itemHeight = 22; |
|||
listView.selectionType = SelectionType.None; |
|||
listView.style.flexGrow = 1.0f; |
|||
listView.style.height = new StyleLength(listView.itemHeight * 4); |
|||
|
|||
VisualElement MakeItem() => new CategoricalOptionElement( |
|||
optionsProperty, probabilitiesProperty); |
|||
listView.makeItem = MakeItem; |
|||
|
|||
void BindItem(VisualElement e, int i) |
|||
{ |
|||
var optionElement = (CategoricalOptionElement)e; |
|||
optionElement.BindProperties(i); |
|||
var removeButton = optionElement.Q<Button>("remove"); |
|||
removeButton.clicked += () => |
|||
{ |
|||
probabilitiesProperty.DeleteArrayElementAtIndex(i); |
|||
|
|||
// First delete sets option to null, second delete removes option
|
|||
var numOptions = optionsProperty.arraySize; |
|||
optionsProperty.DeleteArrayElementAtIndex(i); |
|||
if (numOptions == optionsProperty.arraySize) |
|||
optionsProperty.DeleteArrayElementAtIndex(i); |
|||
|
|||
m_SerializedProperty.serializedObject.ApplyModifiedProperties(); |
|||
listView.itemsSource = categoricalParameter.probabilities; |
|||
listView.Refresh(); |
|||
}; |
|||
} |
|||
listView.bindItem = BindItem; |
|||
|
|||
var addOptionButton = template.Q<Button>("add-option"); |
|||
addOptionButton.clicked += () => |
|||
{ |
|||
probabilitiesProperty.arraySize++; |
|||
optionsProperty.arraySize++; |
|||
m_SerializedProperty.serializedObject.ApplyModifiedProperties(); |
|||
listView.itemsSource = categoricalParameter.probabilities; |
|||
listView.Refresh(); |
|||
listView.ScrollToItem(probabilitiesProperty.arraySize); |
|||
}; |
|||
|
|||
var addFolderButton = template.Q<Button>("add-folder"); |
|||
if (categoricalParameter.sampleType.IsSubclassOf(typeof(Object))) |
|||
{ |
|||
addFolderButton.clicked += () => |
|||
{ |
|||
var folderPath = EditorUtility.OpenFolderPanel( |
|||
"Add Options From Folder", Application.dataPath, string.Empty); |
|||
if (folderPath == string.Empty) |
|||
return; |
|||
var categories = LoadAssetsFromFolder(folderPath, categoricalParameter.sampleType); |
|||
probabilitiesProperty.arraySize += categories.Count; |
|||
optionsProperty.arraySize += categories.Count; |
|||
var uniformProbability = 1f / categories.Count; |
|||
for (var i = 0; i < categories.Count; i++) |
|||
{ |
|||
var optionProperty = optionsProperty.GetArrayElementAtIndex(i); |
|||
var probabilityProperty = probabilitiesProperty.GetArrayElementAtIndex(i); |
|||
optionProperty.objectReferenceValue = categories[i]; |
|||
probabilityProperty.floatValue = uniformProbability; |
|||
} |
|||
m_SerializedProperty.serializedObject.ApplyModifiedProperties(); |
|||
listView.itemsSource = categoricalParameter.probabilities; |
|||
listView.Refresh(); |
|||
}; |
|||
} |
|||
else |
|||
addFolderButton.style.display = new StyleEnum<DisplayStyle>(DisplayStyle.None); |
|||
|
|||
var clearOptionsButton = template.Q<Button>("clear-options"); |
|||
clearOptionsButton.clicked += () => |
|||
{ |
|||
probabilitiesProperty.arraySize = 0; |
|||
optionsProperty.arraySize = 0; |
|||
m_SerializedProperty.serializedObject.ApplyModifiedProperties(); |
|||
listView.itemsSource = categoricalParameter.probabilities; |
|||
listView.Refresh(); |
|||
}; |
|||
|
|||
var scrollView = listView.Q<ScrollView>(); |
|||
listView.RegisterCallback<WheelEvent>(evt => |
|||
{ |
|||
if (Mathf.Approximately(scrollView.verticalScroller.highValue, 0f)) |
|||
return; |
|||
if ((scrollView.scrollOffset.y <= 0f && evt.delta.y < 0f) || |
|||
scrollView.scrollOffset.y >= scrollView.verticalScroller.highValue && evt.delta.y > 0f) |
|||
evt.StopImmediatePropagation(); |
|||
}); |
|||
|
|||
var uniformToggle = template.Q<Toggle>("uniform"); |
|||
var uniformProperty = m_SerializedProperty.FindPropertyRelative("uniform"); |
|||
uniformToggle.BindProperty(uniformProperty); |
|||
void ToggleProbabilityFields(bool toggle) |
|||
{ |
|||
if (toggle) |
|||
listView.AddToClassList("uniform-probability"); |
|||
else |
|||
listView.RemoveFromClassList("uniform-probability"); |
|||
} |
|||
ToggleProbabilityFields(uniformToggle.value); |
|||
if (Application.isPlaying) |
|||
uniformToggle.SetEnabled(false); |
|||
else |
|||
uniformToggle.RegisterCallback<ChangeEvent<bool>>(evt => ToggleProbabilityFields(evt.newValue)); |
|||
|
|||
var seedField = template.Q<IntegerField>("seed"); |
|||
seedField.BindProperty(m_SerializedProperty.FindPropertyRelative("m_Sampler.<baseSeed>k__BackingField")); |
|||
|
|||
m_PropertiesContainer.Add(template); |
|||
} |
|||
|
|||
static List<Object> LoadAssetsFromFolder(string folderPath, Type assetType) |
|||
{ |
|||
if (!folderPath.StartsWith(Application.dataPath)) |
|||
throw new ApplicationException("Selected folder is not an asset folder in this project"); |
|||
var assetsPath = "Assets" + folderPath.Remove(0, Application.dataPath.Length); |
|||
var assetIds = AssetDatabase.FindAssets($"t:{assetType.Name}", new []{assetsPath}); |
|||
var assets = new List<Object>(); |
|||
foreach (var guid in assetIds) |
|||
assets.Add(AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(guid), assetType)); |
|||
return assets; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: a26a70e27aed4ced88ef9ac7e17c2793 |
|||
timeCreated: 1598228666 |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using UnityEditor; |
|||
using UnityEditor.UIElements; |
|||
using UnityEngine.Perception.Randomization.ParameterBehaviours; |
|||
using UnityEngine.Perception.Randomization.Parameters; |
|||
using UnityEngine.UIElements; |
|||
|
|||
namespace UnityEngine.Perception.Randomization.Editor |
|||
{ |
|||
class ParameterListItemElement : VisualElement |
|||
{ |
|||
VisualElement m_Properties; |
|||
VisualElement m_TargetContainer; |
|||
ToolbarMenu m_TargetPropertyMenu; |
|||
SerializedProperty m_SerializedProperty; |
|||
SerializedProperty m_Collapsed; |
|||
|
|||
const string k_CollapsedParameterClass = "collapsed-parameter"; |
|||
|
|||
public bool collapsed |
|||
{ |
|||
get => m_Collapsed.boolValue; |
|||
set |
|||
{ |
|||
m_Collapsed.boolValue = value; |
|||
m_SerializedProperty.serializedObject.ApplyModifiedProperties(); |
|||
if (value) |
|||
AddToClassList(k_CollapsedParameterClass); |
|||
else |
|||
RemoveFromClassList(k_CollapsedParameterClass); |
|||
} |
|||
} |
|||
|
|||
public string displayName => m_SerializedProperty.displayName; |
|||
|
|||
public bool filtered |
|||
{ |
|||
set => style.display = value |
|||
? new StyleEnum<DisplayStyle>(DisplayStyle.Flex) |
|||
: new StyleEnum<DisplayStyle>(DisplayStyle.None); |
|||
} |
|||
|
|||
public ParameterListItemElement(SerializedProperty property) |
|||
{ |
|||
var template = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>( |
|||
$"{StaticData.uxmlDir}/ParameterListItemElement.uxml"); |
|||
template.CloneTree(this); |
|||
|
|||
m_SerializedProperty = property; |
|||
var parameter = (Parameter)StaticData.GetManagedReferenceValue(property); |
|||
m_Collapsed = property.FindPropertyRelative("collapsed"); |
|||
|
|||
var parameterTypeLabel = this.Query<Label>("parameter-type-label").First(); |
|||
parameterTypeLabel.text = Parameter.GetDisplayName(parameter.GetType()); |
|||
|
|||
var parameterNameField = this.Q<TextElement>("name"); |
|||
parameterNameField.text = property.displayName; |
|||
|
|||
var collapseToggle = this.Q<VisualElement>("collapse"); |
|||
collapseToggle.RegisterCallback<MouseUpEvent>(evt => collapsed = !collapsed); |
|||
|
|||
var parameterProperties = this.Q<VisualElement>("properties"); |
|||
parameterProperties.Add(new ParameterElement(property)); |
|||
} |
|||
} |
|||
} |
|
|||
using System; |
|||
using Unity.Mathematics; |
|||
|
|||
namespace UnityEngine.Perception.Randomization.Parameters |
|||
{ |
|||
/// <summary>
|
|||
/// A struct representing the hue, saturation, value, and alpha components of a particular color
|
|||
/// </summary>
|
|||
[Serializable] |
|||
public struct ColorHsva |
|||
{ |
|||
/// <summary>
|
|||
/// A float value representing the hue component of a color
|
|||
/// </summary>
|
|||
public float h; |
|||
|
|||
/// <summary>
|
|||
/// A float value representing the saturation component of a color
|
|||
/// </summary>
|
|||
public float s; |
|||
|
|||
/// <summary>
|
|||
/// A float value representing the value component of a color
|
|||
/// </summary>
|
|||
public float v; |
|||
|
|||
/// <summary>
|
|||
/// A float value representing the alpha component of a color
|
|||
/// </summary>
|
|||
public float a; |
|||
|
|||
/// <summary>
|
|||
/// Constructs an ColorHsva struct
|
|||
/// </summary>
|
|||
/// <param name="h">Hue</param>
|
|||
/// <param name="s">Saturation</param>
|
|||
/// <param name="v">Value</param>
|
|||
/// <param name="a">Alpha</param>
|
|||
public ColorHsva(float h, float s, float v, float a) |
|||
{ |
|||
this.h = h; |
|||
this.s = s; |
|||
this.v = v; |
|||
this.a = a; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Implicitly converts an HSVA Color to a float4
|
|||
/// </summary>
|
|||
/// <param name="c">The HSVA color to convert to a float4</param>
|
|||
/// <returns>A new float4</returns>
|
|||
public static implicit operator float4(ColorHsva c) => new float4(c.h, c.s, c.v, c.a); |
|||
|
|||
/// <summary>
|
|||
/// Implicitly converts an float4 to an HSVA color
|
|||
/// </summary>
|
|||
/// <param name="f">The float4 to convert to an HSVA color</param>
|
|||
/// <returns>A new HSVA color</returns>
|
|||
public static implicit operator ColorHsva(float4 f) => new ColorHsva(f.x, f.y, f.z, f.w); |
|||
|
|||
/// <summary>
|
|||
/// Implicitly converts an HSVA Color to a Vector4
|
|||
/// </summary>
|
|||
/// <param name="c">The HSVA color to convert to a Vector4</param>
|
|||
/// <returns>A new Vector4</returns>
|
|||
public static implicit operator Vector4(ColorHsva c) => new float4(c.h, c.s, c.v, c.a); |
|||
|
|||
/// <summary>
|
|||
/// Implicitly converts an Vector4 to an HSVA color
|
|||
/// </summary>
|
|||
/// <param name="v">The Vector4 color to convert to an HSVA color</param>
|
|||
/// <returns>A new HSVA color</returns>
|
|||
public static implicit operator ColorHsva(Vector4 v) => new ColorHsva(v.x, v.y, v.z, v.w); |
|||
|
|||
/// <summary>
|
|||
/// Converts an HSVA Color to an RGBA Color
|
|||
/// </summary>
|
|||
/// <param name="c">The HSVA color to convert to RGBA</param>
|
|||
/// <returns>A new RGBA color</returns>
|
|||
public static explicit operator Color(ColorHsva c) |
|||
{ |
|||
var color = Color.HSVToRGB(c.h, c.s, c.v); |
|||
color.a = c.a; |
|||
return color; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Converts an RGBA Color to an HSVA Color
|
|||
/// </summary>
|
|||
/// <param name="c">The RGBA color to convert to HSVA</param>
|
|||
/// <returns>A new HSVA color</returns>
|
|||
public static explicit operator ColorHsva(Color c) |
|||
{ |
|||
Color.RGBToHSV(c, out var h, out var s, out var v); |
|||
return new ColorHsva(h, s, v, c.a); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Generates a string representation of a ColorHsva
|
|||
/// </summary>
|
|||
/// <returns>A string representing the components of this ColorHsva</returns>
|
|||
public override string ToString() |
|||
{ |
|||
return $"ColorHsva({h}, {s}, {v}, {a})"; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: ccdce8798ec146649d4714046529de2c |
|||
timeCreated: 1598326388 |
|
|||
using System; |
|||
|
|||
namespace UnityEngine.Perception.Randomization.Parameters |
|||
{ |
|||
/// <summary>
|
|||
/// A categorical parameter for generating ColorHsva samples
|
|||
/// </summary>
|
|||
[Serializable] |
|||
public class ColorHsvaCategoricalParameter : CategoricalParameter<ColorHsva> { } |
|||
} |
|
|||
using System; |
|||
|
|||
namespace UnityEngine.Perception.Randomization.Parameters |
|||
{ |
|||
/// <summary>
|
|||
/// A categorical parameter for generating RGBA color samples
|
|||
/// </summary>
|
|||
[Serializable] |
|||
public class ColorRgbCategoricalParameter : CategoricalParameter<Color> { } |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: e7985c4ea0bf49578e9cabd2c1a63cb6 |
|||
timeCreated: 1598217458 |
|
|||
fileFormatVersion: 2 |
|||
guid: f4bd575c48a145ec9b63eb48ce636ed7 |
|||
timeCreated: 1598251957 |
|
|||
fileFormatVersion: 2 |
|||
guid: a4fdf61227254683a9950f586d6e8f57 |
|||
timeCreated: 1598252064 |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using Unity.Burst; |
|||
using Unity.Collections; |
|||
using Unity.Jobs; |
|||
using UnityEngine.Perception.Randomization.Samplers; |
|||
|
|||
namespace UnityEngine.Perception.Randomization.Parameters |
|||
{ |
|||
/// <summary>
|
|||
/// A numeric parameter for generating RGBA color samples
|
|||
/// </summary>
|
|||
[Serializable] |
|||
public class ColorRgbParameter : NumericParameter<Color> |
|||
{ |
|||
/// <summary>
|
|||
/// The sampler used for randomizing the red component of generated samples
|
|||
/// </summary>
|
|||
[SerializeReference] public ISampler red = new UniformSampler(0f, 1f); |
|||
|
|||
/// <summary>
|
|||
/// The sampler used for randomizing the green component of generated samples
|
|||
/// </summary>
|
|||
[SerializeReference] public ISampler green = new UniformSampler(0f, 1f); |
|||
|
|||
/// <summary>
|
|||
/// The sampler used for randomizing the blue component of generated samples
|
|||
/// </summary>
|
|||
[SerializeReference] public ISampler blue = new UniformSampler(0f, 1f); |
|||
|
|||
/// <summary>
|
|||
/// The sampler used for randomizing the alpha component of generated samples
|
|||
/// </summary>
|
|||
[SerializeReference] public ISampler alpha = new ConstantSampler(1f); |
|||
|
|||
/// <summary>
|
|||
/// Returns an IEnumerable that iterates over each sampler field in this parameter
|
|||
/// </summary>
|
|||
public override IEnumerable<ISampler> samplers |
|||
{ |
|||
get |
|||
{ |
|||
yield return red; |
|||
yield return green; |
|||
yield return blue; |
|||
yield return alpha; |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Generates an RGBA color sample
|
|||
/// </summary>
|
|||
/// <returns>The generated RGBA sample</returns>
|
|||
public override Color Sample() |
|||
{ |
|||
return new Color(red.Sample(), green.Sample(), blue.Sample(), alpha.Sample()); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Schedules a job to generate an array of samples
|
|||
/// </summary>
|
|||
/// <param name="sampleCount">The number of samples to generate</param>
|
|||
/// <param name="jobHandle">The handle of the scheduled job</param>
|
|||
/// <returns>A NativeArray of samples</returns>
|
|||
public override NativeArray<Color> Samples(int sampleCount, out JobHandle jobHandle) |
|||
{ |
|||
var samples = new NativeArray<Color>(sampleCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory); |
|||
var redRng = red.Samples(sampleCount, out var redHandle); |
|||
var greenRng = green.Samples(sampleCount, out var greenHandle); |
|||
var blueRng = blue.Samples(sampleCount, out var blueHandle); |
|||
var alphaRng = alpha.Samples(sampleCount, out var alphaHandle); |
|||
|
|||
var handles = new NativeArray<JobHandle>(4, Allocator.TempJob) |
|||
{ |
|||
[0] = redHandle, |
|||
[1] = greenHandle, |
|||
[2] = blueHandle, |
|||
[3] = alphaHandle |
|||
}; |
|||
var combinedJobHandles = JobHandle.CombineDependencies(handles); |
|||
|
|||
jobHandle = new SamplesJob |
|||
{ |
|||
redRng = redRng, |
|||
greenRng = greenRng, |
|||
blueRng = blueRng, |
|||
alphaRng = alphaRng, |
|||
samples = samples |
|||
}.Schedule(combinedJobHandles); |
|||
handles.Dispose(jobHandle); |
|||
|
|||
return samples; |
|||
} |
|||
|
|||
[BurstCompile] |
|||
struct SamplesJob : IJob |
|||
{ |
|||
[DeallocateOnJobCompletion] public NativeArray<float> redRng; |
|||
[DeallocateOnJobCompletion] public NativeArray<float> greenRng; |
|||
[DeallocateOnJobCompletion] public NativeArray<float> blueRng; |
|||
[DeallocateOnJobCompletion] public NativeArray<float> alphaRng; |
|||
public NativeArray<Color> samples; |
|||
|
|||
public void Execute() |
|||
{ |
|||
for (var i = 0; i < samples.Length; i++) |
|||
samples[i] = new Color(redRng[i], greenRng[i], blueRng[i], alphaRng[i]); |
|||
} |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: bb8689894f7f41d180c308dbe85f3ced |
|||
timeCreated: 1598132668 |
|
|||
fileFormatVersion: 2 |
|||
guid: e71c37bf9c4144728de471f853a09a19 |
|||
timeCreated: 1598290624 |
|
|||
fileFormatVersion: 2 |
|||
guid: 396df67bc35a43dbabb608af04012599 |
|||
timeCreated: 1598378733 |
|
|||
using System; |
|||
|
|||
namespace UnityEngine.Perception.Randomization.ParameterBehaviours |
|||
{ |
|||
[Serializable] |
|||
class ParameterListException : Exception |
|||
{ |
|||
public ParameterListException(string message) : base(message) { } |
|||
public ParameterListException(string message, Exception innerException) : base(message, innerException) { } |
|||
} |
|||
} |
|
|||
using System; |
|||
using UnityEngine.Perception.Randomization.Parameters; |
|||
|
|||
namespace UnityEngine.Perception.Randomization.ParameterBehaviours |
|||
{ |
|||
[Serializable] |
|||
class ParameterListItem |
|||
{ |
|||
public string name = "Parameter"; |
|||
[SerializeReference] public Parameter parameter; |
|||
[HideInInspector, SerializeField] public ParameterTarget target = new ParameterTarget(); |
|||
|
|||
public bool hasTarget => target.component != null; |
|||
|
|||
public void ApplyToTarget() |
|||
{ |
|||
if (!hasTarget) |
|||
return; |
|||
target.ApplyValueToTarget(parameter.GenericSample()); |
|||
} |
|||
|
|||
public void Validate() |
|||
{ |
|||
target.Validate(); |
|||
parameter.Validate(); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: b922e785add647cd876af9a755bbddf5 |
|||
timeCreated: 1598227279 |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using Randomization.ParameterBehaviours; |
|||
using UnityEngine; |
|||
using UnityEngine.Perception.Randomization.Parameters; |
|||
|
|||
namespace UnityEngine.Perception.Randomization.ParameterBehaviours |
|||
{ |
|||
/// <summary>
|
|||
/// Defines a list of parameters for randomizing simulations
|
|||
/// </summary>
|
|||
[ExecuteInEditMode] |
|||
[AddComponentMenu("Perception/Randomization/Parameter List")] |
|||
public class ParameterList : ParameterBehaviour |
|||
{ |
|||
[SerializeReference] internal List<ParameterListItem> configuredParameters = new List<ParameterListItem>(); |
|||
|
|||
// /// <summary>
|
|||
// /// The parameters contained within this ParameterList
|
|||
// /// </summary>
|
|||
// public override IEnumerable<Parameter> parameters
|
|||
// {
|
|||
// get
|
|||
// {
|
|||
// foreach (var configParameter in configuredParameters)
|
|||
// yield return configParameter.parameter;
|
|||
// }
|
|||
// }
|
|||
|
|||
internal ParameterListItem AddParameter<T>(string parameterName) where T : Parameter, new() |
|||
{ |
|||
var parameter = new T(); |
|||
var configParameter = new ParameterListItem { name = parameterName, parameter = parameter }; |
|||
configuredParameters.Add(configParameter); |
|||
return configParameter; |
|||
} |
|||
|
|||
internal ParameterListItem AddParameter(string parameterName, Type parameterType) |
|||
{ |
|||
if (!parameterType.IsSubclassOf(typeof(Parameter))) |
|||
throw new ParameterListException($"Cannot add non-parameter types ({parameterType})"); |
|||
var parameter = (Parameter)Activator.CreateInstance(parameterType); |
|||
var configParameter = new ParameterListItem { name = parameterName, parameter = parameter }; |
|||
configuredParameters.Add(configParameter); |
|||
return configParameter; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Find a parameter in this configuration by name
|
|||
/// </summary>
|
|||
/// <param name="parameterName">The name of the parameter to lookup</param>
|
|||
/// <param name="parameterType">The type of parameter to lookup</param>
|
|||
/// <returns>The parameter if found, null otherwise</returns>
|
|||
/// <exception cref="ParameterListException"></exception>
|
|||
public Parameter GetParameter(string parameterName, Type parameterType) |
|||
{ |
|||
foreach (var configParameter in configuredParameters) |
|||
{ |
|||
if (configParameter.name == parameterName && configParameter.parameter.GetType() == parameterType) |
|||
return configParameter.parameter; |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Find a parameter in this configuration by name and type
|
|||
/// </summary>
|
|||
/// <param name="parameterName"></param>
|
|||
/// <typeparam name="T">The type of parameter to look for</typeparam>
|
|||
/// <returns>The parameter if found, null otherwise</returns>
|
|||
public T GetParameter<T>(string parameterName) where T : Parameter |
|||
{ |
|||
foreach (var configuredParameter in configuredParameters) |
|||
{ |
|||
if (configuredParameter.name == parameterName && configuredParameter.parameter is T typedParameter) |
|||
return typedParameter; |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Applies parameter samples to their targets at the start of each scenario iteration
|
|||
/// </summary>
|
|||
public override void OnIterationStart() |
|||
{ |
|||
foreach (var configParameter in configuredParameters) |
|||
if (configParameter.target.applicationFrequency == ParameterApplicationFrequency.EveryIteration) |
|||
configParameter.ApplyToTarget(); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Applies parameter samples to their targets at the start of every frame
|
|||
/// </summary>
|
|||
public override void OnFrameStart() |
|||
{ |
|||
foreach (var configParameter in configuredParameters) |
|||
if (configParameter.target.applicationFrequency == ParameterApplicationFrequency.EveryFrame) |
|||
configParameter.ApplyToTarget(); |
|||
} |
|||
|
|||
// /// <summary>
|
|||
// /// Validates the settings of each parameter within this ParameterList
|
|||
// /// </summary>
|
|||
// /// <exception cref="ParameterListException"></exception>
|
|||
// public override void Validate()
|
|||
// {
|
|||
// var parameterNames = new HashSet<string>();
|
|||
// foreach (var configParameter in configuredParameters)
|
|||
// {
|
|||
// if (parameterNames.Contains(configParameter.name))
|
|||
// throw new ParameterListException(
|
|||
// $"Two or more parameters cannot share the same name (\"{configParameter.name}\")");
|
|||
// parameterNames.Add(configParameter.name);
|
|||
// configParameter.Validate();
|
|||
// }
|
|||
// }
|
|||
} |
|||
} |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
using UnityEngine.Perception.Randomization.Parameters; |
|||
using UnityEngine.Perception.Randomization.Samplers; |
|||
|
|||
namespace Randomization.ParameterBehaviours |
|||
{ |
|||
public abstract class ParameterAsset : ScriptableObject |
|||
{ |
|||
internal IEnumerable<Parameter> parameters |
|||
{ |
|||
get |
|||
{ |
|||
var fields = GetType().GetFields(); |
|||
foreach (var field in fields) |
|||
{ |
|||
if (!field.IsPublic || !field.FieldType.IsSubclassOf(typeof(Parameter))) |
|||
continue; |
|||
var parameter = (Parameter)field.GetValue(this); |
|||
if (parameter == null) |
|||
{ |
|||
parameter = (Parameter)Activator.CreateInstance(field.FieldType); |
|||
field.SetValue(this, parameter); |
|||
} |
|||
yield return parameter; |
|||
} |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Reset to default values in the Editor
|
|||
/// </summary>
|
|||
public virtual void Reset() |
|||
{ |
|||
foreach (var parameter in parameters) |
|||
foreach (var sampler in parameter.samplers) |
|||
sampler.baseSeed = SamplerUtility.GenerateRandomSeed(); |
|||
} |
|||
} |
|||
} |
|
|||
using System; |
|||
using UnityEngine; |
|||
using UnityEngine.Perception.Randomization.Scenarios; |
|||
|
|||
namespace Randomization.ParameterBehaviours |
|||
{ |
|||
/// <summary>
|
|||
/// The base class for all randomization scripts
|
|||
/// </summary>
|
|||
public abstract class ParameterBehaviour : MonoBehaviour |
|||
{ |
|||
public virtual int executionPriority => 1; |
|||
|
|||
public void Awake() |
|||
{ |
|||
ScenarioBase.activeScenario.AddBehaviour(this); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Included in the base ParameterBehaviour class to activate the enabled toggle in the inspector UI
|
|||
/// </summary>
|
|||
protected virtual void OnEnable() {} |
|||
|
|||
/// <summary>
|
|||
/// OnFrameStart is called at the start of every frame if the ParameterBehaviour is enabled
|
|||
/// </summary>
|
|||
public virtual void OnFrameStart() { } |
|||
|
|||
/// <summary>
|
|||
/// OnIterationStart is called at the start of every iteration if the ParameterBehaviour is enabled
|
|||
/// </summary>
|
|||
public virtual void OnIterationStart() { } |
|||
|
|||
/// <summary>
|
|||
/// OnIterationEnd is called at the end of every iteration if the ParameterBehaviour is enabled
|
|||
/// </summary>
|
|||
public virtual void OnIterationEnd() { } |
|||
|
|||
/// <summary>
|
|||
/// Run when the scenario completes
|
|||
/// </summary>
|
|||
public virtual void OnScenarioComplete() {} |
|||
} |
|||
} |
|
|||
.dark-viewport { |
|||
border-radius: 5px; |
|||
background-color: #191919; |
|||
padding: 2px; |
|||
} |
|||
|
|||
.parameter-container { |
|||
border-width: 2px; |
|||
border-radius: 5px; |
|||
flex-direction: row; |
|||
margin: 2px 1px; |
|||
} |
|||
|
|||
.parameter-type-menu { |
|||
margin: 1px 3px; |
|||
border-width: 1px; |
|||
border-radius: 3px; |
|||
background-color: #585858; |
|||
} |
|||
|
|||
#parameter-type-menu .unity-toolbar-menu__text { |
|||
font-size: 13px; |
|||
padding: 3px; |
|||
} |
|||
|
|||
.sampler-type-menu { |
|||
flex-grow: 1.5; |
|||
border-radius: 3px; |
|||
border-width: 1px; |
|||
margin-top: 2px; |
|||
margin-right: 3px; |
|||
} |
|||
|
|||
.sampler-name { |
|||
/*color: lightgreen;*/ |
|||
-unity-font-style: bold; |
|||
} |
|||
|
|||
.parameter-type-label-container { |
|||
flex-direction: row; |
|||
justify-content: space-between; |
|||
align-items: center; |
|||
margin-bottom: 1px; |
|||
} |
|||
|
|||
.parameter-type-label-box { |
|||
flex-direction: row; |
|||
align-items: center; |
|||
justify-content: flex-start; |
|||
flex-grow: 0; |
|||
-unity-text-align: middle-center; |
|||
border-width: 0; |
|||
padding: 1px; |
|||
font-size: 13px; |
|||
-unity-font-style: bold; |
|||
} |
|||
|
|||
.parameter-type-label { |
|||
color: cornflowerblue; |
|||
/*min-width: 120px;*/ |
|||
-unity-text-align: middle-left; |
|||
} |
|||
|
|||
.parameter-type-label-box .unity-base-text-field__input { |
|||
padding-left: 6px; |
|||
padding-right: 6px; |
|||
} |
|||
|
|||
.unity-toggle { |
|||
margin-left: 0; |
|||
} |
|||
|
|||
.property-selection-container { |
|||
flex-direction: row; |
|||
} |
|||
|
|||
.property-select-menu { |
|||
flex-grow: 1; |
|||
border-width: 1px; |
|||
padding-bottom: 1px; |
|||
border-radius: 3px; |
|||
margin-right: 1px; |
|||
} |
|||
|
|||
.remove-parameter-button { |
|||
background-image: resource("Packages/com.unity.perception/Editor/Randomization/Icons/X.png"); |
|||
width: 16px; |
|||
height: 16px; |
|||
} |
|||
|
|||
.move-buttons-container { |
|||
width: auto; |
|||
margin-right: 6px; |
|||
border-color: black; |
|||
border-top-left-radius: 3px; |
|||
border-bottom-left-radius: 3px; |
|||
background-color: #2A2A2A; |
|||
padding: 3px 2px; |
|||
justify-content: center; |
|||
} |
|||
|
|||
.drag-handle { |
|||
width: 16px; |
|||
height: 70%; |
|||
min-height: 20px; |
|||
background-image: resource("Packages/com.unity.perception/Editor/Randomization/Icons/DragHandle.png"); |
|||
} |
|||
|
|||
.move-button { |
|||
border-width: 0; |
|||
width: 42px; |
|||
height: 16px; |
|||
padding: 9px; |
|||
-unity-background-scale-mode: scale-to-fit; |
|||
} |
|||
|
|||
.unity-imgui-container { |
|||
margin-left: 1px; |
|||
margin-right: 3px; |
|||
} |
|||
|
|||
.search-icon { |
|||
width: 16px; |
|||
height: 16px; |
|||
margin-top: 2px; |
|||
flex-shrink: 0; |
|||
background-image: resource("Packages/com.unity.perception/Editor/Randomization/Icons/Search.png"); |
|||
} |
|||
|
|||
.collapse-parameter-toggle { |
|||
flex-shrink: 0; |
|||
margin-right: 2px; |
|||
width: 12px; |
|||
height: 12px; |
|||
background-image: resource("Packages/com.unity.perception/Editor/Randomization/Icons/FoldoutOpen.png"); |
|||
} |
|||
|
|||
.collapsed-parameter .collapse-parameter-toggle { |
|||
background-image: resource("Packages/com.unity.perception/Editor/Randomization/Icons/FoldoutClosed.png"); |
|||
} |
|||
|
|||
.collapsed-parameter .parameter-properties-container { |
|||
display: none; |
|||
} |
|||
|
|||
.collapsed-parameter .move-buttons-container { |
|||
flex-direction: row; |
|||
} |
|||
|
|||
.collapsed-parameter .move-button { |
|||
width: 16px; |
|||
} |
|||
|
|||
.categorical-option { |
|||
flex-direction: row; |
|||
background-color: #3F3F3F; |
|||
margin: 1px; |
|||
border-radius: 4px; |
|||
} |
|||
|
|||
.options-list-view { |
|||
background-color: #191919; |
|||
border-radius: 4px; |
|||
margin-right: 2px; |
|||
padding: 3px; |
|||
border-bottom-right-radius: 0; |
|||
} |
|||
|
|||
.option-property-field { |
|||
width: 0; |
|||
flex-grow: 1; |
|||
flex-shrink: 0; |
|||
} |
|||
|
|||
.uniform-probability .hide-when-uniform { |
|||
display: none; |
|||
} |
|||
|
|||
.add-option-button { |
|||
align-self: flex-end; |
|||
border-width: 0; |
|||
border-top-right-radius: 0; |
|||
border-top-left-radius: 0; |
|||
background-color: #191919; |
|||
margin-top: 0; |
|||
margin-right: 2px; |
|||
} |
|||
|
|||
.add-option-button:hover { |
|||
background-color: #2A2A2A; |
|||
} |
|||
|
|||
.add-option-button:active { |
|||
color: cornflowerblue; |
|||
} |
|||
|
|||
.remove-option-button { |
|||
width: 12px; |
|||
height: 14px; |
|||
background-image: resource("Packages/com.unity.perception/Editor/Randomization/Icons/X.png"); |
|||
} |
|||
|
|||
.parameter-drag-bar { |
|||
width: 100px; |
|||
height: 6px; |
|||
background-color: rgba(100,149,237,0.4); |
|||
position: absolute; |
|||
} |
|||
|
|||
.float-range .unity-base-field__label { |
|||
min-width: auto; |
|||
margin-right: 4px; |
|||
} |
|
|||
<UXML xmlns="UnityEngine.UIElements" xmlns:editor="UnityEditor.UIElements"> |
|||
<VisualElement> |
|||
<Style src="../Uss/Styles.uss"/> |
|||
|
|||
<VisualElement style="flex-direction: row; align-items: center; margin-bottom: 2px; margin-top: 2px;"> |
|||
<VisualElement class="search-icon" style="margin-left: 3px; margin-right: 2px;"/> |
|||
<TextField name="filter-parameters" style="flex-grow: 1; flex-shrink: 1;"/> |
|||
</VisualElement> |
|||
<ScrollView name="parameter-scroll-view" class="dark-viewport" style="min-height: 100px; max-height: 600px;"> |
|||
<VisualElement name="parameters-container" style="flex-shrink: 0;"/> |
|||
</ScrollView> |
|||
|
|||
<VisualElement style="flex-direction: row; justify-content: space-between;"> |
|||
<VisualElement style="flex-grow: 1"/> |
|||
<editor:ToolbarMenu text="Add New Parameter" name="parameter-type-menu" class="parameter-type-menu"/> |
|||
<Button name="collapse-all" text="Collapse All" style="font-size: 13px; padding: 4px;"/> |
|||
<Button name="expand-all" text="Expand All" style="font-size: 13px; padding: 4px;"/> |
|||
<VisualElement style="flex-grow: 1"/> |
|||
</VisualElement> |
|||
</VisualElement> |
|||
</UXML> |
|
|||
<UXML xmlns="UnityEngine.UIElements" xmlns:editor="UnityEditor.UIElements"> |
|||
<VisualElement style="flex-direction: row;"> |
|||
<Label style="width: 150px;"/> |
|||
<editor:ToolbarMenu style="flex-grow: 1; margin-left: 3px; margin-right: 2px; border-top-width: 1px; border-bottom-width: 1px; border-radius: 3px;"/> |
|||
</VisualElement> |
|||
</UXML> |
|
|||
fileFormatVersion: 2 |
|||
guid: 18765b47a76c4adcb639d0d247b8bd34 |
|||
timeCreated: 1596419194 |
|
|||
using System; |
|||
using UnityEngine; |
|||
using UnityEditor; |
|||
using UnityEditor.UIElements; |
|||
using UnityEngine.Perception.Randomization.Configuration; |
|||
using UnityEngine.Perception.Randomization.Parameters; |
|||
using UnityEngine.UIElements; |
|||
|
|||
namespace UnityEngine.Perception.Randomization.Editor |
|||
{ |
|||
[CustomEditor(typeof(ParameterConfiguration))] |
|||
class ParameterConfigurationEditor : UnityEditor.Editor |
|||
{ |
|||
VisualElement m_Root; |
|||
VisualElement m_ParameterContainer; |
|||
|
|||
public ParameterConfiguration config; |
|||
|
|||
string m_FilterString = string.Empty; |
|||
public string FilterString |
|||
{ |
|||
get => m_FilterString; |
|||
private set |
|||
{ |
|||
m_FilterString = value; |
|||
var lowerFilter = m_FilterString.ToLower(); |
|||
foreach (var child in m_ParameterContainer.Children()) |
|||
{ |
|||
var paramIndex = m_ParameterContainer.IndexOf(child); |
|||
var param = config.parameters[paramIndex]; |
|||
((ParameterElement)child).Filtered = param.name.ToLower().Contains(lowerFilter); |
|||
} |
|||
} |
|||
} |
|||
|
|||
public override VisualElement CreateInspectorGUI() |
|||
{ |
|||
config = (ParameterConfiguration)target; |
|||
m_Root = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>( |
|||
$"{StaticData.uxmlDir}/ParameterConfiguration.uxml").CloneTree(); |
|||
|
|||
m_ParameterContainer = m_Root.Q<VisualElement>("parameters-container"); |
|||
|
|||
var filter = m_Root.Q<TextField>("filter-parameters"); |
|||
filter.RegisterValueChangedCallback((e) => { FilterString = e.newValue; }); |
|||
|
|||
var collapseAllButton = m_Root.Q<Button>("collapse-all"); |
|||
collapseAllButton.clicked += () => CollapseParameters(true); |
|||
|
|||
var expandAllButton = m_Root.Q<Button>("expand-all"); |
|||
expandAllButton.clicked += () => CollapseParameters(false); |
|||
|
|||
var parameterTypeMenu = m_Root.Q<ToolbarMenu>("parameter-type-menu"); |
|||
foreach (var parameterType in StaticData.parameterTypes) |
|||
{ |
|||
parameterTypeMenu.menu.AppendAction( |
|||
Parameter.GetDisplayName(parameterType), |
|||
a => { AddParameter(parameterType); }, |
|||
a => DropdownMenuAction.Status.Normal); |
|||
} |
|||
|
|||
RefreshParameterElements(); |
|||
|
|||
return m_Root; |
|||
} |
|||
|
|||
void RefreshParameterElements() |
|||
{ |
|||
m_ParameterContainer.Clear(); |
|||
for (var i = 0; i < config.parameters.Count; i++) |
|||
m_ParameterContainer.Add(CreateParameterElement(i)); |
|||
} |
|||
|
|||
ParameterElement CreateParameterElement(int index) |
|||
{ |
|||
return new ParameterElement(index, this); |
|||
} |
|||
|
|||
void AddParameter(Type parameterType) |
|||
{ |
|||
var parameter = config.AddParameter(parameterType); |
|||
parameter.RandomizeSamplers(); |
|||
|
|||
serializedObject.Update(); |
|||
m_ParameterContainer.Add(CreateParameterElement(config.parameters.Count - 1)); |
|||
} |
|||
|
|||
public void RemoveParameter(VisualElement template) |
|||
{ |
|||
var paramIndex = m_ParameterContainer.IndexOf(template); |
|||
m_ParameterContainer.RemoveAt(paramIndex); |
|||
config.parameters.RemoveAt(paramIndex); |
|||
serializedObject.Update(); |
|||
RefreshParameterElements(); |
|||
} |
|||
|
|||
public void ReorderParameter(int currentIndex, int nextIndex) |
|||
{ |
|||
if (currentIndex == nextIndex) |
|||
return; |
|||
|
|||
if (nextIndex > currentIndex) |
|||
nextIndex--; |
|||
|
|||
var parameterElement = m_ParameterContainer[currentIndex]; |
|||
var parameter = config.parameters[currentIndex]; |
|||
|
|||
parameterElement.RemoveFromHierarchy(); |
|||
config.parameters.RemoveAt(currentIndex); |
|||
|
|||
m_ParameterContainer.Insert(nextIndex, parameterElement); |
|||
config.parameters.Insert(nextIndex, parameter); |
|||
|
|||
serializedObject.Update(); |
|||
|
|||
RefreshParameterElements(); |
|||
} |
|||
|
|||
void CollapseParameters(bool collapsed) |
|||
{ |
|||
foreach (var child in m_ParameterContainer.Children()) |
|||
((ParameterElement)child).Collapsed = collapsed; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: dd62abede5784c84f90495b367408ced |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using UnityEngine.UIElements; |
|||
|
|||
namespace UnityEngine.Perception.Randomization.Editor |
|||
{ |
|||
class ParameterDragBar : VisualElement |
|||
{ |
|||
public ParameterDragBar() |
|||
{ |
|||
AddToClassList("parameter-drag-bar"); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 7c1e08b02e5a4c55875f34baf32f8e76 |
|||
timeCreated: 1596143672 |
|
|||
using UnityEngine.UIElements; |
|||
|
|||
namespace UnityEngine.Perception.Randomization.Editor |
|||
{ |
|||
class ParameterDragManipulator : MouseManipulator |
|||
{ |
|||
bool m_Active; |
|||
float m_Offset; |
|||
ParameterElement m_ParameterElement; |
|||
VisualElement m_DragHandle; |
|||
VisualElement m_DragBar; |
|||
VisualElement m_ParameterContainer; |
|||
|
|||
protected override void RegisterCallbacksOnTarget() |
|||
{ |
|||
m_DragHandle = target.Q<VisualElement>("drag-handle"); |
|||
m_ParameterElement = (ParameterElement)target; |
|||
m_DragHandle.RegisterCallback<MouseDownEvent>(OnMouseDown); |
|||
m_DragHandle.RegisterCallback<MouseMoveEvent>(OnMouseMove); |
|||
m_DragHandle.RegisterCallback<MouseUpEvent>(OnMouseUp); |
|||
} |
|||
|
|||
protected override void UnregisterCallbacksFromTarget() |
|||
{ |
|||
m_DragHandle.UnregisterCallback<MouseDownEvent>(OnMouseDown); |
|||
m_DragHandle.UnregisterCallback<MouseMoveEvent>(OnMouseMove); |
|||
m_DragHandle.UnregisterCallback<MouseUpEvent>(OnMouseUp); |
|||
} |
|||
|
|||
void OnMouseDown(MouseDownEvent evt) |
|||
{ |
|||
if (m_Active) |
|||
{ |
|||
evt.StopImmediatePropagation(); |
|||
return; |
|||
} |
|||
|
|||
if (m_ParameterElement.ConfigEditor.FilterString != string.Empty) |
|||
return; |
|||
|
|||
m_ParameterContainer = target.parent; |
|||
m_DragBar = new ParameterDragBar(); |
|||
m_DragBar.style.width = new StyleLength(m_ParameterContainer.resolvedStyle.width); |
|||
target.parent.Add(m_DragBar); |
|||
|
|||
m_Offset = m_DragHandle.worldBound.position.y - m_ParameterContainer.worldBound.position.y; |
|||
m_DragBar.style.top = evt.localMousePosition.y + m_Offset; |
|||
|
|||
m_Active = true; |
|||
m_DragHandle.CaptureMouse(); |
|||
evt.StopPropagation(); |
|||
} |
|||
|
|||
void OnMouseMove(MouseMoveEvent evt) |
|||
{ |
|||
if (!m_Active || !m_DragHandle.HasMouseCapture()) |
|||
return; |
|||
|
|||
m_DragBar.style.top = evt.localMousePosition.y + m_Offset; |
|||
|
|||
evt.StopPropagation(); |
|||
} |
|||
|
|||
void OnMouseUp(MouseUpEvent evt) |
|||
{ |
|||
if (!m_Active || !m_DragHandle.HasMouseCapture() || !CanStopManipulation(evt)) |
|||
return; |
|||
|
|||
var dragBarY = evt.localMousePosition.y + m_Offset; |
|||
m_DragBar.RemoveFromHierarchy(); |
|||
|
|||
m_Active = false; |
|||
m_DragHandle.ReleaseMouse(); |
|||
evt.StopPropagation(); |
|||
|
|||
var p = 0; |
|||
var middlePoints = new float[m_ParameterContainer.childCount]; |
|||
foreach (var parameterElement in m_ParameterContainer.Children()) |
|||
{ |
|||
var middleHeight = parameterElement.worldBound.height / 2; |
|||
var localY = parameterElement.worldBound.y - m_ParameterContainer.worldBound.position.y; |
|||
middlePoints[p++] = middleHeight + localY; |
|||
} |
|||
|
|||
for (var i = 0; i < middlePoints.Length; i++) |
|||
{ |
|||
if (dragBarY < middlePoints[i]) |
|||
{ |
|||
ReorderParameter(m_ParameterElement.ParameterIndex, i); |
|||
return; |
|||
} |
|||
} |
|||
ReorderParameter(m_ParameterElement.ParameterIndex, middlePoints.Length); |
|||
} |
|||
|
|||
void ReorderParameter(int currentIndex, int nextIndex) |
|||
{ |
|||
m_ParameterElement.ConfigEditor.ReorderParameter(currentIndex, nextIndex); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: f2b59fa8baf440f597257d8eb8219afa |
|||
timeCreated: 1596140810 |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using UnityEditor; |
|||
using UnityEditor.UIElements; |
|||
using UnityEngine.Perception.Randomization.Parameters; |
|||
using UnityEngine.UIElements; |
|||
|
|||
namespace UnityEngine.Perception.Randomization.Editor |
|||
{ |
|||
class ParameterElement : VisualElement |
|||
{ |
|||
int m_ParameterIndex; |
|||
bool m_Filtered; |
|||
VisualElement m_Properties; |
|||
VisualElement m_ExtraProperties; |
|||
VisualElement m_TargetContainer; |
|||
ToolbarMenu m_TargetPropertyMenu; |
|||
SerializedProperty m_SerializedProperty; |
|||
SerializedProperty m_Target; |
|||
SerializedProperty m_TargetGameObject; |
|||
SerializedProperty m_ApplicationFrequency; |
|||
|
|||
const string k_CollapsedParameterClass = "collapsed-parameter"; |
|||
|
|||
public ParameterConfigurationEditor ConfigEditor { get; private set; } |
|||
Parameter parameter => ConfigEditor.config.parameters[m_ParameterIndex]; |
|||
CategoricalParameterBase categoricalParameter => (CategoricalParameterBase)parameter; |
|||
public int ParameterIndex => parent.IndexOf(this); |
|||
|
|||
public bool Collapsed |
|||
{ |
|||
get => parameter.collapsed; |
|||
set |
|||
{ |
|||
parameter.collapsed = value; |
|||
if (value) |
|||
AddToClassList(k_CollapsedParameterClass); |
|||
else |
|||
RemoveFromClassList(k_CollapsedParameterClass); |
|||
} |
|||
} |
|||
|
|||
public bool Filtered |
|||
{ |
|||
get => m_Filtered; |
|||
set |
|||
{ |
|||
m_Filtered = value; |
|||
style.display = value |
|||
? new StyleEnum<DisplayStyle>(DisplayStyle.Flex) |
|||
: new StyleEnum<DisplayStyle>(DisplayStyle.None); |
|||
} |
|||
} |
|||
|
|||
public ParameterElement(int index, ParameterConfigurationEditor paramConfigEditor) |
|||
{ |
|||
ConfigEditor = paramConfigEditor; |
|||
var template = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>( |
|||
$"{StaticData.uxmlDir}/ParameterElement.uxml"); |
|||
template.CloneTree(this); |
|||
|
|||
m_ParameterIndex = index; |
|||
m_SerializedProperty = |
|||
ConfigEditor.serializedObject.FindProperty("parameters").GetArrayElementAtIndex(m_ParameterIndex); |
|||
|
|||
this.AddManipulator(new ParameterDragManipulator()); |
|||
|
|||
Collapsed = parameter.collapsed; |
|||
|
|||
var removeButton = this.Q<Button>("remove-parameter"); |
|||
removeButton.RegisterCallback<MouseUpEvent>(evt => paramConfigEditor.RemoveParameter(this)); |
|||
|
|||
var parameterTypeLabel = this.Query<Label>("parameter-type-label").First(); |
|||
parameterTypeLabel.text = Parameter.GetDisplayName(parameter.GetType()); |
|||
|
|||
var parameterNameField = this.Q<TextField>("name"); |
|||
parameterNameField.isDelayed = true; |
|||
parameterNameField.BindProperty(m_SerializedProperty.FindPropertyRelative("name")); |
|||
|
|||
m_TargetContainer = this.Q<VisualElement>("target-container"); |
|||
m_TargetPropertyMenu = this.Q<ToolbarMenu>("property-select-menu"); |
|||
m_Target = m_SerializedProperty.FindPropertyRelative("target"); |
|||
m_TargetGameObject = m_Target.FindPropertyRelative("gameObject"); |
|||
ToggleTargetContainer(); |
|||
|
|||
var frequencyField = this.Q<EnumField>("application-frequency"); |
|||
frequencyField.Init(ParameterApplicationFrequency.OnIterationSetup); |
|||
m_ApplicationFrequency = m_Target.FindPropertyRelative("applicationFrequency"); |
|||
frequencyField.BindProperty(m_ApplicationFrequency); |
|||
|
|||
var targetField = this.Q<ObjectField>("target"); |
|||
targetField.objectType = typeof(GameObject); |
|||
targetField.value = m_TargetGameObject.objectReferenceValue; |
|||
targetField.RegisterCallback<ChangeEvent<Object>>(evt => |
|||
{ |
|||
ClearTarget(); |
|||
var appFreqEnumIndex = m_ApplicationFrequency.intValue; |
|||
m_TargetGameObject.objectReferenceValue = (GameObject)evt.newValue; |
|||
m_ApplicationFrequency.intValue = appFreqEnumIndex; |
|||
m_SerializedProperty.serializedObject.ApplyModifiedProperties(); |
|||
ToggleTargetContainer(); |
|||
FillPropertySelectMenu(); |
|||
}); |
|||
FillPropertySelectMenu(); |
|||
|
|||
var collapseToggle = this.Q<VisualElement>("collapse"); |
|||
collapseToggle.RegisterCallback<MouseUpEvent>(evt => Collapsed = !Collapsed); |
|||
|
|||
m_ExtraProperties = this.Q<VisualElement>("extra-properties"); |
|||
CreatePropertyFields(); |
|||
} |
|||
|
|||
void ToggleTargetContainer() |
|||
{ |
|||
m_TargetContainer.style.display = m_TargetGameObject.objectReferenceValue == null |
|||
? new StyleEnum<DisplayStyle>(DisplayStyle.None) |
|||
: new StyleEnum<DisplayStyle>(DisplayStyle.Flex); |
|||
} |
|||
|
|||
void ClearTarget() |
|||
{ |
|||
m_Target.FindPropertyRelative("component").objectReferenceValue = null; |
|||
m_Target.FindPropertyRelative("propertyName").stringValue = string.Empty; |
|||
m_SerializedProperty.serializedObject.ApplyModifiedProperties(); |
|||
} |
|||
|
|||
void SetTarget(ParameterTarget newTarget) |
|||
{ |
|||
m_TargetGameObject.objectReferenceValue = newTarget.gameObject; |
|||
m_Target.FindPropertyRelative("component").objectReferenceValue = newTarget.component; |
|||
m_Target.FindPropertyRelative("propertyName").stringValue = newTarget.propertyName; |
|||
m_Target.FindPropertyRelative("fieldOrProperty").intValue = (int)newTarget.fieldOrProperty; |
|||
m_SerializedProperty.serializedObject.ApplyModifiedProperties(); |
|||
m_TargetPropertyMenu.text = TargetPropertyDisplayText(parameter.target); |
|||
} |
|||
|
|||
static string TargetPropertyDisplayText(ParameterTarget target) |
|||
{ |
|||
return $"{target.component.GetType().Name}.{target.propertyName}"; |
|||
} |
|||
|
|||
void FillPropertySelectMenu() |
|||
{ |
|||
if (!parameter.hasTarget) |
|||
return; |
|||
|
|||
m_TargetPropertyMenu.menu.MenuItems().Clear(); |
|||
var options = GatherPropertyOptions(parameter.target.gameObject, parameter.sampleType); |
|||
if (options.Count == 0) |
|||
{ |
|||
m_TargetPropertyMenu.text = "No compatible properties"; |
|||
m_TargetPropertyMenu.SetEnabled(false); |
|||
} |
|||
else |
|||
{ |
|||
m_TargetPropertyMenu.SetEnabled(true); |
|||
foreach (var option in options) |
|||
{ |
|||
m_TargetPropertyMenu.menu.AppendAction( |
|||
TargetPropertyDisplayText(option), |
|||
a => { SetTarget(option); }); |
|||
} |
|||
m_TargetPropertyMenu.text = parameter.target.propertyName == string.Empty |
|||
? "Select a property" |
|||
: TargetPropertyDisplayText(parameter.target); |
|||
} |
|||
} |
|||
|
|||
static List<ParameterTarget> GatherPropertyOptions(GameObject obj, Type propertyType) |
|||
{ |
|||
var options = new List<ParameterTarget>(); |
|||
foreach (var component in obj.GetComponents<Component>()) |
|||
{ |
|||
if (component == null) |
|||
continue; |
|||
var componentType = component.GetType(); |
|||
var fieldInfos = componentType.GetFields(); |
|||
foreach (var fieldInfo in fieldInfos) |
|||
{ |
|||
if (fieldInfo.FieldType == propertyType && fieldInfo.IsPublic && !fieldInfo.IsInitOnly) |
|||
options.Add(new ParameterTarget() |
|||
{ |
|||
gameObject = obj, |
|||
component = component, |
|||
propertyName = fieldInfo.Name, |
|||
fieldOrProperty = FieldOrProperty.Field |
|||
}); |
|||
} |
|||
|
|||
var propertyInfos = componentType.GetProperties(); |
|||
foreach (var propertyInfo in propertyInfos) |
|||
{ |
|||
if (propertyInfo.PropertyType == propertyType && propertyInfo.GetSetMethod() != null) |
|||
options.Add(new ParameterTarget() |
|||
{ |
|||
gameObject = obj, |
|||
component = component, |
|||
propertyName = propertyInfo.Name, |
|||
fieldOrProperty = FieldOrProperty.Property |
|||
}); |
|||
} |
|||
} |
|||
return options; |
|||
} |
|||
|
|||
void CreatePropertyFields() |
|||
{ |
|||
m_ExtraProperties.Clear(); |
|||
|
|||
if (parameter is CategoricalParameterBase) |
|||
{ |
|||
CreateCategoricalParameterFields(); |
|||
return; |
|||
} |
|||
|
|||
var currentProperty = m_SerializedProperty.Copy(); |
|||
var nextSiblingProperty = m_SerializedProperty.Copy(); |
|||
nextSiblingProperty.Next(false); |
|||
|
|||
if (currentProperty.NextVisible(true)) |
|||
{ |
|||
do |
|||
{ |
|||
if (SerializedProperty.EqualContents(currentProperty, nextSiblingProperty)) |
|||
break; |
|||
if (currentProperty.type.Contains("managedReference") && |
|||
currentProperty.managedReferenceFieldTypename == StaticData.samplerSerializedFieldType) |
|||
m_ExtraProperties.Add(new SamplerElement(currentProperty.Copy(), parameter)); |
|||
else |
|||
{ |
|||
var propertyField = new PropertyField(currentProperty.Copy()); |
|||
propertyField.Bind(currentProperty.serializedObject); |
|||
m_ExtraProperties.Add(propertyField); |
|||
} |
|||
} while (currentProperty.NextVisible(false)); |
|||
} |
|||
} |
|||
|
|||
void CreateCategoricalParameterFields() |
|||
{ |
|||
var template = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>( |
|||
$"{StaticData.uxmlDir}/CategoricalParameterTemplate.uxml").CloneTree(); |
|||
|
|||
var optionsProperty = m_SerializedProperty.FindPropertyRelative("m_Categories"); |
|||
var probabilitiesProperty = m_SerializedProperty.FindPropertyRelative("probabilities"); |
|||
var probabilities = categoricalParameter.probabilities; |
|||
|
|||
var listView = template.Q<ListView>("options"); |
|||
listView.itemsSource = probabilities; |
|||
listView.itemHeight = 22; |
|||
listView.selectionType = SelectionType.None; |
|||
listView.style.flexGrow = 1.0f; |
|||
listView.style.height = new StyleLength(listView.itemHeight * 4); |
|||
|
|||
VisualElement MakeItem() => new CategoricalOptionElement( |
|||
optionsProperty, probabilitiesProperty); |
|||
listView.makeItem = MakeItem; |
|||
|
|||
void BindItem(VisualElement e, int i) |
|||
{ |
|||
var optionElement = (CategoricalOptionElement)e; |
|||
optionElement.BindProperties(i); |
|||
var removeButton = optionElement.Q<Button>("remove"); |
|||
removeButton.clicked += () => |
|||
{ |
|||
probabilitiesProperty.DeleteArrayElementAtIndex(i); |
|||
|
|||
// First delete sets option to null, second delete removes option
|
|||
var numOptions = optionsProperty.arraySize; |
|||
optionsProperty.DeleteArrayElementAtIndex(i); |
|||
if (numOptions == optionsProperty.arraySize) |
|||
optionsProperty.DeleteArrayElementAtIndex(i); |
|||
|
|||
m_SerializedProperty.serializedObject.ApplyModifiedProperties(); |
|||
listView.itemsSource = categoricalParameter.probabilities; |
|||
listView.Refresh(); |
|||
}; |
|||
} |
|||
listView.bindItem = BindItem; |
|||
|
|||
var addOptionButton = template.Q<Button>("add-option"); |
|||
addOptionButton.clicked += () => |
|||
{ |
|||
probabilitiesProperty.arraySize++; |
|||
optionsProperty.arraySize++; |
|||
m_SerializedProperty.serializedObject.ApplyModifiedProperties(); |
|||
listView.itemsSource = categoricalParameter.probabilities; |
|||
listView.Refresh(); |
|||
listView.ScrollToItem(probabilitiesProperty.arraySize); |
|||
}; |
|||
|
|||
var addFolderButton = template.Q<Button>("add-folder"); |
|||
if (categoricalParameter.sampleType.IsSubclassOf(typeof(Object))) |
|||
{ |
|||
addFolderButton.clicked += () => |
|||
{ |
|||
var folderPath = EditorUtility.OpenFolderPanel( |
|||
"Add Options From Folder", Application.dataPath, string.Empty); |
|||
if (folderPath == string.Empty) |
|||
return; |
|||
var categories = LoadAssetsFromFolder(folderPath, categoricalParameter.sampleType); |
|||
probabilitiesProperty.arraySize += categories.Count; |
|||
optionsProperty.arraySize += categories.Count; |
|||
var uniformProbability = 1f / categories.Count; |
|||
for (var i = 0; i < categories.Count; i++) |
|||
{ |
|||
var optionProperty = optionsProperty.GetArrayElementAtIndex(i); |
|||
var probabilityProperty = probabilitiesProperty.GetArrayElementAtIndex(i); |
|||
optionProperty.objectReferenceValue = categories[i]; |
|||
probabilityProperty.floatValue = uniformProbability; |
|||
} |
|||
m_SerializedProperty.serializedObject.ApplyModifiedProperties(); |
|||
listView.itemsSource = categoricalParameter.probabilities; |
|||
listView.Refresh(); |
|||
}; |
|||
} |
|||
else |
|||
addFolderButton.style.display = new StyleEnum<DisplayStyle>(DisplayStyle.None); |
|||
|
|||
var clearOptionsButton = template.Q<Button>("clear-options"); |
|||
clearOptionsButton.clicked += () => |
|||
{ |
|||
probabilitiesProperty.arraySize = 0; |
|||
optionsProperty.arraySize = 0; |
|||
m_SerializedProperty.serializedObject.ApplyModifiedProperties(); |
|||
listView.itemsSource = categoricalParameter.probabilities; |
|||
listView.Refresh(); |
|||
}; |
|||
|
|||
var scrollView = listView.Q<ScrollView>(); |
|||
listView.RegisterCallback<WheelEvent>(evt => |
|||
{ |
|||
if (Mathf.Approximately(scrollView.verticalScroller.highValue, 0f)) |
|||
return; |
|||
if ((scrollView.scrollOffset.y <= 0f && evt.delta.y < 0f) || |
|||
scrollView.scrollOffset.y >= scrollView.verticalScroller.highValue && evt.delta.y > 0f) |
|||
evt.StopImmediatePropagation(); |
|||
}); |
|||
|
|||
var uniformToggle = template.Q<Toggle>("uniform"); |
|||
var uniformProperty = m_SerializedProperty.FindPropertyRelative("uniform"); |
|||
uniformToggle.BindProperty(uniformProperty); |
|||
void ToggleProbabilityFields(bool toggle) |
|||
{ |
|||
if (toggle) |
|||
listView.AddToClassList("uniform-probability"); |
|||
else |
|||
listView.RemoveFromClassList("uniform-probability"); |
|||
} |
|||
ToggleProbabilityFields(uniformToggle.value); |
|||
if (Application.isPlaying) |
|||
uniformToggle.SetEnabled(false); |
|||
else |
|||
uniformToggle.RegisterCallback<ChangeEvent<bool>>(evt => ToggleProbabilityFields(evt.newValue)); |
|||
|
|||
var seedField = template.Q<IntegerField>("seed"); |
|||
seedField.BindProperty(m_SerializedProperty.FindPropertyRelative("m_Sampler.<baseSeed>k__BackingField")); |
|||
|
|||
m_ExtraProperties.Add(template); |
|||
} |
|||
|
|||
static List<Object> LoadAssetsFromFolder(string folderPath, Type assetType) |
|||
{ |
|||
if (!folderPath.StartsWith(Application.dataPath)) |
|||
throw new ApplicationException("Selected folder is not an asset folder in this project"); |
|||
var assetsPath = "Assets" + folderPath.Remove(0, Application.dataPath.Length); |
|||
var guids = AssetDatabase.FindAssets($"t:{assetType.Name}", new []{assetsPath}); |
|||
var assets = new List<Object>(); |
|||
foreach (var guid in guids) |
|||
assets.Add(AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(guid), assetType)); |
|||
return assets; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: b5afd2495bca4fdca95b86d9113f27b2 |
|||
timeCreated: 1594059945 |
部分文件因为文件数量过多而无法显示
撰写
预览
正在加载...
取消
保存
Reference in new issue