比较提交
合并到: 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:dr-test1
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
此合并请求有变更与目标分支冲突。
/TestProjects/PerceptionURP/Assets/Scenes/SampleScene.unity
/com.unity.perception/Editor/Randomization.meta
/com.unity.perception/Editor/Randomization
/com.unity.perception/Runtime/Randomization.meta
/com.unity.perception/Runtime/Randomization
4 次代码提交
作者 | SHA1 | 备注 | 提交日期 |
---|---|---|---|
Jon Hogins | 3bed86dd | Implementing randomization. | 5 年前 |
Jon Hogins | a7e59530 | Adding randomizer | 5 年前 |
Jon Hogins | 459f09dc | Pointing to correct mac image | 5 年前 |
Jon Hogins | eec15714 | Updating artifactory urls | 5 年前 |
共有 10 个文件被更改,包括 260 次插入 和 6 次删除
-
67TestProjects/PerceptionURP/Assets/Scenes/SampleScene.unity
-
2TestProjects/PerceptionURP/ProjectSettings/QualitySettings.asset
-
8com.unity.perception/Editor/Randomization.meta
-
3com.unity.perception/Runtime/Randomization.meta
-
11com.unity.perception/Editor/Randomization/RandomizerEditor.cs.meta
-
114com.unity.perception/Editor/Randomization/RandomizerEditor.cs
-
3com.unity.perception/Runtime/Randomization/Randomizer.cs.meta
-
58com.unity.perception/Runtime/Randomization/Randomizer.cs
|
|||
fileFormatVersion: 2 |
|||
guid: 8118d82ac4f24df4ab6f1be4d9175224 |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 9f6395dd1591475b81874ea91d6e9f6a |
|||
timeCreated: 1589383573 |
|
|||
fileFormatVersion: 2 |
|||
guid: c3902fbed23a52f4e93c142804bef8e2 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using UnityEditor; |
|||
using UnityEngine; |
|||
using UnityEngine.Perception.Randomization; |
|||
|
|||
namespace UnityEditor.Perception.Randomization |
|||
{ |
|||
[CustomEditor(typeof(Randomizer))] |
|||
public class RandomizerEditor : Editor |
|||
{ |
|||
struct RandomizationTarget |
|||
{ |
|||
public GameObject GameObject; |
|||
public Type ComponentType; |
|||
public string FloatFieldName; |
|||
public TargetKind TargetKind; |
|||
} |
|||
public override void OnInspectorGUI() |
|||
{ |
|||
base.OnInspectorGUI(); |
|||
if (EditorGUILayout.DropdownButton(new GUIContent("Add parameter"), FocusType.Keyboard)) |
|||
{ |
|||
var lastRect = GUILayoutUtility.GetLastRect(); |
|||
var dropdownOptions = GatherOptions().ToArray(); |
|||
var menu = new GenericMenu(); |
|||
foreach (var option in dropdownOptions) |
|||
{ |
|||
var localOption = option; |
|||
menu.AddItem(new GUIContent($"{option.GameObject.name}.{option.ComponentType.Name}.{option.FloatFieldName}"), |
|||
false, |
|||
() => AddParameter(localOption)); |
|||
} |
|||
menu.DropDown(lastRect); |
|||
} |
|||
} |
|||
|
|||
void AddParameter(RandomizationTarget localOption) |
|||
{ |
|||
var entriesProp = this.serializedObject.FindProperty(nameof(Randomizer.randomizationEntries)); |
|||
var newIndex = entriesProp.arraySize; |
|||
entriesProp.InsertArrayElementAtIndex(newIndex); |
|||
var element = entriesProp.GetArrayElementAtIndex(newIndex); |
|||
element.FindPropertyRelative(nameof(RandomizationEntry.GameObject)).objectReferenceValue = localOption.GameObject; |
|||
element.FindPropertyRelative(nameof(RandomizationEntry.ComponentType)).stringValue = |
|||
$"{localOption.ComponentType.FullName}, {localOption.ComponentType.Assembly.FullName}"; |
|||
element.FindPropertyRelative(nameof(RandomizationEntry.MemberName)).stringValue = localOption.FloatFieldName; |
|||
var targetKindProp = element.FindPropertyRelative(nameof(RandomizationEntry.TargetKind)); |
|||
targetKindProp.enumValueIndex = (int)localOption.TargetKind; |
|||
element.FindPropertyRelative(nameof(RandomizationEntry.Min)).floatValue = 0f; |
|||
element.FindPropertyRelative(nameof(RandomizationEntry.Max)).floatValue = 1f; |
|||
serializedObject.ApplyModifiedProperties(); |
|||
} |
|||
|
|||
IEnumerable<RandomizationTarget> GatherOptions() |
|||
{ |
|||
var randomizer = (Randomizer)this.target; |
|||
var targetScene = randomizer.gameObject.scene; |
|||
var rootGameObjects = targetScene.GetRootGameObjects(); |
|||
foreach (var rootGameObject in rootGameObjects) |
|||
{ |
|||
foreach (var randomizationTarget in GatherOptions(rootGameObject.transform)) |
|||
{ |
|||
yield return randomizationTarget; |
|||
} |
|||
} |
|||
} |
|||
|
|||
IEnumerable<RandomizationTarget> GatherOptions(Transform parent) |
|||
{ |
|||
foreach (var component in parent.GetComponents<Component>()) |
|||
{ |
|||
if (component == null) |
|||
continue; |
|||
|
|||
var componentType = component.GetType(); |
|||
var fieldInfos = componentType.GetFields(); |
|||
|
|||
foreach (var fieldInfo in fieldInfos) |
|||
{ |
|||
if (fieldInfo.FieldType == typeof(float)) |
|||
yield return new RandomizationTarget() |
|||
{ |
|||
ComponentType = componentType, |
|||
FloatFieldName = fieldInfo.Name, |
|||
TargetKind = TargetKind.Field, |
|||
GameObject = parent.gameObject |
|||
}; |
|||
} |
|||
var propertyInfos = componentType.GetProperties(); |
|||
|
|||
foreach (var propertyInfo in propertyInfos) |
|||
{ |
|||
if (propertyInfo.PropertyType == typeof(float)) |
|||
yield return new RandomizationTarget() |
|||
{ |
|||
ComponentType = componentType, |
|||
FloatFieldName = propertyInfo.Name, |
|||
TargetKind = TargetKind.Property, |
|||
GameObject = parent.gameObject |
|||
}; |
|||
} |
|||
} |
|||
for (int i = 0; i < parent.transform.childCount; i++) |
|||
{ |
|||
foreach (var childOption in GatherOptions(parent.transform.GetChild(i))) |
|||
{ |
|||
yield return childOption; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: e18db86d4c0f4b57b10daa3bac1f2c66 |
|||
timeCreated: 1589383813 |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using Unity.Entities; |
|||
using UnityEngine; |
|||
|
|||
namespace UnityEngine.Perception.Randomization |
|||
{ |
|||
public class Randomizer : MonoBehaviour |
|||
{ |
|||
[SerializeField] |
|||
public List<RandomizationEntry> randomizationEntries = new List<RandomizationEntry>(); |
|||
|
|||
Unity.Mathematics.Random m_Random = new Unity.Mathematics.Random(1); |
|||
|
|||
void Update() |
|||
{ |
|||
foreach (var randomizationEntry in randomizationEntries) |
|||
{ |
|||
Randomize(randomizationEntry); |
|||
} |
|||
} |
|||
|
|||
void Randomize(RandomizationEntry randomizationEntry) |
|||
{ |
|||
var value = m_Random.NextFloat(randomizationEntry.Min, randomizationEntry.Max); |
|||
var type = Type.GetType(randomizationEntry.ComponentType); |
|||
var component = randomizationEntry.GameObject.GetComponent(type); |
|||
switch (randomizationEntry.TargetKind) |
|||
{ |
|||
case TargetKind.Field: |
|||
var fieldInfo = type.GetField(randomizationEntry.MemberName); |
|||
fieldInfo.SetValue(component, value); |
|||
break; |
|||
case TargetKind.Property: |
|||
var propertyInfo = type.GetProperty(randomizationEntry.MemberName); |
|||
propertyInfo.SetValue(component, value); |
|||
break; |
|||
} |
|||
} |
|||
} |
|||
|
|||
public enum TargetKind |
|||
{ |
|||
Field, |
|||
Property |
|||
} |
|||
|
|||
[Serializable] |
|||
public class RandomizationEntry |
|||
{ |
|||
public GameObject GameObject; |
|||
public string ComponentType; |
|||
public string MemberName; |
|||
public TargetKind TargetKind; |
|||
public float Min; |
|||
public float Max; |
|||
} |
|||
} |
撰写
预览
正在加载...
取消
保存
Reference in new issue