比较提交

...
此合并请求有变更与目标分支冲突。
/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 次删除
  1. 67
      TestProjects/PerceptionURP/Assets/Scenes/SampleScene.unity
  2. 2
      TestProjects/PerceptionURP/ProjectSettings/QualitySettings.asset
  3. 8
      com.unity.perception/Editor/Randomization.meta
  4. 3
      com.unity.perception/Runtime/Randomization.meta
  5. 11
      com.unity.perception/Editor/Randomization/RandomizerEditor.cs.meta
  6. 114
      com.unity.perception/Editor/Randomization/RandomizerEditor.cs
  7. 3
      com.unity.perception/Runtime/Randomization/Randomizer.cs.meta
  8. 58
      com.unity.perception/Runtime/Randomization/Randomizer.cs

67
TestProjects/PerceptionURP/Assets/Scenes/SampleScene.unity


- {fileID: 1640252283}
- {fileID: 464025709}
- {fileID: 411238281}
- {fileID: 1058419514}
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}

m_Script: {fileID: 11500000, guid: 8b33f0bc2b78db642a758f07826d0dd0, type: 3}
m_Name:
m_EditorClassIdentifier:
classes:
labels:
- Crate
--- !u!65 &411238278
BoxCollider:

m_Script: {fileID: 11500000, guid: 8b33f0bc2b78db642a758f07826d0dd0, type: 3}
m_Name:
m_EditorClassIdentifier:
classes:
labels:
- Cube
--- !u!65 &464025706
BoxCollider:

m_Type: 1
m_Shape: 0
m_Color: {r: 1, g: 0.95686275, b: 0.8392157, a: 1}
m_Intensity: 3.1415927
m_Intensity: 0.84
m_Range: 10
m_SpotAngle: 30
m_InnerSpotAngle: 21.80208

m_RequiresDepthTextureOption: 2
m_RequiresOpaqueTextureOption: 2
m_CameraType: 0
m_CameraOutput: 0
m_Cameras: []
m_RendererIndex: -1
m_VolumeLayerMask:

m_AntialiasingQuality: 2
m_StopNaN: 0
m_Dithering: 0
m_ClearDepth: 1
m_RequiresDepthTexture: 0
m_RequiresColorTexture: 0
m_Version: 2

captureRgbImages: 1
produceSegmentationImages: 1
produceObjectCountAnnotations: 1
objectCountId: 51DA3C27-369D-4929-AEA6-D01614635CE2
produceBoundingBoxAnnotations: 1
boundingBoxId: F9F22E05-443F-4602-A422-EBE4EA9B55CB
produceRenderedObjectInfoMetric: 1
renderedObjectInfoId: 5BA92024-B3B7-41A7-9D3F-C03A6A8DDD01
boundingBoxOrigin: 0
--- !u!1 &1058419513
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1058419514}
- component: {fileID: 1058419515}
m_Layer: 0
m_Name: Randomizer
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &1058419514
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1058419513}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 4662620}
m_RootOrder: 5
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &1058419515
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1058419513}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: e18db86d4c0f4b57b10daa3bac1f2c66, type: 3}
m_Name:
m_EditorClassIdentifier:
randomizationEntries:
- GameObject: {fileID: 705507993}
ComponentType: UnityEngine.Light
MemberName: intensity
TargetKind: 1
Min: 0
Max: 1
--- !u!1 &1640252278
GameObject:
m_ObjectHideFlags: 0

m_Script: {fileID: 11500000, guid: 8b33f0bc2b78db642a758f07826d0dd0, type: 3}
m_Name:
m_EditorClassIdentifier:
classes:
labels:
- Box
--- !u!65 &1640252280
BoxCollider:

2
TestProjects/PerceptionURP/ProjectSettings/QualitySettings.asset


skinWeights: 2
textureQuality: 0
anisotropicTextures: 1
antiAliasing: 2
antiAliasing: 0
softParticles: 0
softVegetation: 1
realtimeReflectionProbes: 1

8
com.unity.perception/Editor/Randomization.meta


fileFormatVersion: 2
guid: 8118d82ac4f24df4ab6f1be4d9175224
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

3
com.unity.perception/Runtime/Randomization.meta


fileFormatVersion: 2
guid: 9f6395dd1591475b81874ea91d6e9f6a
timeCreated: 1589383573

11
com.unity.perception/Editor/Randomization/RandomizerEditor.cs.meta


fileFormatVersion: 2
guid: c3902fbed23a52f4e93c142804bef8e2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

114
com.unity.perception/Editor/Randomization/RandomizerEditor.cs


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;
}
}
}
}
}

3
com.unity.perception/Runtime/Randomization/Randomizer.cs.meta


fileFormatVersion: 2
guid: e18db86d4c0f4b57b10daa3bac1f2c66
timeCreated: 1589383813

58
com.unity.perception/Runtime/Randomization/Randomizer.cs


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;
}
}
正在加载...
取消
保存