Steven Leal
4 年前
当前提交
0c713aff
共有 83 个文件被更改,包括 1355 次插入 和 769 次删除
-
49com.unity.perception/Editor/Randomization/StaticData.cs
-
2com.unity.perception/Editor/Randomization/Uxml/CategoricalOptionElement.uxml
-
2com.unity.perception/Editor/Randomization/Uxml/ParameterConfiguration.uxml
-
33com.unity.perception/Editor/Randomization/Uxml/ParameterElement.uxml
-
1com.unity.perception/Editor/Randomization/Uxml/SamplerElement.uxml
-
48com.unity.perception/Runtime/Randomization/Configuration/ParameterConfiguration.cs
-
14com.unity.perception/Runtime/Randomization/Parameters/CategoricalParameter.cs
-
13com.unity.perception/Runtime/Randomization/Parameters/NumericParameter.cs
-
44com.unity.perception/Runtime/Randomization/Parameters/Parameter.cs
-
14com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/BooleanParameter.cs
-
109com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/ColorHsvaParameter.cs
-
2com.unity.perception/Runtime/Randomization/Samplers/SamplerUtility.cs
-
5com.unity.perception/Runtime/Randomization/Scenarios/FixedLengthScenario.cs
-
53com.unity.perception/Runtime/Randomization/Scenarios/ScenarioBase.cs
-
10com.unity.perception/Tests/Runtime/Randomization/ParameterConfigurationTests.cs
-
10com.unity.perception/Tests/Runtime/Randomization/ScenarioTests.cs
-
22com.unity.perception/Editor/Randomization/Editors/ParameterConfigurationEditor.cs
-
10com.unity.perception/Editor/Randomization/VisualElements/ParameterDragManipulator.cs
-
11com.unity.perception/Runtime/Randomization/Configuration/ParameterTarget.cs
-
3com.unity.perception/Editor/Randomization/Editors.meta
-
3com.unity.perception/Editor/Randomization/PropertyDrawers.meta
-
81com.unity.perception/Editor/Randomization/Uss/ParameterConfigurationStyles.uss
-
110com.unity.perception/Editor/Randomization/Uss/ParameterStyles.uss
-
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
-
31com.unity.perception/Editor/Randomization/Uxml/ConfiguredParameterElement.uxml
-
3com.unity.perception/Editor/Randomization/Uxml/ConfiguredParameterElement.uxml.meta
-
10com.unity.perception/Editor/Randomization/Uxml/ParameterDrawer.uxml
-
3com.unity.perception/Editor/Randomization/Uxml/ParameterDrawer.uxml.meta
-
3com.unity.perception/Editor/Randomization/VisualElements.meta
-
22com.unity.perception/Runtime/Randomization/Configuration/ConfiguredParameter.cs
-
3com.unity.perception/Runtime/Randomization/Configuration/ConfiguredParameter.cs.meta
-
3com.unity.perception/Runtime/Randomization/ParameterBehaviours.meta
-
7com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/ColorHsvaCategoricalParameter.cs
-
3com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/ColorHsvaCategoricalParameter.cs.meta
-
7com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/ColorRgbCategoricalParameter.cs
-
3com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/ColorRgbCategoricalParameter.cs.meta
-
111com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/ColorRgbParameter.cs
-
3com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/ColorRgbParameter.cs.meta
-
30com.unity.perception/Editor/Randomization/Editors/ParameterBehaviourEditor.cs
-
3com.unity.perception/Editor/Randomization/Editors/ParameterBehaviourEditor.cs.meta
-
25com.unity.perception/Editor/Randomization/PropertyDrawers/ColorHsvaDrawer.cs
-
3com.unity.perception/Editor/Randomization/PropertyDrawers/ColorHsvaDrawer.cs.meta
-
26com.unity.perception/Editor/Randomization/PropertyDrawers/ParameterDrawer.cs
-
3com.unity.perception/Editor/Randomization/PropertyDrawers/ParameterDrawer.cs.meta
-
39com.unity.perception/Editor/Randomization/VisualElements/ColorHsvaField.cs
-
3com.unity.perception/Editor/Randomization/VisualElements/ColorHsvaField.cs.meta
-
212com.unity.perception/Editor/Randomization/VisualElements/ConfiguredParameterElement.cs
-
3com.unity.perception/Editor/Randomization/VisualElements/ConfiguredParameterElement.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
-
51com.unity.perception/Runtime/Randomization/ParameterBehaviours/ParameterBehaviour.cs
-
3com.unity.perception/Runtime/Randomization/ParameterBehaviours/ParameterBehaviour.cs.meta
-
213com.unity.perception/Editor/Randomization/Uss/Styles.uss
-
6com.unity.perception/Editor/Randomization/Uxml/ParameterDrawerElement.uxml
-
3com.unity.perception/Editor/Randomization/Uxml/ParameterDrawerElement.uxml.meta
-
374com.unity.perception/Editor/Randomization/ParameterElement.cs
-
0/com.unity.perception/Editor/Randomization/Uss/ParameterConfigurationStyles.uss.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/Editors/ParameterConfigurationEditor.cs
-
0/com.unity.perception/Editor/Randomization/Editors/ParameterConfigurationEditor.cs.meta
-
0/com.unity.perception/Editor/Randomization/VisualElements/ParameterDragBar.cs
-
0/com.unity.perception/Editor/Randomization/VisualElements/ParameterDragBar.cs.meta
-
0/com.unity.perception/Editor/Randomization/VisualElements/ParameterDragManipulator.cs
-
0/com.unity.perception/Editor/Randomization/VisualElements/ParameterDragManipulator.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
-
0/com.unity.perception/Editor/Randomization/Editors/ScenarioBaseEditor.cs.meta
-
0/com.unity.perception/Runtime/Randomization/Configuration/ParameterTarget.cs
-
0/com.unity.perception/Runtime/Randomization/Configuration/ParameterTarget.cs.meta
|
|||
<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 |
|||
guid: 0b17046409af4c22bf74eec2a5965984 |
|||
timeCreated: 1598135707 |
|
|||
fileFormatVersion: 2 |
|||
guid: d3107e026b2943c1868c9b3f8c6480d3 |
|||
timeCreated: 1598135730 |
|
|||
.dark-viewport { |
|||
border-radius: 5px; |
|||
background-color: #191919; |
|||
padding: 2px; |
|||
} |
|||
|
|||
.unity-toggle { |
|||
margin-left: 0; |
|||
} |
|||
|
|||
.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"); |
|||
} |
|||
|
|||
.parameter-drag-bar { |
|||
width: 100px; |
|||
height: 6px; |
|||
background-color: rgba(100,149,237,0.4); |
|||
position: absolute; |
|||
} |
|||
|
|||
.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; |
|||
} |
|
|||
.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; |
|||
/*min-width: 120px;*/ |
|||
-unity-text-align: middle-left; |
|||
} |
|||
|
|||
.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"); |
|||
} |
|
|||
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 |
|
|||
<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"/> |
|||
<TextField name="name" text="Parameter Name"/> |
|||
</Box> |
|||
<Button name="remove-parameter" class="remove-parameter-button"/> |
|||
</VisualElement> |
|||
|
|||
<VisualElement name="properties" class="parameter-properties-container"> |
|||
<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> |
|||
</VisualElement> |
|||
</VisualElement> |
|||
</Box> |
|||
</UXML> |
|
|||
fileFormatVersion: 2 |
|||
guid: bb5d8b14dfb1488388860c0437274b7c |
|||
timeCreated: 1598232124 |
|
|||
<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: 7f8f95a1bb144a96b9310164f5560387 |
|||
timeCreated: 1598135666 |
|
|||
using System; |
|||
using UnityEngine.Perception.Randomization.Parameters; |
|||
|
|||
namespace UnityEngine.Perception.Randomization.Configuration |
|||
{ |
|||
[Serializable] |
|||
class ConfiguredParameter |
|||
{ |
|||
public string name = "Parameter"; |
|||
[SerializeReference] public Parameter parameter; |
|||
[HideInInspector, SerializeField] public ParameterTarget target = new ParameterTarget(); |
|||
|
|||
public bool hasTarget => target.gameObject != null; |
|||
|
|||
public void ApplyToTarget() |
|||
{ |
|||
if (!hasTarget) |
|||
return; |
|||
target.ApplyValueToTarget(parameter.GenericSample()); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: b922e785add647cd876af9a755bbddf5 |
|||
timeCreated: 1598227279 |
|
|||
fileFormatVersion: 2 |
|||
guid: 2dd2a5a912ed49ab8356572e5ca6d950 |
|||
timeCreated: 1598132657 |
|
|||
using System; |
|||
|
|||
namespace UnityEngine.Perception.Randomization.Parameters |
|||
{ |
|||
[Serializable] |
|||
public class ColorHsvaCategoricalParameter : CategoricalParameter<ColorHsva> { } |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: e7985c4ea0bf49578e9cabd2c1a63cb6 |
|||
timeCreated: 1598217458 |
|
|||
using System; |
|||
|
|||
namespace UnityEngine.Perception.Randomization.Parameters |
|||
{ |
|||
[Serializable] |
|||
public class ColorRgbCategoricalParameter : CategoricalParameter<Color> { } |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: f4bd575c48a145ec9b63eb48ce636ed7 |
|||
timeCreated: 1598251957 |
|
|||
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 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: a4fdf61227254683a9950f586d6e8f57 |
|||
timeCreated: 1598252064 |
|
|||
using System; |
|||
using Randomization.ParameterBehaviours; |
|||
using UnityEditor; |
|||
using UnityEditor.UIElements; |
|||
using UnityEngine.UIElements; |
|||
|
|||
namespace UnityEngine.Perception.Randomization.Editor |
|||
{ |
|||
[CustomEditor(typeof(ParameterBehaviour), true)] |
|||
public class ParameterBehaviourEditor : UnityEditor.Editor |
|||
{ |
|||
public override VisualElement CreateInspectorGUI() |
|||
{ |
|||
var root = new VisualElement(); |
|||
var iterator = serializedObject.GetIterator(); |
|||
|
|||
// Start iterating over properties
|
|||
iterator.NextVisible(true); |
|||
|
|||
// Skip m_Script property
|
|||
iterator.NextVisible(false); |
|||
|
|||
// Create property fields
|
|||
do { root.Add(new PropertyField(iterator.Copy())); } |
|||
while (iterator.NextVisible(false)); |
|||
|
|||
return root; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 305a421aca744ce49ced7056c1733f48 |
|||
timeCreated: 1598220645 |
|
|||
using UnityEditor; |
|||
using UnityEngine.Perception.Randomization.Parameters; |
|||
using UnityEngine.UIElements; |
|||
|
|||
namespace UnityEngine.Perception.Randomization.Editor.PropertyDrawers |
|||
{ |
|||
[CustomPropertyDrawer(typeof(ColorHsva), true)] |
|||
public 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); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 5e8094c28dd142a09fbbd38ca560164b |
|||
timeCreated: 1598250942 |
|
|||
using System; |
|||
using UnityEditor; |
|||
using UnityEngine.Perception.Randomization.Parameters; |
|||
using UnityEngine.UIElements; |
|||
|
|||
namespace UnityEngine.Perception.Randomization.Editor.PropertyDrawers |
|||
{ |
|||
[CustomPropertyDrawer(typeof(Parameter), true)] |
|||
public 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); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: d389620d3aa3471ca1877eb59cdfb465 |
|||
timeCreated: 1598135745 |
|
|||
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 System; |
|||
using System.Collections.Generic; |
|||
using UnityEditor; |
|||
using UnityEditor.UIElements; |
|||
using UnityEngine.Perception.Randomization.Configuration; |
|||
using UnityEngine.Perception.Randomization.Parameters; |
|||
using UnityEngine.UIElements; |
|||
|
|||
namespace UnityEngine.Perception.Randomization.Editor |
|||
{ |
|||
class ConfiguredParameterElement : VisualElement |
|||
{ |
|||
bool m_Filtered; |
|||
Type m_ParameterSampleType; |
|||
|
|||
VisualElement m_Properties; |
|||
VisualElement m_TargetContainer; |
|||
ToolbarMenu m_TargetPropertyMenu; |
|||
SerializedProperty m_SerializedProperty; |
|||
SerializedProperty m_Collapsed; |
|||
SerializedProperty m_Target; |
|||
SerializedProperty m_TargetGameObject; |
|||
SerializedProperty m_TargetComponent; |
|||
SerializedProperty m_TargetProperty; |
|||
|
|||
const string k_CollapsedParameterClass = "collapsed-parameter"; |
|||
|
|||
public ParameterConfigurationEditor configEditor { get; private set; } |
|||
|
|||
public int ParameterIndex => parent.IndexOf(this); |
|||
|
|||
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 bool filtered |
|||
{ |
|||
get => m_Filtered; |
|||
set |
|||
{ |
|||
m_Filtered = value; |
|||
style.display = value |
|||
? new StyleEnum<DisplayStyle>(DisplayStyle.Flex) |
|||
: new StyleEnum<DisplayStyle>(DisplayStyle.None); |
|||
} |
|||
} |
|||
|
|||
public ConfiguredParameterElement(SerializedProperty property, ParameterConfigurationEditor config) |
|||
{ |
|||
configEditor = config; |
|||
var template = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>( |
|||
$"{StaticData.uxmlDir}/ConfiguredParameterElement.uxml"); |
|||
template.CloneTree(this); |
|||
|
|||
m_SerializedProperty = property; |
|||
var parameterProperty = m_SerializedProperty.FindPropertyRelative("parameter"); |
|||
var parameter = (Parameter)StaticData.GetManagedReferenceValue(parameterProperty); |
|||
m_ParameterSampleType = parameter.sampleType; |
|||
m_Collapsed = parameterProperty.FindPropertyRelative("collapsed"); |
|||
m_Target = m_SerializedProperty.FindPropertyRelative("target"); |
|||
m_TargetGameObject = m_Target.FindPropertyRelative("gameObject"); |
|||
m_TargetComponent = m_Target.FindPropertyRelative("component"); |
|||
m_TargetProperty = m_Target.FindPropertyRelative("property"); |
|||
|
|||
this.AddManipulator(new ParameterDragManipulator()); |
|||
|
|||
var removeButton = this.Q<Button>("remove-parameter"); |
|||
removeButton.RegisterCallback<MouseUpEvent>(evt => configEditor.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"); |
|||
|
|||
ToggleTargetContainer(); |
|||
|
|||
var frequencyField = this.Q<EnumField>("application-frequency"); |
|||
frequencyField.Init(ParameterApplicationFrequency.OnIterationSetup); |
|||
var applicationFrequency = m_Target.FindPropertyRelative("applicationFrequency"); |
|||
frequencyField.BindProperty(applicationFrequency); |
|||
|
|||
var targetField = this.Q<ObjectField>("target"); |
|||
targetField.objectType = typeof(GameObject); |
|||
targetField.value = m_TargetGameObject.objectReferenceValue; |
|||
targetField.RegisterCallback<ChangeEvent<Object>>(evt => |
|||
{ |
|||
ClearTarget(); |
|||
var appFreqEnumIndex = applicationFrequency.intValue; |
|||
m_TargetGameObject.objectReferenceValue = (GameObject)evt.newValue; |
|||
applicationFrequency.intValue = appFreqEnumIndex; |
|||
m_SerializedProperty.serializedObject.ApplyModifiedProperties(); |
|||
ToggleTargetContainer(); |
|||
FillPropertySelectMenu(); |
|||
}); |
|||
FillPropertySelectMenu(); |
|||
|
|||
var collapseToggle = this.Q<VisualElement>("collapse"); |
|||
collapseToggle.RegisterCallback<MouseUpEvent>(evt => collapsed = !collapsed); |
|||
|
|||
var parameterProperties = this.Q<VisualElement>("properties"); |
|||
parameterProperties.Add(new ParameterElement(m_SerializedProperty.FindPropertyRelative("parameter"))); |
|||
} |
|||
|
|||
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(newTarget.component, newTarget.propertyName); |
|||
} |
|||
|
|||
static string TargetPropertyDisplayText(Component component, string propertyName) |
|||
{ |
|||
return $"{component.GetType().Name}.{propertyName}"; |
|||
} |
|||
|
|||
void FillPropertySelectMenu() |
|||
{ |
|||
if (m_TargetGameObject.objectReferenceValue == null) |
|||
return; |
|||
|
|||
m_TargetPropertyMenu.menu.MenuItems().Clear(); |
|||
var options = GatherPropertyOptions((GameObject)m_TargetGameObject.objectReferenceValue, m_ParameterSampleType); |
|||
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.component, option.propertyName), |
|||
a => { SetTarget(option); }); |
|||
} |
|||
m_TargetPropertyMenu.text = m_TargetProperty.stringValue == string.Empty |
|||
? "Select a property" |
|||
: TargetPropertyDisplayText((Component)m_TargetComponent.objectReferenceValue, m_TargetProperty.stringValue); |
|||
} |
|||
} |
|||
|
|||
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; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: a26a70e27aed4ced88ef9ac7e17c2793 |
|||
timeCreated: 1598228666 |
|
|||
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; |
|||
} |
|||
} |
|||
} |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
using UnityEngine.Perception.Randomization.Parameters; |
|||
using UnityEngine.Perception.Randomization.Samplers; |
|||
|
|||
namespace Randomization.ParameterBehaviours |
|||
{ |
|||
public abstract class ParameterBehaviour : MonoBehaviour |
|||
{ |
|||
internal static HashSet<ParameterBehaviour> activeBehaviours = new HashSet<ParameterBehaviour>(); |
|||
|
|||
public abstract IEnumerable<Parameter> parameters { get; } |
|||
|
|||
void Awake() |
|||
{ |
|||
activeBehaviours.Add(this); |
|||
OnInitialize(); |
|||
} |
|||
|
|||
void OnDestroy() |
|||
{ |
|||
activeBehaviours.Remove(this); |
|||
} |
|||
|
|||
protected virtual void OnInitialize() { } |
|||
|
|||
public virtual void OnFrameStart() { } |
|||
|
|||
public virtual void OnIterationStart() { } |
|||
|
|||
public virtual void OnIterationEnd() { } |
|||
|
|||
public virtual void OnScenarioComplete() {} |
|||
|
|||
public virtual void Validate() { } |
|||
|
|||
internal void ResetState(int scenarioIteration) |
|||
{ |
|||
foreach (var parameter in parameters) |
|||
parameter.ResetState(scenarioIteration); |
|||
} |
|||
|
|||
public virtual void Reset() |
|||
{ |
|||
foreach (var parameter in parameters) |
|||
foreach (var sampler in parameter.samplers) |
|||
sampler.baseSeed = SamplerUtility.GenerateRandomSeed(); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: bb8689894f7f41d180c308dbe85f3ced |
|||
timeCreated: 1598132668 |
|
|||
.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="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 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; |
|||
} |
|||
} |
|||
} |
撰写
预览
正在加载...
取消
保存
Reference in new issue