Added Randomizers and RandomizerTags
This commit is contained in:
Родитель
4e70bb0d23
Коммит
964300eae5
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 2c0b9128211c487091d21926e24c3303
|
||||
timeCreated: 1600211324
|
|
@ -1,3 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 3066f77d411047baafb6cc454adc6e37
|
||||
timeCreated: 1595535184
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
<<<<<<< HEAD
|
||||
guid: 85401640505a48f9a8fe55045f5f28d8
|
||||
timeCreated: 1600754567
|
||||
=======
|
||||
guid: 0b17046409af4c22bf74eec2a5965984
|
||||
timeCreated: 1598135707
|
||||
>>>>>>> 86d25d2... implemented parameter behaviours
|
|
@ -1,6 +1,7 @@
|
|||
using UnityEditor;
|
||||
using UnityEditor.UIElements;
|
||||
using UnityEngine.Experimental.Perception.Randomization.Scenarios;
|
||||
using UnityEngine.Experimental.Perception.Randomization.VisualElements;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace UnityEngine.Experimental.Perception.Randomization.Editor
|
||||
|
@ -13,6 +14,7 @@ namespace UnityEngine.Experimental.Perception.Randomization.Editor
|
|||
VisualElement m_Root;
|
||||
VisualElement m_InspectorPropertiesContainer;
|
||||
VisualElement m_ConstantsContainer;
|
||||
VisualElement m_RandomizerListPlaceholder;
|
||||
SerializedProperty m_ConstantsProperty;
|
||||
|
||||
public override VisualElement CreateInspectorGUI()
|
||||
|
@ -21,15 +23,18 @@ namespace UnityEngine.Experimental.Perception.Randomization.Editor
|
|||
m_SerializedObject = new SerializedObject(m_Scenario);
|
||||
m_Root = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(
|
||||
$"{StaticData.uxmlDir}/ScenarioBaseElement.uxml").CloneTree();
|
||||
CreatePropertyFields();
|
||||
CheckIfConstantsExist();
|
||||
|
||||
var serializeConstantsButton = m_Root.Query<Button>("serialize-constants").First();
|
||||
var serializeConstantsButton = m_Root.Q<Button>("serialize-constants");
|
||||
serializeConstantsButton.clicked += () => m_Scenario.Serialize();
|
||||
|
||||
var deserializeConstantsButton = m_Root.Query<Button>("deserialize-constants").First();
|
||||
var deserializeConstantsButton = m_Root.Q<Button>("deserialize-constants");
|
||||
deserializeConstantsButton.clicked += () => m_Scenario.Deserialize();
|
||||
|
||||
m_RandomizerListPlaceholder = m_Root.Q<VisualElement>("randomizer-list-placeholder");
|
||||
|
||||
CreatePropertyFields();
|
||||
CheckIfConstantsExist();
|
||||
|
||||
return m_Root;
|
||||
}
|
||||
|
||||
|
@ -44,20 +49,24 @@ namespace UnityEngine.Experimental.Perception.Randomization.Editor
|
|||
{
|
||||
do
|
||||
{
|
||||
if (iterator.name == "m_Script")
|
||||
switch (iterator.name)
|
||||
{
|
||||
// Skip this property
|
||||
}
|
||||
else if (iterator.name == "constants")
|
||||
{
|
||||
m_ConstantsProperty = iterator.Copy();
|
||||
}
|
||||
else
|
||||
{
|
||||
foundProperties = true;
|
||||
var propertyField = new PropertyField(iterator.Copy());
|
||||
propertyField.Bind(m_SerializedObject);
|
||||
m_InspectorPropertiesContainer.Add(propertyField);
|
||||
case "m_Script":
|
||||
break;
|
||||
case "constants":
|
||||
m_ConstantsProperty = iterator.Copy();
|
||||
break;
|
||||
case "m_Randomizers":
|
||||
m_RandomizerListPlaceholder.Add(new RandomizerList(iterator.Copy()));
|
||||
break;
|
||||
default:
|
||||
{
|
||||
foundProperties = true;
|
||||
var propertyField = new PropertyField(iterator.Copy());
|
||||
propertyField.Bind(m_SerializedObject);
|
||||
m_InspectorPropertiesContainer.Add(propertyField);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} while (iterator.NextVisible(false));
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
<<<<<<< HEAD
|
||||
guid: 57a29c3831024d55aca1a6267dabb56c
|
||||
timeCreated: 1600754583
|
||||
=======
|
||||
guid: face5e97e23d402cbf6fafadb39fa0c3
|
||||
timeCreated: 1596213301
|
||||
>>>>>>> 86d25d2... implemented parameter behaviours
|
|
@ -1,3 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: e37f169c618d471d8ed9614a41096437
|
||||
timeCreated: 1595281335
|
|
@ -1,125 +0,0 @@
|
|||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using UnityEditor.UIElements;
|
||||
using UnityEngine.Experimental.Perception.Randomization.Configuration;
|
||||
using UnityEngine.Experimental.Perception.Randomization.Parameters;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace UnityEngine.Experimental.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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: dd62abede5784c84f90495b367408ced
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -1,3 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 7c1e08b02e5a4c55875f34baf32f8e76
|
||||
timeCreated: 1596143672
|
|
@ -1,3 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: f2b59fa8baf440f597257d8eb8219afa
|
||||
timeCreated: 1596140810
|
|
@ -1,374 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEditor.UIElements;
|
||||
using UnityEngine.Experimental.Perception.Randomization.Parameters;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace UnityEngine.Experimental.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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,3 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: ea72d77c64d1447aa195e2068f02cf74
|
||||
timeCreated: 1595279847
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
<<<<<<< HEAD
|
||||
guid: 47a26876f92a4b19adb3b7b525efa830
|
||||
timeCreated: 1600754588
|
||||
=======
|
||||
guid: d3107e026b2943c1868c9b3f8c6480d3
|
||||
timeCreated: 1598135730
|
||||
>>>>>>> 86d25d2... implemented parameter behaviours
|
|
@ -0,0 +1,25 @@
|
|||
using UnityEditor;
|
||||
using UnityEngine.Experimental.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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
<<<<<<< HEAD
|
||||
guid: e2ea91ddb1134cc6a14d2e3859a275f5
|
||||
timeCreated: 1600754588
|
||||
=======
|
||||
guid: 5e8094c28dd142a09fbbd38ca560164b
|
||||
timeCreated: 1598250942
|
||||
>>>>>>> 86d25d2... implemented parameter behaviours
|
|
@ -0,0 +1,26 @@
|
|||
using System;
|
||||
using UnityEditor;
|
||||
using UnityEngine.Experimental.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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
<<<<<<< HEAD
|
||||
guid: e396dea59a4843529416020c3d0ef5af
|
||||
timeCreated: 1600754588
|
||||
=======
|
||||
guid: d389620d3aa3471ca1877eb59cdfb465
|
||||
timeCreated: 1598135745
|
||||
>>>>>>> 86d25d2... implemented parameter behaviours
|
|
@ -1,3 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: b4fa54f5ed5d4d67a278fa8b42dc55cb
|
||||
timeCreated: 1596171029
|
|
@ -1,3 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: b367f8f2cb8e465ca2d60ccbd5414a14
|
||||
timeCreated: 1595277943
|
|
@ -1,3 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: face5e97e23d402cbf6fafadb39fa0c3
|
||||
timeCreated: 1596213301
|
|
@ -1,7 +1,11 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using UnityEditor;
|
||||
using UnityEngine.Experimental.Perception.Randomization.Parameters;
|
||||
using UnityEngine.Experimental.Perception.Randomization.Randomizers;
|
||||
using UnityEngine.Experimental.Perception.Randomization.Samplers;
|
||||
|
||||
namespace UnityEngine.Experimental.Perception.Randomization.Editor
|
||||
|
@ -14,11 +18,13 @@ namespace UnityEngine.Experimental.Perception.Randomization.Editor
|
|||
internal static readonly string samplerSerializedFieldType;
|
||||
|
||||
internal static Type[] parameterTypes;
|
||||
internal static Type[] randomizerTypes;
|
||||
internal static Type[] samplerTypes;
|
||||
|
||||
static StaticData()
|
||||
{
|
||||
parameterTypes = GetConstructableDerivedTypes<Parameter>();
|
||||
randomizerTypes = GetConstructableDerivedTypes<Randomizer>();
|
||||
samplerTypes = GetConstructableDerivedTypes<ISampler>();
|
||||
var samplerType = typeof(ISampler);
|
||||
samplerSerializedFieldType = $"{samplerType.Assembly.GetName().Name} {samplerType.FullName}";
|
||||
|
@ -35,5 +41,52 @@ namespace UnityEngine.Experimental.Perception.Randomization.Editor
|
|||
}
|
||||
return types.ToArray();
|
||||
}
|
||||
|
||||
internal static object GetManagedReferenceValue(SerializedProperty prop, bool parent=false)
|
||||
{
|
||||
var path = prop.propertyPath.Replace(".Array.data[", "[");
|
||||
object obj = prop.serializedObject.targetObject;
|
||||
var elements = path.Split('.');
|
||||
if (parent)
|
||||
elements = elements.Take(elements.Count() - 1).ToArray();
|
||||
|
||||
foreach (var element in elements)
|
||||
{
|
||||
if (element.Contains("["))
|
||||
{
|
||||
var elementName = element.Substring(0, element.IndexOf("["));
|
||||
var index = Convert.ToInt32(element.Substring(element.IndexOf("[")).Replace("[","").Replace("]",""));
|
||||
obj = GetArrayValue(obj, elementName, index);
|
||||
}
|
||||
else
|
||||
obj = GetValue(obj, element);
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
static object GetValue(object source, string name)
|
||||
{
|
||||
if (source == null)
|
||||
return null;
|
||||
var type = source.GetType();
|
||||
var f = type.GetField(name, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
|
||||
if (f == null)
|
||||
{
|
||||
var p = type.GetProperty(name, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.IgnoreCase);
|
||||
return p == null ? null : p.GetValue(source, null);
|
||||
}
|
||||
return f.GetValue(source);
|
||||
}
|
||||
|
||||
static object GetArrayValue(object source, string name, int index)
|
||||
{
|
||||
var value = GetValue(source, name);
|
||||
if (!(value is IEnumerable enumerable))
|
||||
return null;
|
||||
var enumerator = enumerable.GetEnumerator();
|
||||
while (index-- >= 0)
|
||||
enumerator.MoveNext();
|
||||
return enumerator.Current;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,109 @@
|
|||
.randomizer-element {
|
||||
border-width: 2px;
|
||||
border-radius: 5px;
|
||||
margin: 2px 1px;
|
||||
background-color: #383838;
|
||||
}
|
||||
|
||||
.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;
|
||||
}
|
||||
|
||||
.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-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 .collapse-toggle {
|
||||
background-image: resource("Packages/com.unity.perception/Editor/Randomization/Icons/FoldoutClosed.png");
|
||||
}
|
||||
|
||||
.collapsed .properties-container {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.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");
|
||||
}
|
||||
|
||||
.drag-handle {
|
||||
flex-shrink: 0;
|
||||
width: 16px;
|
||||
height: 100%;
|
||||
min-height: 20px;
|
||||
background-image: resource("Packages/com.unity.perception/Editor/Randomization/Icons/DragHandle.png");
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
<<<<<<< HEAD
|
||||
guid: 0a4e5cce05674cabb4e35dbba3176bb0
|
||||
timeCreated: 1600754588
|
||||
=======
|
||||
guid: def81fa16f8b41aca393a30c3b1fac72
|
||||
timeCreated: 1598222679
|
||||
>>>>>>> 86d25d2... implemented parameter behaviours
|
|
@ -0,0 +1,16 @@
|
|||
.sampler-type-menu {
|
||||
flex-grow: 1.5;
|
||||
border-radius: 3px;
|
||||
border-width: 1px;
|
||||
margin-top: 2px;
|
||||
margin-right: 3px;
|
||||
}
|
||||
|
||||
.sampler-name {
|
||||
/*color: lightgreen;*/
|
||||
}
|
||||
|
||||
.float-range .unity-base-field__label {
|
||||
min-width: auto;
|
||||
margin-right: 4px;
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
<<<<<<< HEAD
|
||||
guid: f96184638ee64ea18b5e2d5c90f94c67
|
||||
timeCreated: 1600754588
|
||||
=======
|
||||
guid: 85ff041b142f41798a7703bda9bb1ba7
|
||||
timeCreated: 1598222791
|
||||
>>>>>>> 86d25d2... implemented parameter behaviours
|
|
@ -0,0 +1,21 @@
|
|||
.dark-viewport {
|
||||
border-radius: 5px;
|
||||
background-color: #191919;
|
||||
padding: 2px;
|
||||
}
|
||||
|
||||
.info-box {
|
||||
border-width: 1px;
|
||||
border-color: #191919;
|
||||
padding: 2px 4px 2px 4px;
|
||||
white-space: normal;
|
||||
margin-top: 4px;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.drag-bar {
|
||||
width: 100px;
|
||||
height: 6px;
|
||||
background-color: rgba(100,149,237,0.4);
|
||||
position: absolute;
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 7db846b4c7cf420e8fdc32c7f701f5c3
|
||||
timeCreated: 1600276536
|
|
@ -1,213 +0,0 @@
|
|||
.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;
|
||||
}
|
|
@ -1,3 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 5e1a10e7ee7a46898d0138a9d08615ee
|
||||
timeCreated: 1589577216
|
|
@ -1,5 +1,5 @@
|
|||
<UXML xmlns="UnityEngine.UIElements" xmlns:editor="UnityEditor.UIElements">
|
||||
<VisualElement class="categorical-option ">
|
||||
<VisualElement class="categorical-option">
|
||||
<Button name="remove" class="remove-option-button"/>
|
||||
<Label name="index-label" text="[0]" style="min-width: 50px;"/>
|
||||
<editor:PropertyField name="option" class="option-property-field"/>
|
||||
|
|
|
@ -1,23 +0,0 @@
|
|||
<UXML xmlns="UnityEngine.UIElements" xmlns:editor="UnityEditor.UIElements">
|
||||
<VisualElement>
|
||||
<Style src="../Uss/Styles.uss"/>
|
||||
<Label style="white-space: normal; margin-bottom: 2px; margin-top: 2px;" text="Use this component to define a list of parameters for randomizing various aspects of your scene throughout the simulation (e.g. object size and placement, lighting, etc.) and assign them to properties of GameObjects present in your scene."/>
|
||||
<Label style="white-space: normal; margin-bottom: 2px; margin-top: 10px" text ="Search parameter names:"/>
|
||||
<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>
|
||||
<Label style="white-space: normal; margin-bottom: 2px; margin-top: 10px" text ="Parameter list:"/>
|
||||
<ScrollView name="parameter-scroll-view" class="dark-viewport" style="min-height: 100px; max-height: 600px; margin-top: 2px">
|
||||
<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>
|
|
@ -1,10 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 6b8a21614fbae12468cb42ada0df200f
|
||||
ScriptedImporter:
|
||||
internalIDToNameTable: []
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
script: {fileID: 13804, guid: 0000000000000000e000000000000000, type: 0}
|
|
@ -0,0 +1,10 @@
|
|||
<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-toggle foldout-open"/>
|
||||
<Label name="field-name" style="font-size: 12px;"/>
|
||||
</VisualElement>
|
||||
<VisualElement name="drawer" class="properties-container" style="padding-left: 18px;"/>
|
||||
</VisualElement>
|
||||
</UXML>
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
<<<<<<< HEAD
|
||||
guid: fbfd6bfda79247c1a4578907f9df9d6c
|
||||
timeCreated: 1600754588
|
||||
=======
|
||||
guid: 6a4bb3efae29429292ccdfa63e661872
|
||||
timeCreated: 1598240583
|
||||
>>>>>>> 86d25d2... implemented parameter behaviours
|
|
@ -1,6 +0,0 @@
|
|||
<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>
|
|
@ -1,3 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 18765b47a76c4adcb639d0d247b8bd34
|
||||
timeCreated: 1596419194
|
|
@ -1,31 +1,6 @@
|
|||
<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>
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
<UXML xmlns="UnityEngine.UIElements" xmlns:editor="UnityEditor.UIElements">
|
||||
<VisualElement class="randomizer-element" style="flex-direction: row;">
|
||||
<Style src="../Uss/ParameterStyles.uss"/>
|
||||
<VisualElement name="drag-handle" class="drag-handle"/>
|
||||
|
||||
<VisualElement style="flex-grow: 1;">
|
||||
<VisualElement style="flex-direction: row; justify-content: space-between;">
|
||||
<VisualElement style="flex-direction: row; align-items: center;">
|
||||
<VisualElement name="collapse" class="collapse-toggle foldout-open"/>
|
||||
<Toggle name="enabled"/>
|
||||
<TextElement name="class-name" text="Randomizer Class Name"/>
|
||||
</VisualElement>
|
||||
<Button name="remove" class="remove-option-button"/>
|
||||
</VisualElement>
|
||||
|
||||
<VisualElement name="properties" class="properties-container" style="padding-left: 16px;"/>
|
||||
</VisualElement>
|
||||
</VisualElement>
|
||||
</UXML>
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: f68d0e4ae9a94881adad2ff4835cddaf
|
||||
timeCreated: 1600290113
|
|
@ -0,0 +1,8 @@
|
|||
<UXML xmlns="UnityEngine.UIElements" xmlns:editor="UnityEditor.UIElements">
|
||||
<VisualElement name="randomizers-container" class="dark-viewport" style="margin-top: 6px; min-height: 100px;"/>
|
||||
<VisualElement style="flex-direction: row; align-items: center; justify-content: center; margin-top: 4px;">
|
||||
<editor:ToolbarMenu name="add-randomizer" text="Add Randomizer"/>
|
||||
<Button name="expand-all" text="Expand All"/>
|
||||
<Button name="collapse-all" text="Collapse All"/>
|
||||
</VisualElement>
|
||||
</UXML>
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 61284b57145a4b87b960f780ead021cb
|
||||
timeCreated: 1600368801
|
|
@ -1,5 +1,6 @@
|
|||
<UXML xmlns="UnityEngine.UIElements" xmlns:editor="UnityEditor.UIElements">
|
||||
<VisualElement name="sampler-template" style="margin-bottom: 4px;">
|
||||
<Style src="../Uss/SamplerStyles.uss"/>
|
||||
<VisualElement style="flex-direction: row; align-items: center;">
|
||||
<Label name="sampler-name" text="Sampler Name" class="unity-base-field__label sampler-name"/>
|
||||
<editor:ToolbarMenu name="sampler-type-dropdown" text="Placeholder Sampler Type" class="sampler-type-menu"/>
|
||||
|
|
|
@ -1,20 +1,23 @@
|
|||
<UXML xmlns="UnityEngine.UIElements" xmlns:editor="UnityEditor.UIElements">
|
||||
<VisualElement>
|
||||
<Style src="../Uss/Styles.uss"/>
|
||||
<Label style="white-space: normal; margin-bottom: 5px; margin-top: 2px" text="Scenarios control the execution flow of your simulation by applying randomization parameters. Make sure to always have only one scenario active within your scene."/>
|
||||
<VisualElement name="inspector-properties" style="margin-bottom: 20px;"/>
|
||||
<Style src="../Uss/ScenarioStyles.uss"/>
|
||||
<TextElement class="info-box" text="Scenarios control the execution flow of your simulation by applying randomization parameters. Make sure to always have only one scenario active within your scene."/>
|
||||
<VisualElement name="inspector-properties" style="margin-bottom: 4px;"/>
|
||||
|
||||
<VisualElement name="configuration-container" class="dark-viewport">
|
||||
<Toggle label="Quit On Complete" tooltip="Quit the application when the scenario completes" binding-path="quitOnComplete" style="margin-left: 3px"/>
|
||||
<VisualElement name="configuration-container" class="dark-viewport" style="padding-left: 16px">
|
||||
<Toggle label="Quit On Complete" tooltip="Quit the application when the scenario completes" binding-path="quitOnComplete"/>
|
||||
<VisualElement name="constants-container">
|
||||
<editor:PropertyField binding-path="constants" tooltip="A custom list of parameters for this scenario that will be JSON serialized. You can add or remove constants by modifying the code for this scenario class. Only these properties of the simulation can be changed externally from a built player."/>
|
||||
<editor:PropertyField name="configuration-file-name" label="Constants File Name" binding-path="serializedConstantsFileName"/>
|
||||
<editor:PropertyField tooltip="Read constants from JSON when the application starts" name="deserialize-on-start" label="Deserialize On Start" binding-path="deserializeOnStart" style="padding-left: 4px;"/>
|
||||
<editor:PropertyField tooltip="Read constants from JSON when the application starts" name="deserialize-on-start" label="Deserialize On Start" binding-path="deserializeOnStart"/>
|
||||
<VisualElement style="flex-direction: row;">
|
||||
<Button name="serialize-constants" text="Serialize Constants" style="flex-grow: 1;"/>
|
||||
<Button name="deserialize-constants" text="Deserialize Constants" style="flex-grow: 1;"/>
|
||||
</VisualElement>
|
||||
</VisualElement>
|
||||
</VisualElement>
|
||||
|
||||
<VisualElement name="randomizer-list-placeholder"/>
|
||||
|
||||
</VisualElement>
|
||||
</UXML>
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
<<<<<<< HEAD
|
||||
guid: 64930d74a0b54875ab472b72066417bc
|
||||
timeCreated: 1600754567
|
||||
=======
|
||||
guid: 7f8f95a1bb144a96b9310164f5560387
|
||||
timeCreated: 1598135666
|
||||
>>>>>>> 86d25d2... implemented parameter behaviours
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
<<<<<<< HEAD
|
||||
guid: 5b6d309152934df99cfff89a96b9703e
|
||||
timeCreated: 1600754567
|
||||
=======
|
||||
guid: 3066f77d411047baafb6cc454adc6e37
|
||||
timeCreated: 1595535184
|
||||
>>>>>>> 86d25d2... implemented parameter behaviours
|
|
@ -0,0 +1,39 @@
|
|||
using UnityEditor;
|
||||
using UnityEditor.UIElements;
|
||||
using UnityEngine.Experimental.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();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
<<<<<<< HEAD
|
||||
guid: c70590a385e44f6fbe82f5c74cb92f71
|
||||
timeCreated: 1600754567
|
||||
=======
|
||||
guid: 103b163a2467415ab86b0df8175b12a6
|
||||
timeCreated: 1598254290
|
||||
>>>>>>> 86d25d2... implemented parameter behaviours
|
|
@ -1,20 +1,21 @@
|
|||
using UnityEngine.UIElements;
|
||||
using UnityEngine.Experimental.Perception.Randomization.VisualElements;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace UnityEngine.Experimental.Perception.Randomization.Editor
|
||||
{
|
||||
class ParameterDragManipulator : MouseManipulator
|
||||
class DragToReorderManipulator : MouseManipulator
|
||||
{
|
||||
bool m_Active;
|
||||
float m_Offset;
|
||||
ParameterElement m_ParameterElement;
|
||||
RandomizerElement m_RandomizerElement;
|
||||
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_RandomizerElement = (RandomizerElement)target;
|
||||
m_DragHandle = m_RandomizerElement.Q<VisualElement>("drag-handle");
|
||||
m_DragHandle.RegisterCallback<MouseDownEvent>(OnMouseDown);
|
||||
m_DragHandle.RegisterCallback<MouseMoveEvent>(OnMouseMove);
|
||||
m_DragHandle.RegisterCallback<MouseUpEvent>(OnMouseUp);
|
||||
|
@ -35,9 +36,6 @@ namespace UnityEngine.Experimental.Perception.Randomization.Editor
|
|||
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);
|
||||
|
@ -82,20 +80,21 @@ namespace UnityEngine.Experimental.Perception.Randomization.Editor
|
|||
middlePoints[p++] = middleHeight + localY;
|
||||
}
|
||||
|
||||
var randomizerIndex = m_RandomizerElement.parent.IndexOf(m_RandomizerElement);
|
||||
for (var i = 0; i < middlePoints.Length; i++)
|
||||
{
|
||||
if (dragBarY < middlePoints[i])
|
||||
{
|
||||
ReorderParameter(m_ParameterElement.ParameterIndex, i);
|
||||
ReorderParameter(randomizerIndex, i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
ReorderParameter(m_ParameterElement.ParameterIndex, middlePoints.Length);
|
||||
ReorderParameter(randomizerIndex, middlePoints.Length);
|
||||
}
|
||||
|
||||
void ReorderParameter(int currentIndex, int nextIndex)
|
||||
{
|
||||
m_ParameterElement.ConfigEditor.ReorderParameter(currentIndex, nextIndex);
|
||||
m_RandomizerElement.randomizerList.ReorderRandomizer(currentIndex, nextIndex);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
fileFormatVersion: 2
|
||||
guid: ca07567b4377a1f41a9bcaf56d0ce8df
|
||||
guid: f2b59fa8baf440f597257d8eb8219afa
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
|
@ -0,0 +1,48 @@
|
|||
using UnityEditor;
|
||||
using UnityEngine.Experimental.Perception.Randomization.Editor;
|
||||
using UnityEngine.Experimental.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";
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
<<<<<<< HEAD
|
||||
guid: a9f0d234cfc24a8da54ec04d5ec9a129
|
||||
timeCreated: 1600754567
|
||||
=======
|
||||
guid: e2eb905ca8c14b5cbe43e48418948be0
|
||||
timeCreated: 1598255728
|
||||
>>>>>>> 86d25d2... implemented parameter behaviours
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
<<<<<<< HEAD
|
||||
guid: 708f941b18c345d8a0b7d1ea31d27843
|
||||
timeCreated: 1600754567
|
||||
=======
|
||||
guid: e37f169c618d471d8ed9614a41096437
|
||||
timeCreated: 1595281335
|
||||
>>>>>>> 86d25d2... implemented parameter behaviours
|
|
@ -6,7 +6,7 @@ namespace UnityEngine.Experimental.Perception.Randomization.Editor
|
|||
{
|
||||
public ParameterDragBar()
|
||||
{
|
||||
AddToClassList("parameter-drag-bar");
|
||||
AddToClassList("drag-bar");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
<<<<<<< HEAD
|
||||
fileFormatVersion: 2
|
||||
<<<<<<< HEAD
|
||||
guid: 61021c66c33e40e98de0702ae0aa4449
|
||||
timeCreated: 1600754567
|
||||
=======
|
||||
guid: 7c1e08b02e5a4c55875f34baf32f8e76
|
||||
timeCreated: 1596143672
|
||||
>>>>>>> 86d25d2... implemented parameter behaviours
|
||||
=======
|
||||
fileFormatVersion: 2
|
||||
guid: 7c1e08b02e5a4c55875f34baf32f8e76
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
>>>>>>> 750f255... working on new workflow
|
|
@ -0,0 +1,196 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEditor.UIElements;
|
||||
using UnityEngine.Experimental.Perception.Randomization.Editor;
|
||||
using UnityEngine.Experimental.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);
|
||||
if (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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
<<<<<<< HEAD
|
||||
guid: b15caa7425ab4b9a8367bd544ab4730d
|
||||
timeCreated: 1600754567
|
||||
=======
|
||||
guid: ea72d77c64d1447aa195e2068f02cf74
|
||||
timeCreated: 1595279847
|
||||
>>>>>>> 86d25d2... implemented parameter behaviours
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
<<<<<<< HEAD
|
||||
guid: 7df00c41d9394fa0ae239349350cb563
|
||||
timeCreated: 1600754567
|
||||
=======
|
||||
guid: b4fa54f5ed5d4d67a278fa8b42dc55cb
|
||||
timeCreated: 1596171029
|
||||
>>>>>>> 86d25d2... implemented parameter behaviours
|
|
@ -0,0 +1,93 @@
|
|||
using System;
|
||||
using UnityEditor;
|
||||
using UnityEditor.UIElements;
|
||||
using UnityEngine.Experimental.Perception.Randomization.Editor;
|
||||
using UnityEngine.Experimental.Perception.Randomization.Randomizers;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace UnityEngine.Experimental.Perception.Randomization.VisualElements
|
||||
{
|
||||
class RandomizerElement : VisualElement
|
||||
{
|
||||
SerializedProperty m_Collapsed;
|
||||
SerializedProperty m_Property;
|
||||
VisualElement m_PropertiesContainer;
|
||||
|
||||
Randomizer randomizer => (Randomizer)StaticData.GetManagedReferenceValue(m_Property);
|
||||
|
||||
public Type randomizerType => randomizer.GetType();
|
||||
|
||||
const string k_CollapsedParameterClass = "collapsed";
|
||||
|
||||
public RandomizerList randomizerList { get; }
|
||||
|
||||
public bool collapsed
|
||||
{
|
||||
get => m_Collapsed.boolValue;
|
||||
set
|
||||
{
|
||||
m_Collapsed.boolValue = value;
|
||||
m_Property.serializedObject.ApplyModifiedProperties();
|
||||
if (value)
|
||||
AddToClassList(k_CollapsedParameterClass);
|
||||
else
|
||||
RemoveFromClassList(k_CollapsedParameterClass);
|
||||
}
|
||||
}
|
||||
|
||||
public RandomizerElement(SerializedProperty property, RandomizerList randomizerList)
|
||||
{
|
||||
m_Property = property;
|
||||
this.randomizerList = randomizerList;
|
||||
m_Collapsed = property.FindPropertyRelative("collapsed");
|
||||
AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(
|
||||
$"{StaticData.uxmlDir}/RandomizerElement.uxml").CloneTree(this);
|
||||
|
||||
var classNameLabel = this.Q<TextElement>("class-name");
|
||||
var splitType = property.managedReferenceFullTypename.Split(' ', '.');
|
||||
classNameLabel.text = splitType[splitType.Length - 1];
|
||||
|
||||
m_PropertiesContainer = this.Q<VisualElement>("properties");
|
||||
|
||||
var collapseToggle = this.Q<VisualElement>("collapse");
|
||||
collapseToggle.RegisterCallback<MouseUpEvent>(evt => collapsed = !collapsed);
|
||||
|
||||
var enabledToggle = this.Q<Toggle>("enabled");
|
||||
enabledToggle.BindProperty(property.FindPropertyRelative("<enabled>k__BackingField"));
|
||||
|
||||
var removeButton = this.Q<Button>("remove");
|
||||
removeButton.clicked += () => randomizerList.RemoveRandomizer(this);
|
||||
|
||||
this.AddManipulator(new DragToReorderManipulator());
|
||||
|
||||
FillPropertiesContainer();
|
||||
}
|
||||
|
||||
void FillPropertiesContainer()
|
||||
{
|
||||
m_PropertiesContainer.Clear();
|
||||
var iterator = m_Property.Copy();
|
||||
var nextSiblingProperty = m_Property.Copy();
|
||||
nextSiblingProperty.NextVisible(false);
|
||||
|
||||
var foundProperties = false;
|
||||
if (iterator.NextVisible(true))
|
||||
{
|
||||
do
|
||||
{
|
||||
if (SerializedProperty.EqualContents(iterator, nextSiblingProperty))
|
||||
break;
|
||||
if (iterator.name == "<enabled>k__BackingField")
|
||||
continue;
|
||||
foundProperties = true;
|
||||
var propertyField = new PropertyField(iterator.Copy());
|
||||
propertyField.Bind(m_Property.serializedObject);
|
||||
m_PropertiesContainer.Add(propertyField);
|
||||
} while (iterator.NextVisible(false));
|
||||
}
|
||||
|
||||
if (!foundProperties)
|
||||
m_PropertiesContainer.style.display = new StyleEnum<DisplayStyle>(DisplayStyle.None);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: b06477660dbb47749bbc3db0aeb5005d
|
||||
timeCreated: 1600290125
|
|
@ -0,0 +1,92 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEditor.UIElements;
|
||||
using UnityEngine.Experimental.Perception.Randomization.Editor;
|
||||
using UnityEngine.Experimental.Perception.Randomization.Parameters;
|
||||
using UnityEngine.Experimental.Perception.Randomization.Scenarios;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace UnityEngine.Experimental.Perception.Randomization.VisualElements
|
||||
{
|
||||
class RandomizerList : VisualElement
|
||||
{
|
||||
SerializedProperty m_Property;
|
||||
VisualElement m_Container;
|
||||
ToolbarMenu m_AddRandomizerMenu;
|
||||
|
||||
ScenarioBase scenario => (ScenarioBase)m_Property.serializedObject.targetObject;
|
||||
|
||||
public RandomizerList(SerializedProperty property)
|
||||
{
|
||||
m_Property = property;
|
||||
AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(
|
||||
$"{StaticData.uxmlDir}/RandomizerList.uxml").CloneTree(this);
|
||||
|
||||
m_Container = this.Q<VisualElement>("randomizers-container");
|
||||
m_AddRandomizerMenu = this.Q<ToolbarMenu>("add-randomizer");
|
||||
|
||||
var expandAllButton = this.Q<Button>("expand-all");
|
||||
expandAllButton.clicked += () => CollapseRandomizers(false);
|
||||
|
||||
var collapseAllButton = this.Q<Button>("collapse-all");
|
||||
collapseAllButton.clicked += () => CollapseRandomizers(true);
|
||||
|
||||
RefreshList();
|
||||
}
|
||||
|
||||
void RefreshList()
|
||||
{
|
||||
m_Container.Clear();
|
||||
for (var i = 0; i < m_Property.arraySize; i++)
|
||||
m_Container.Add(new RandomizerElement(m_Property.GetArrayElementAtIndex(i), this));
|
||||
SetMenuOptions();
|
||||
}
|
||||
|
||||
void SetMenuOptions()
|
||||
{
|
||||
m_AddRandomizerMenu.menu.MenuItems().Clear();
|
||||
var typeSet = new HashSet<Type>();
|
||||
foreach (var randomizer in scenario.randomizers)
|
||||
typeSet.Add(randomizer.GetType());
|
||||
foreach (var randomizerType in StaticData.randomizerTypes)
|
||||
{
|
||||
if (typeSet.Contains(randomizerType))
|
||||
continue;
|
||||
m_AddRandomizerMenu.menu.AppendAction(
|
||||
Parameter.GetDisplayName(randomizerType),
|
||||
a => { AddRandomizer(randomizerType); });
|
||||
}
|
||||
}
|
||||
|
||||
void AddRandomizer(Type randomizerType)
|
||||
{
|
||||
var newRandomizer = scenario.CreateRandomizer(randomizerType);
|
||||
newRandomizer.RandomizeParameterSeeds();
|
||||
m_Property.serializedObject.Update();
|
||||
RefreshList();
|
||||
}
|
||||
|
||||
public void RemoveRandomizer(RandomizerElement element)
|
||||
{
|
||||
scenario.RemoveRandomizer(element.randomizerType);
|
||||
m_Property.serializedObject.Update();
|
||||
RefreshList();
|
||||
}
|
||||
|
||||
public void ReorderRandomizer(int currentIndex, int nextIndex)
|
||||
{
|
||||
if (currentIndex == nextIndex)
|
||||
return;
|
||||
scenario.ReorderRandomizer(currentIndex, nextIndex);
|
||||
m_Property.serializedObject.Update();
|
||||
RefreshList();
|
||||
}
|
||||
|
||||
void CollapseRandomizers(bool collapsed)
|
||||
{
|
||||
foreach (var child in m_Container.Children())
|
||||
((RandomizerElement)child).collapsed = collapsed;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: dcef5294bac746bbad269c94b529f7df
|
||||
timeCreated: 1600366159
|
|
@ -74,7 +74,7 @@ namespace UnityEngine.Experimental.Perception.Randomization.Editor
|
|||
m_Properties.Clear();
|
||||
var currentProperty = m_Property.Copy();
|
||||
var nextSiblingProperty = m_Property.Copy();
|
||||
nextSiblingProperty.Next(false);
|
||||
nextSiblingProperty.NextVisible(false);
|
||||
|
||||
if (currentProperty.NextVisible(true))
|
||||
{
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
<<<<<<< HEAD
|
||||
guid: 134b50014b9f4c0694a087d3529ea4c2
|
||||
timeCreated: 1600754567
|
||||
=======
|
||||
guid: b367f8f2cb8e465ca2d60ccbd5414a14
|
||||
timeCreated: 1595277943
|
||||
>>>>>>> 86d25d2... implemented parameter behaviours
|
|
@ -12,7 +12,7 @@ MonoBehaviour:
|
|||
m_Script: {fileID: 11500000, guid: d0353a89b1f911e48b9e16bdc9f2e058, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
version: 1
|
||||
version: 2
|
||||
--- !u!21 &2100000
|
||||
Material:
|
||||
serializedVersion: 6
|
||||
|
@ -26,7 +26,7 @@ Material:
|
|||
m_LightmapFlags: 4
|
||||
m_EnableInstancingVariants: 0
|
||||
m_DoubleSidedGI: 0
|
||||
m_CustomRenderQueue: 3050
|
||||
m_CustomRenderQueue: 3000
|
||||
stringTagMap:
|
||||
RenderType: Transparent
|
||||
disabledShaderPasses:
|
||||
|
@ -90,3 +90,4 @@ Material:
|
|||
- _Color: {r: 1, g: 1, b: 1, a: 1}
|
||||
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
|
||||
- _SpecColor: {r: 0.19999996, g: 0.19999996, b: 0.19999996, a: 1}
|
||||
m_BuildTextureStacks: []
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: b5afd2495bca4fdca95b86d9113f27b2
|
||||
timeCreated: 1594059945
|
|
@ -1,107 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Experimental.Perception.Randomization.Parameters;
|
||||
|
||||
namespace UnityEngine.Experimental.Perception.Randomization.Configuration
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates parameter interfaces for randomizing simulations
|
||||
/// </summary>
|
||||
[ExecuteInEditMode]
|
||||
[AddComponentMenu("Perception/Randomization/ParameterConfiguration")]
|
||||
public class ParameterConfiguration : MonoBehaviour
|
||||
{
|
||||
internal static HashSet<ParameterConfiguration> configurations = new HashSet<ParameterConfiguration>();
|
||||
[SerializeReference] internal List<Parameter> parameters = new List<Parameter>();
|
||||
|
||||
/// <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="ParameterConfigurationException"></exception>
|
||||
public Parameter GetParameter(string parameterName, Type parameterType)
|
||||
{
|
||||
foreach (var parameter in parameters)
|
||||
{
|
||||
if (parameter.name == parameterName && parameter.GetType() == parameterType)
|
||||
return 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 parameter in parameters)
|
||||
{
|
||||
if (parameter.name == parameterName && parameter is T typedParameter)
|
||||
return typedParameter;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
string PlaceholderParameterName() => $"Parameter{parameters.Count}";
|
||||
|
||||
internal T AddParameter<T>() where T : Parameter, new()
|
||||
{
|
||||
var parameter = new T();
|
||||
parameter.name = PlaceholderParameterName();
|
||||
parameters.Add(parameter);
|
||||
return parameter;
|
||||
}
|
||||
|
||||
internal Parameter AddParameter(Type parameterType)
|
||||
{
|
||||
if (!parameterType.IsSubclassOf(typeof(Parameter)))
|
||||
throw new ParameterConfigurationException($"Cannot add non-parameter types ({parameterType})");
|
||||
var parameter = (Parameter)Activator.CreateInstance(parameterType);
|
||||
parameter.name = PlaceholderParameterName();
|
||||
parameters.Add(parameter);
|
||||
return parameter;
|
||||
}
|
||||
|
||||
internal void ApplyParameters(int seedOffset, ParameterApplicationFrequency frequency)
|
||||
{
|
||||
foreach (var parameter in parameters)
|
||||
if (parameter.target.applicationFrequency == frequency)
|
||||
parameter.ApplyToTarget(seedOffset);
|
||||
}
|
||||
|
||||
internal void ResetParameterStates(int scenarioIteration)
|
||||
{
|
||||
foreach (var parameter in parameters)
|
||||
parameter.ResetState(scenarioIteration);
|
||||
}
|
||||
|
||||
internal void ValidateParameters()
|
||||
{
|
||||
var parameterNames = new HashSet<string>();
|
||||
foreach (var parameter in parameters)
|
||||
{
|
||||
if (parameterNames.Contains(parameter.name))
|
||||
throw new ParameterConfigurationException(
|
||||
$"Two or more parameters cannot share the same name (\"{parameter.name}\")");
|
||||
parameterNames.Add(parameter.name);
|
||||
parameter.Validate();
|
||||
}
|
||||
}
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
configurations.Add(this);
|
||||
}
|
||||
|
||||
void OnDisable()
|
||||
{
|
||||
configurations.Remove(this);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
using System;
|
||||
|
||||
namespace UnityEngine.Experimental.Perception.Randomization.Configuration
|
||||
{
|
||||
[Serializable]
|
||||
class ParameterConfigurationException : Exception
|
||||
{
|
||||
public ParameterConfigurationException(string message) : base(message) { }
|
||||
public ParameterConfigurationException(string message, Exception innerException) : base(message, innerException) { }
|
||||
}
|
||||
}
|
|
@ -1,3 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 17957711f996479c98d1bdf7f153f791
|
||||
timeCreated: 1594069464
|
|
@ -11,16 +11,19 @@ namespace UnityEngine.Experimental.Perception.Randomization.Parameters
|
|||
[Serializable]
|
||||
public abstract class CategoricalParameter<T> : CategoricalParameterBase
|
||||
{
|
||||
[SerializeField] internal bool uniform;
|
||||
[SerializeField] internal bool uniform = true;
|
||||
[SerializeReference] ISampler m_Sampler = new UniformSampler(0f, 1f);
|
||||
|
||||
[SerializeField] List<T> m_Categories = new List<T>();
|
||||
float[] m_NormalizedProbabilities;
|
||||
|
||||
/// <summary>
|
||||
/// Returns a list containing the samplers attached to this parameter
|
||||
/// Returns an IEnumerable that iterates over each sampler field in this parameter
|
||||
/// </summary>
|
||||
public override ISampler[] samplers => new [] { m_Sampler };
|
||||
public override IEnumerable<ISampler> samplers
|
||||
{
|
||||
get { yield return m_Sampler; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The sample type generated by this parameter
|
||||
|
@ -42,62 +45,37 @@ namespace UnityEngine.Experimental.Perception.Randomization.Parameters
|
|||
public float GetProbability(int index) => probabilities[index];
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a new categorical parameter
|
||||
/// Updates this parameter's list of categorical options
|
||||
/// </summary>
|
||||
protected CategoricalParameter() { }
|
||||
|
||||
/// <summary>
|
||||
/// Create a new categorical parameter from a list of categories with uniform probabilities
|
||||
/// </summary>
|
||||
/// <param name="categoricalOptions">List of categories</param>
|
||||
/// <exception cref="ArgumentException"></exception>
|
||||
protected CategoricalParameter(IEnumerable<T> categoricalOptions)
|
||||
/// <param name="categoricalOptions">The categorical options to configure</param>
|
||||
public void SetOptions(IEnumerable<T> categoricalOptions)
|
||||
{
|
||||
if (categories.Count == 0)
|
||||
throw new ArgumentException("List of options is empty");
|
||||
uniform = true;
|
||||
foreach (var option in categoricalOptions)
|
||||
AddOption(option, 1f);
|
||||
m_Categories.Clear();
|
||||
probabilities.Clear();
|
||||
foreach (var category in categoricalOptions)
|
||||
AddOption(category, 1f);
|
||||
NormalizeProbabilities();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new categorical parameter from a list of categories and their associated probabilities
|
||||
/// Updates this parameter's list of categorical options
|
||||
/// </summary>
|
||||
/// <param name="categoricalOptions">List of categories and their associated probabilities</param>
|
||||
/// <exception cref="ArgumentException"></exception>
|
||||
protected CategoricalParameter(IEnumerable<(T, float)> categoricalOptions)
|
||||
/// <param name="categoricalOptions">The categorical options to configure</param>
|
||||
public void SetOptions(IEnumerable<(T, float)> categoricalOptions)
|
||||
{
|
||||
if (categories.Count == 0)
|
||||
throw new ArgumentException("List of options is empty");
|
||||
m_Categories.Clear();
|
||||
probabilities.Clear();
|
||||
foreach (var (category, probability) in categoricalOptions)
|
||||
AddOption(category, probability);
|
||||
NormalizeProbabilities();
|
||||
}
|
||||
|
||||
internal override void AddOption()
|
||||
{
|
||||
m_Categories.Add(default);
|
||||
probabilities.Add(0f);
|
||||
}
|
||||
|
||||
internal void AddOption(T option, float probability)
|
||||
void AddOption(T option, float probability)
|
||||
{
|
||||
m_Categories.Add(option);
|
||||
probabilities.Add(probability);
|
||||
}
|
||||
|
||||
internal override void RemoveOption(int index)
|
||||
{
|
||||
m_Categories.RemoveAt(index);
|
||||
probabilities.RemoveAt(index);
|
||||
}
|
||||
|
||||
internal override void ClearOptions()
|
||||
{
|
||||
m_Categories.Clear();
|
||||
probabilities.Clear();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a list of the potential categories this parameter can generate
|
||||
/// </summary>
|
||||
|
@ -116,7 +94,7 @@ namespace UnityEngine.Experimental.Perception.Randomization.Parameters
|
|||
/// Validates the categorical probabilities assigned to this parameter
|
||||
/// </summary>
|
||||
/// <exception cref="ParameterValidationException"></exception>
|
||||
internal override void Validate()
|
||||
public override void Validate()
|
||||
{
|
||||
base.Validate();
|
||||
if (!uniform)
|
||||
|
@ -127,7 +105,7 @@ namespace UnityEngine.Experimental.Perception.Randomization.Parameters
|
|||
}
|
||||
}
|
||||
|
||||
internal void NormalizeProbabilities()
|
||||
void NormalizeProbabilities()
|
||||
{
|
||||
var totalProbability = 0f;
|
||||
for (var i = 0; i < probabilities.Count; i++)
|
||||
|
@ -182,11 +160,13 @@ namespace UnityEngine.Experimental.Perception.Randomization.Parameters
|
|||
: m_Categories[BinarySearch(randomValue)];
|
||||
}
|
||||
|
||||
internal sealed override void ApplyToTarget(int seedOffset)
|
||||
/// <summary>
|
||||
/// Generates a generic sample
|
||||
/// </summary>
|
||||
/// <returns>The generated sample</returns>
|
||||
public override object GenericSample()
|
||||
{
|
||||
if (!hasTarget)
|
||||
return;
|
||||
target.ApplyValueToTarget(Sample());
|
||||
return Sample();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,9 +10,5 @@ namespace UnityEngine.Experimental.Perception.Randomization.Parameters
|
|||
public abstract class CategoricalParameterBase : Parameter
|
||||
{
|
||||
[SerializeField] internal List<float> probabilities = new List<float>();
|
||||
|
||||
internal abstract void AddOption();
|
||||
internal abstract void RemoveOption(int index);
|
||||
internal abstract void ClearOptions();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,14 +32,19 @@ namespace UnityEngine.Experimental.Perception.Randomization.Parameters
|
|||
/// <returns>A NativeArray containing generated samples</returns>
|
||||
public abstract NativeArray<T> Samples(int sampleCount, out JobHandle jobHandle);
|
||||
|
||||
internal sealed override void ApplyToTarget(int seedOffset)
|
||||
/// <summary>
|
||||
/// Generates a generic sample
|
||||
/// </summary>
|
||||
/// <returns>The generated sample</returns>
|
||||
public override object GenericSample()
|
||||
{
|
||||
if (!hasTarget)
|
||||
return;
|
||||
target.ApplyValueToTarget(Sample());
|
||||
return Sample();
|
||||
}
|
||||
|
||||
internal override void Validate()
|
||||
/// <summary>
|
||||
/// Validate the settings of this parameter
|
||||
/// </summary>
|
||||
public override void Validate()
|
||||
{
|
||||
base.Validate();
|
||||
foreach (var sampler in samplers)
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Experimental.Perception.Randomization.Samplers;
|
||||
|
||||
|
@ -23,20 +24,20 @@ namespace UnityEngine.Experimental.Perception.Randomization.Parameters
|
|||
|
||||
[HideInInspector, SerializeField] internal bool collapsed;
|
||||
|
||||
/// <summary>
|
||||
/// The name of the parameter
|
||||
/// </summary>
|
||||
[HideInInspector] public string name = "Parameter";
|
||||
|
||||
/// <summary>
|
||||
/// The target this parameter apply a sample to
|
||||
/// </summary>
|
||||
[HideInInspector, SerializeField] public ParameterTarget target = new ParameterTarget();
|
||||
|
||||
/// <summary>
|
||||
/// Indicates whether this parameter has a target GameObject
|
||||
/// </summary>
|
||||
public bool hasTarget => target.gameObject != null;
|
||||
// /// <summary>
|
||||
// /// The name of the parameter
|
||||
// /// </summary>
|
||||
// [HideInInspector] public string name = "Parameter";
|
||||
//
|
||||
// /// <summary>
|
||||
// /// The target this parameter apply a sample to
|
||||
// /// </summary>
|
||||
// [HideInInspector, SerializeField] public ParameterTarget target = new ParameterTarget();
|
||||
//
|
||||
// /// <summary>
|
||||
// /// Indicates whether this parameter has a target GameObject
|
||||
// /// </summary>
|
||||
// public bool hasTarget => target.gameObject != null;
|
||||
|
||||
/// <summary>
|
||||
/// The sample type generated by this parameter
|
||||
|
@ -44,9 +45,9 @@ namespace UnityEngine.Experimental.Perception.Randomization.Parameters
|
|||
public abstract Type sampleType { get; }
|
||||
|
||||
/// <summary>
|
||||
/// An array containing a reference to each sampler field in this parameter
|
||||
/// Returns an IEnumerable that iterates over each sampler field in this parameter
|
||||
/// </summary>
|
||||
public abstract ISampler[] samplers { get; }
|
||||
public abstract IEnumerable<ISampler> samplers { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a new parameter
|
||||
|
@ -79,35 +80,33 @@ namespace UnityEngine.Experimental.Perception.Randomization.Parameters
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resets sampler states and then offsets those states using the current scenario iteration
|
||||
/// Resets the state of each sampler employed by this parameter
|
||||
/// </summary>
|
||||
/// <param name="scenarioIteration">The current scenario iteration</param>
|
||||
public void ResetState(int scenarioIteration)
|
||||
public void ResetState()
|
||||
{
|
||||
foreach (var sampler in samplers)
|
||||
{
|
||||
sampler.ResetState();
|
||||
sampler.IterateState(scenarioIteration);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Applies one sampled value to this parameters assigned target gameobject
|
||||
/// Offsets the state of each sampler employed by this parameter
|
||||
/// </summary>
|
||||
internal abstract void ApplyToTarget(int seedOffset);
|
||||
/// <param name="offsetIndex">Often the current scenario iteration</param>
|
||||
public void IterateState(int offsetIndex)
|
||||
{
|
||||
foreach (var sampler in samplers)
|
||||
sampler.IterateState(offsetIndex);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generates a generic sample
|
||||
/// </summary>
|
||||
/// <returns>The generated sample</returns>
|
||||
public abstract object GenericSample();
|
||||
|
||||
/// <summary>
|
||||
/// Validates parameter settings
|
||||
/// </summary>
|
||||
internal virtual void Validate()
|
||||
{
|
||||
if (hasTarget)
|
||||
{
|
||||
if (target.component == null)
|
||||
throw new ParameterValidationException($"Null component target on parameter \"{name}\"");
|
||||
if (string.IsNullOrEmpty(target.propertyName))
|
||||
throw new ParameterValidationException($"Invalid property target on parameter \"{name}\"");
|
||||
}
|
||||
}
|
||||
public virtual void Validate() { }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,90 +0,0 @@
|
|||
using System;
|
||||
|
||||
namespace UnityEngine.Experimental.Perception.Randomization.Parameters
|
||||
{
|
||||
/// <summary>
|
||||
/// Used to apply sampled parameter values to a particular GameObject, Component, and property.
|
||||
/// Typically managed by a parameter configuration.
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class ParameterTarget
|
||||
{
|
||||
[SerializeField] internal GameObject gameObject;
|
||||
[SerializeField] internal Component component;
|
||||
[SerializeField] internal string propertyName = string.Empty;
|
||||
[SerializeField] internal FieldOrProperty fieldOrProperty = FieldOrProperty.Field;
|
||||
[SerializeField] internal ParameterApplicationFrequency applicationFrequency = ParameterApplicationFrequency.OnIterationSetup;
|
||||
|
||||
/// <summary>
|
||||
/// Assigns a new target
|
||||
/// </summary>
|
||||
/// <param name="targetObject">The target GameObject</param>
|
||||
/// <param name="targetComponent">The target component on the target GameObject</param>
|
||||
/// <param name="fieldOrPropertyName">The name of the property to apply the parameter to</param>
|
||||
/// <param name="frequency">How often to apply the parameter to its target</param>
|
||||
public void AssignNewTarget(
|
||||
GameObject targetObject,
|
||||
Component targetComponent,
|
||||
string fieldOrPropertyName,
|
||||
ParameterApplicationFrequency frequency)
|
||||
{
|
||||
gameObject = targetObject;
|
||||
component = targetComponent;
|
||||
propertyName = fieldOrPropertyName;
|
||||
applicationFrequency = frequency;
|
||||
var componentType = component.GetType();
|
||||
fieldOrProperty = componentType.GetField(fieldOrPropertyName) != null
|
||||
? FieldOrProperty.Field
|
||||
: FieldOrProperty.Property;
|
||||
}
|
||||
|
||||
internal void Clear()
|
||||
{
|
||||
gameObject = null;
|
||||
component = null;
|
||||
propertyName = string.Empty;
|
||||
}
|
||||
|
||||
internal void ApplyValueToTarget(object value)
|
||||
{
|
||||
var componentType = component.GetType();
|
||||
if (fieldOrProperty == FieldOrProperty.Field)
|
||||
{
|
||||
var field = componentType.GetField(propertyName);
|
||||
if (field == null)
|
||||
throw new ParameterValidationException(
|
||||
$"Component type {componentType.Name} does not have a field named {propertyName}");
|
||||
field.SetValue(component, value);
|
||||
}
|
||||
else
|
||||
{
|
||||
var property = componentType.GetProperty(propertyName);
|
||||
if (property == null)
|
||||
throw new ParameterValidationException(
|
||||
$"Component type {componentType.Name} does not have a property named {propertyName}");
|
||||
property.SetValue(component, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// How often to apply a new sample to a parameter's target
|
||||
/// </summary>
|
||||
public enum ParameterApplicationFrequency
|
||||
{
|
||||
/// <summary>
|
||||
/// Applies a parameter once every iteration
|
||||
/// </summary>
|
||||
OnIterationSetup,
|
||||
|
||||
/// <summary>
|
||||
/// Applies a parameter once every frame
|
||||
/// </summary>
|
||||
EveryFrame
|
||||
}
|
||||
|
||||
enum FieldOrProperty
|
||||
{
|
||||
Field, Property
|
||||
}
|
||||
}
|
|
@ -1,3 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 2f42c40592b1423e96c12f59de1125f7
|
||||
timeCreated: 1596315783
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Unity.Burst;
|
||||
using Unity.Collections;
|
||||
using Unity.Jobs;
|
||||
|
@ -18,11 +19,20 @@ namespace UnityEngine.Experimental.Perception.Randomization.Parameters
|
|||
[HideInInspector, SerializeReference] public ISampler value = new UniformSampler(0f, 1f);
|
||||
|
||||
/// <summary>
|
||||
/// Returns the sampler employed by this parameter
|
||||
/// A threshold value that transforms random values within the range [0, 1] to boolean values.
|
||||
/// Values greater than the threshold are true, and values less than the threshold are false.
|
||||
/// </summary>
|
||||
public override ISampler[] samplers => new[] { value };
|
||||
[Range(0, 1)] public float threshold = 0.5f;
|
||||
|
||||
static bool Sample(float t) => t >= 0.5f;
|
||||
/// <summary>
|
||||
/// Returns an IEnumerable that iterates over each sampler field in this parameter
|
||||
/// </summary>
|
||||
public override IEnumerable<ISampler> samplers
|
||||
{
|
||||
get { yield return value; }
|
||||
}
|
||||
|
||||
bool Sample(float t) => t >= threshold;
|
||||
|
||||
/// <summary>
|
||||
/// Generates a boolean sample
|
||||
|
@ -46,7 +56,8 @@ namespace UnityEngine.Experimental.Perception.Randomization.Parameters
|
|||
jobHandle = new SamplesJob
|
||||
{
|
||||
rngSamples = rngSamples,
|
||||
samples = samples
|
||||
samples = samples,
|
||||
threshold = threshold
|
||||
}.Schedule(jobHandle);
|
||||
return samples;
|
||||
}
|
||||
|
@ -56,11 +67,12 @@ namespace UnityEngine.Experimental.Perception.Randomization.Parameters
|
|||
{
|
||||
[DeallocateOnJobCompletion] public NativeArray<float> rngSamples;
|
||||
public NativeArray<bool> samples;
|
||||
public float threshold;
|
||||
|
||||
public void Execute()
|
||||
{
|
||||
for (var i = 0; i < samples.Length; i++)
|
||||
samples[i] = Sample(rngSamples[i]);
|
||||
samples[i] = rngSamples[i] >= threshold;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
<<<<<<< HEAD
|
||||
guid: 2b14f5553d2847319c3077ecf7206d06
|
||||
timeCreated: 1600754588
|
||||
=======
|
||||
guid: ce91e289cdaa4ccc849a0c287aefd34d
|
||||
timeCreated: 1598326361
|
||||
>>>>>>> 50f2c39... Added xml documentation
|
|
@ -0,0 +1,107 @@
|
|||
using System;
|
||||
using Unity.Mathematics;
|
||||
|
||||
namespace UnityEngine.Experimental.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})";
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: ccdce8798ec146649d4714046529de2c
|
||||
timeCreated: 1598326388
|
|
@ -0,0 +1,10 @@
|
|||
using System;
|
||||
|
||||
namespace UnityEngine.Experimental.Perception.Randomization.Parameters
|
||||
{
|
||||
/// <summary>
|
||||
/// A categorical parameter for generating ColorHsva samples
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class ColorHsvaCategoricalParameter : CategoricalParameter<ColorHsva> { }
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: e7985c4ea0bf49578e9cabd2c1a63cb6
|
||||
timeCreated: 1598217458
|
|
@ -0,0 +1,181 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Unity.Burst;
|
||||
using Unity.Collections;
|
||||
using Unity.Jobs;
|
||||
using UnityEngine.Experimental.Perception.Randomization.Samplers;
|
||||
|
||||
namespace UnityEngine.Experimental.Perception.Randomization.Parameters
|
||||
{
|
||||
/// <summary>
|
||||
/// A numeric parameter for generating color samples using HSVA samplers
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class ColorHsvaParameter : NumericParameter<Color>
|
||||
{
|
||||
/// <summary>
|
||||
/// The sampler used for randomizing the hue component of generated samples
|
||||
/// </summary>
|
||||
[SerializeReference] public ISampler hue = new UniformSampler(0f, 1f);
|
||||
|
||||
/// <summary>
|
||||
/// The sampler used for randomizing the saturation component of generated samples
|
||||
/// </summary>
|
||||
[SerializeReference] public ISampler saturation = new UniformSampler(0f, 1f);
|
||||
|
||||
/// <summary>
|
||||
/// The sampler used for randomizing the value component of generated samples
|
||||
/// </summary>
|
||||
[SerializeReference] public ISampler value = 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 hue;
|
||||
yield return saturation;
|
||||
yield return value;
|
||||
yield return alpha;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generates an RGBA color sample
|
||||
/// </summary>
|
||||
/// <returns>The generated RGBA sample</returns>
|
||||
public override Color Sample()
|
||||
{
|
||||
var color = Color.HSVToRGB(hue.Sample(), saturation.Sample(), value.Sample());
|
||||
color.a = alpha.Sample();
|
||||
return color;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generates an HSVA color sample
|
||||
/// </summary>
|
||||
/// <returns>The generated HSVA sample</returns>
|
||||
public ColorHsva SampleHsva()
|
||||
{
|
||||
return new ColorHsva(hue.Sample(), saturation.Sample(), value.Sample(), alpha.Sample());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Schedules a job to generate an array of RGBA color 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 hueRng = hue.Samples(sampleCount, out var hueHandle);
|
||||
var satRng = saturation.Samples(sampleCount, out var satHandle);
|
||||
var valRng = value.Samples(sampleCount, out var valHandle);
|
||||
var alphaRng = alpha.Samples(sampleCount, out var alphaHandle);
|
||||
|
||||
var handles = new NativeArray<JobHandle>(4, Allocator.TempJob)
|
||||
{
|
||||
[0] = hueHandle,
|
||||
[1] = satHandle,
|
||||
[2] = valHandle,
|
||||
[3] = alphaHandle
|
||||
};
|
||||
var combinedJobHandles = JobHandle.CombineDependencies(handles);
|
||||
|
||||
jobHandle = new SamplesJob
|
||||
{
|
||||
hueRng = hueRng,
|
||||
satRng = satRng,
|
||||
valRng = valRng,
|
||||
alphaRng = alphaRng,
|
||||
samples = samples
|
||||
}.Schedule(combinedJobHandles);
|
||||
handles.Dispose(jobHandle);
|
||||
|
||||
return samples;
|
||||
}
|
||||
|
||||
[BurstCompile]
|
||||
struct SamplesJob : IJob
|
||||
{
|
||||
[DeallocateOnJobCompletion] public NativeArray<float> hueRng;
|
||||
[DeallocateOnJobCompletion] public NativeArray<float> satRng;
|
||||
[DeallocateOnJobCompletion] public NativeArray<float> valRng;
|
||||
[DeallocateOnJobCompletion] public NativeArray<float> alphaRng;
|
||||
public NativeArray<Color> samples;
|
||||
|
||||
static Color CreateColorHsva(float h, float s, float v, float a)
|
||||
{
|
||||
var color = Color.HSVToRGB(h, s, v);
|
||||
color.a = a;
|
||||
return color;
|
||||
}
|
||||
|
||||
public void Execute()
|
||||
{
|
||||
for (var i = 0; i < samples.Length; i++)
|
||||
samples[i] = CreateColorHsva(hueRng[i], satRng[i], valRng[i], alphaRng[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Schedules a job to generate an array of HSVA color 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 NativeArray<ColorHsva> SamplesHsva(int sampleCount, out JobHandle jobHandle)
|
||||
{
|
||||
var samples = new NativeArray<ColorHsva>(sampleCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory);
|
||||
var hueRng = hue.Samples(sampleCount, out var hueHandle);
|
||||
var satRng = saturation.Samples(sampleCount, out var satHandle);
|
||||
var valRng = value.Samples(sampleCount, out var valHandle);
|
||||
var alphaRng = alpha.Samples(sampleCount, out var alphaHandle);
|
||||
|
||||
var handles = new NativeArray<JobHandle>(4, Allocator.TempJob)
|
||||
{
|
||||
[0] = hueHandle,
|
||||
[1] = satHandle,
|
||||
[2] = valHandle,
|
||||
[3] = alphaHandle
|
||||
};
|
||||
var combinedJobHandles = JobHandle.CombineDependencies(handles);
|
||||
|
||||
jobHandle = new SamplesHsvaJob
|
||||
{
|
||||
hueRng = hueRng,
|
||||
satRng = satRng,
|
||||
valRng = valRng,
|
||||
alphaRng = alphaRng,
|
||||
samples = samples
|
||||
}.Schedule(combinedJobHandles);
|
||||
handles.Dispose(jobHandle);
|
||||
|
||||
return samples;
|
||||
}
|
||||
|
||||
[BurstCompile]
|
||||
struct SamplesHsvaJob : IJob
|
||||
{
|
||||
[DeallocateOnJobCompletion] public NativeArray<float> hueRng;
|
||||
[DeallocateOnJobCompletion] public NativeArray<float> satRng;
|
||||
[DeallocateOnJobCompletion] public NativeArray<float> valRng;
|
||||
[DeallocateOnJobCompletion] public NativeArray<float> alphaRng;
|
||||
public NativeArray<ColorHsva> samples;
|
||||
|
||||
public void Execute()
|
||||
{
|
||||
for (var i = 0; i < samples.Length; i++)
|
||||
samples[i] = new ColorHsva(hueRng[i], satRng[i], valRng[i], alphaRng[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
using System;
|
||||
|
||||
namespace UnityEngine.Experimental.Perception.Randomization.Parameters
|
||||
{
|
||||
/// <summary>
|
||||
/// A categorical parameter for generating RGBA color samples
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class ColorRgbCategoricalParameter : CategoricalParameter<Color> { }
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: f4bd575c48a145ec9b63eb48ce636ed7
|
||||
timeCreated: 1598251957
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Unity.Burst;
|
||||
using Unity.Collections;
|
||||
using Unity.Jobs;
|
||||
|
@ -7,25 +8,25 @@ using UnityEngine.Experimental.Perception.Randomization.Samplers;
|
|||
namespace UnityEngine.Experimental.Perception.Randomization.Parameters
|
||||
{
|
||||
/// <summary>
|
||||
/// A numeric parameter for generating Color samples
|
||||
/// A numeric parameter for generating RGBA color samples
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class ColorHsvaParameter : NumericParameter<Color>
|
||||
public class ColorRgbParameter : NumericParameter<Color>
|
||||
{
|
||||
/// <summary>
|
||||
/// The sampler used for randomizing the hue component of generated samples
|
||||
/// The sampler used for randomizing the red component of generated samples
|
||||
/// </summary>
|
||||
[SerializeReference] public ISampler hue = new UniformSampler(0f, 1f);
|
||||
[SerializeReference] public ISampler red = new UniformSampler(0f, 1f);
|
||||
|
||||
/// <summary>
|
||||
/// The sampler used for randomizing the saturation component of generated samples
|
||||
/// The sampler used for randomizing the green component of generated samples
|
||||
/// </summary>
|
||||
[SerializeReference] public ISampler saturation = new UniformSampler(0f, 1f);
|
||||
[SerializeReference] public ISampler green = new UniformSampler(0f, 1f);
|
||||
|
||||
/// <summary>
|
||||
/// The sampler used for randomizing the value component of generated samples
|
||||
/// The sampler used for randomizing the blue component of generated samples
|
||||
/// </summary>
|
||||
[SerializeReference] public ISampler value = new UniformSampler(0f, 1f);
|
||||
[SerializeReference] public ISampler blue = new UniformSampler(0f, 1f);
|
||||
|
||||
/// <summary>
|
||||
/// The sampler used for randomizing the alpha component of generated samples
|
||||
|
@ -33,19 +34,26 @@ namespace UnityEngine.Experimental.Perception.Randomization.Parameters
|
|||
[SerializeReference] public ISampler alpha = new ConstantSampler(1f);
|
||||
|
||||
/// <summary>
|
||||
/// Returns the samplers employed by this parameter
|
||||
/// Returns an IEnumerable that iterates over each sampler field in this parameter
|
||||
/// </summary>
|
||||
public override ISampler[] samplers => new []{ hue, saturation, value, alpha };
|
||||
public override IEnumerable<ISampler> samplers
|
||||
{
|
||||
get
|
||||
{
|
||||
yield return red;
|
||||
yield return green;
|
||||
yield return blue;
|
||||
yield return alpha;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generates a color sample
|
||||
/// Generates an RGBA color sample
|
||||
/// </summary>
|
||||
/// <returns>The generated sample</returns>
|
||||
/// <returns>The generated RGBA sample</returns>
|
||||
public override Color Sample()
|
||||
{
|
||||
var color = Color.HSVToRGB(hue.Sample(), saturation.Sample(), value.Sample());
|
||||
color.a = alpha.Sample();
|
||||
return color;
|
||||
return new Color(red.Sample(), green.Sample(), blue.Sample(), alpha.Sample());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -57,25 +65,25 @@ namespace UnityEngine.Experimental.Perception.Randomization.Parameters
|
|||
public override NativeArray<Color> Samples(int sampleCount, out JobHandle jobHandle)
|
||||
{
|
||||
var samples = new NativeArray<Color>(sampleCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory);
|
||||
var hueRng = hue.Samples(sampleCount, out var hueHandle);
|
||||
var satRng = saturation.Samples(sampleCount, out var satHandle);
|
||||
var valRng = value.Samples(sampleCount, out var valHandle);
|
||||
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] = hueHandle,
|
||||
[1] = satHandle,
|
||||
[2] = valHandle,
|
||||
[0] = redHandle,
|
||||
[1] = greenHandle,
|
||||
[2] = blueHandle,
|
||||
[3] = alphaHandle
|
||||
};
|
||||
var combinedJobHandles = JobHandle.CombineDependencies(handles);
|
||||
|
||||
jobHandle = new SamplesJob
|
||||
{
|
||||
hueRng = hueRng,
|
||||
satRng = satRng,
|
||||
valRng = valRng,
|
||||
redRng = redRng,
|
||||
greenRng = greenRng,
|
||||
blueRng = blueRng,
|
||||
alphaRng = alphaRng,
|
||||
samples = samples
|
||||
}.Schedule(combinedJobHandles);
|
||||
|
@ -87,23 +95,16 @@ namespace UnityEngine.Experimental.Perception.Randomization.Parameters
|
|||
[BurstCompile]
|
||||
struct SamplesJob : IJob
|
||||
{
|
||||
[DeallocateOnJobCompletion] public NativeArray<float> hueRng;
|
||||
[DeallocateOnJobCompletion] public NativeArray<float> satRng;
|
||||
[DeallocateOnJobCompletion] public NativeArray<float> valRng;
|
||||
[DeallocateOnJobCompletion] public NativeArray<float> redRng;
|
||||
[DeallocateOnJobCompletion] public NativeArray<float> greenRng;
|
||||
[DeallocateOnJobCompletion] public NativeArray<float> blueRng;
|
||||
[DeallocateOnJobCompletion] public NativeArray<float> alphaRng;
|
||||
public NativeArray<Color> samples;
|
||||
|
||||
static Color CreateColorHsva(float h, float s, float v, float a)
|
||||
{
|
||||
var color = Color.HSVToRGB(h, s, v);
|
||||
color.a = a;
|
||||
return color;
|
||||
}
|
||||
|
||||
public void Execute()
|
||||
{
|
||||
for (var i = 0; i < samples.Length; i++)
|
||||
samples[i] = CreateColorHsva(hueRng[i], satRng[i], valRng[i], alphaRng[i]);
|
||||
samples[i] = new Color(redRng[i], greenRng[i], blueRng[i], alphaRng[i]);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: a4fdf61227254683a9950f586d6e8f57
|
||||
timeCreated: 1598252064
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Unity.Collections;
|
||||
using Unity.Jobs;
|
||||
using UnityEngine.Experimental.Perception.Randomization.Samplers;
|
||||
|
@ -17,9 +18,12 @@ namespace UnityEngine.Experimental.Perception.Randomization.Parameters
|
|||
[SerializeReference] public ISampler value = new UniformSampler(0f, 1f);
|
||||
|
||||
/// <summary>
|
||||
/// Returns the sampler employed by this parameter
|
||||
/// Returns an IEnumerable that iterates over each sampler field in this parameter
|
||||
/// </summary>
|
||||
public override ISampler[] samplers => new []{ value };
|
||||
public override IEnumerable<ISampler> samplers
|
||||
{
|
||||
get { yield return value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generates a float sample
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Unity.Burst;
|
||||
using Unity.Collections;
|
||||
using Unity.Jobs;
|
||||
|
@ -18,9 +19,12 @@ namespace UnityEngine.Experimental.Perception.Randomization.Parameters
|
|||
[SerializeReference] public ISampler value = new UniformSampler(0f, 1f);
|
||||
|
||||
/// <summary>
|
||||
/// Returns the sampler employed by this parameter
|
||||
/// Returns an IEnumerable that iterates over each sampler field in this parameter
|
||||
/// </summary>
|
||||
public override ISampler[] samplers => new[] { value };
|
||||
public override IEnumerable<ISampler> samplers
|
||||
{
|
||||
get { yield return value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generates an integer sample
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Unity.Burst;
|
||||
using Unity.Collections;
|
||||
using Unity.Jobs;
|
||||
|
@ -23,9 +24,16 @@ namespace UnityEngine.Experimental.Perception.Randomization.Parameters
|
|||
[SerializeReference] public ISampler y = new UniformSampler(0f, 1f);
|
||||
|
||||
/// <summary>
|
||||
/// Returns the samplers employed by this parameter
|
||||
/// Returns an IEnumerable that iterates over each sampler field in this parameter
|
||||
/// </summary>
|
||||
public override ISampler[] samplers => new []{ x, y };
|
||||
public override IEnumerable<ISampler> samplers
|
||||
{
|
||||
get
|
||||
{
|
||||
yield return x;
|
||||
yield return y;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generates a Vector2 sample
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Unity.Burst;
|
||||
using Unity.Collections;
|
||||
using Unity.Jobs;
|
||||
|
@ -28,9 +29,17 @@ namespace UnityEngine.Experimental.Perception.Randomization.Parameters
|
|||
[SerializeReference] public ISampler z = new UniformSampler(0f, 1f);
|
||||
|
||||
/// <summary>
|
||||
/// Returns the samplers employed by this parameter
|
||||
/// Returns an IEnumerable that iterates over each sampler field in this parameter
|
||||
/// </summary>
|
||||
public override ISampler[] samplers => new []{ x, y, z };
|
||||
public override IEnumerable<ISampler> samplers
|
||||
{
|
||||
get
|
||||
{
|
||||
yield return x;
|
||||
yield return y;
|
||||
yield return z;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generates a Vector3 sample
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Unity.Burst;
|
||||
using Unity.Collections;
|
||||
using Unity.Jobs;
|
||||
|
@ -33,9 +34,18 @@ namespace UnityEngine.Experimental.Perception.Randomization.Parameters
|
|||
[SerializeReference] public ISampler w = new UniformSampler(0f, 1f);
|
||||
|
||||
/// <summary>
|
||||
/// The sampler used the samplers employed by this parameter
|
||||
/// Returns an IEnumerable that iterates over each sampler field in this parameter
|
||||
/// </summary>
|
||||
public override ISampler[] samplers => new []{ x, y, z, w };
|
||||
public override IEnumerable<ISampler> samplers
|
||||
{
|
||||
get
|
||||
{
|
||||
yield return x;
|
||||
yield return y;
|
||||
yield return z;
|
||||
yield return w;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generates a Vector4 sample
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
<<<<<<< HEAD
|
||||
guid: 80645bae9cd440ca81c7a1e03572e7da
|
||||
timeCreated: 1600754588
|
||||
=======
|
||||
guid: ae6aad06c0e14f67aa7a9ad9004a1828
|
||||
timeCreated: 1600274594
|
||||
>>>>>>> c653d18... Implemented randomizer class. Ran into SerializeReference issue 1193322.
|
|
@ -0,0 +1,140 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine.Experimental.Perception.Randomization.Parameters;
|
||||
using UnityEngine.Experimental.Perception.Randomization.Scenarios;
|
||||
|
||||
namespace UnityEngine.Experimental.Perception.Randomization.Randomizers
|
||||
{
|
||||
/// <summary>
|
||||
/// Derive Randomizer to implement systems that randomize GameObjects and/or simulation properties.
|
||||
/// </summary>
|
||||
/// <remark>
|
||||
/// Known issue:
|
||||
/// https://issuetracker.unity3d.com/issues/serializereference-non-serialized-initialized-fields-lose-their-values-when-entering-play-mode
|
||||
/// </remark>
|
||||
[Serializable]
|
||||
public abstract class Randomizer
|
||||
{
|
||||
bool m_PreviouslyEnabled;
|
||||
// ReSharper disable once InconsistentNaming
|
||||
internal ScenarioBase m_Scenario;
|
||||
// ReSharper disable once InconsistentNaming
|
||||
internal RandomizerTagManager m_TagManager;
|
||||
|
||||
[HideInInspector, SerializeField] internal bool collapsed;
|
||||
|
||||
/// <summary>
|
||||
/// Enabled Randomizers are updated, disabled Randomizers are not.
|
||||
/// </summary>
|
||||
[field: SerializeField] public bool enabled { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// Returns the scenario containing this Randomizer
|
||||
/// </summary>
|
||||
public ScenarioBase scenario => m_Scenario;
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the RandomizerTagManager of the scenario containing this Randomizer
|
||||
/// </summary>
|
||||
public RandomizerTagManager tagManager => m_TagManager;
|
||||
|
||||
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>
|
||||
/// OnCreate is called when the Randomizer is added or loaded to a scenario
|
||||
/// </summary>
|
||||
protected virtual void OnCreate() { }
|
||||
|
||||
/// <summary>
|
||||
/// OnIterationStart is called at the start of a new scenario iteration
|
||||
/// </summary>
|
||||
protected virtual void OnIterationStart() { }
|
||||
|
||||
/// <summary>
|
||||
/// OnIterationEnd is called the after a scenario iteration has completed
|
||||
/// </summary>
|
||||
protected virtual void OnIterationEnd() { }
|
||||
|
||||
/// <summary>
|
||||
/// OnScenarioComplete is called the after the entire scenario has completed
|
||||
/// </summary>
|
||||
protected virtual void OnScenarioComplete() { }
|
||||
|
||||
/// <summary>
|
||||
/// OnStartRunning is called on the first frame a Randomizer is enabled
|
||||
/// </summary>
|
||||
protected virtual void OnStartRunning() { }
|
||||
|
||||
/// <summary>
|
||||
/// OnStartRunning is called on the first frame a disabled Randomizer is updated
|
||||
/// </summary>
|
||||
protected virtual void OnStopRunning() { }
|
||||
|
||||
/// <summary>
|
||||
/// OnUpdate is executed every frame for enabled Randomizers
|
||||
/// </summary>
|
||||
protected virtual void OnUpdate() { }
|
||||
|
||||
internal virtual void Create()
|
||||
{
|
||||
OnCreate();
|
||||
}
|
||||
|
||||
internal virtual void IterationStart()
|
||||
{
|
||||
OnIterationStart();
|
||||
}
|
||||
|
||||
internal virtual void IterationEnd()
|
||||
{
|
||||
OnIterationEnd();
|
||||
}
|
||||
|
||||
internal virtual void ScenarioComplete()
|
||||
{
|
||||
OnScenarioComplete();
|
||||
}
|
||||
|
||||
internal void Update()
|
||||
{
|
||||
if (enabled)
|
||||
{
|
||||
if (!m_PreviouslyEnabled)
|
||||
{
|
||||
m_PreviouslyEnabled = true;
|
||||
OnStartRunning();
|
||||
}
|
||||
OnUpdate();
|
||||
}
|
||||
else if (m_PreviouslyEnabled)
|
||||
{
|
||||
m_PreviouslyEnabled = false;
|
||||
OnStopRunning();
|
||||
}
|
||||
}
|
||||
|
||||
internal void RandomizeParameterSeeds()
|
||||
{
|
||||
foreach (var parameter in parameters)
|
||||
parameter.RandomizeSamplers();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 3a0043de777a49488339296ce069550d
|
||||
timeCreated: 1600274620
|
|
@ -0,0 +1,25 @@
|
|||
using System;
|
||||
using UnityEngine.Experimental.Perception.Randomization.Scenarios;
|
||||
|
||||
namespace UnityEngine.Experimental.Perception.Randomization.Randomizers
|
||||
{
|
||||
/// <summary>
|
||||
/// Derive the RandomizerTag class to create new tag components.
|
||||
/// RandomizerTags are used to help randomizers query for a set of GameObjects to randomize.
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public abstract class RandomizerTag : MonoBehaviour
|
||||
{
|
||||
void Awake()
|
||||
{
|
||||
ScenarioBase.activeScenario.tagManager.AddTag(GetType(), gameObject);
|
||||
}
|
||||
|
||||
void OnDestroy()
|
||||
{
|
||||
var scenario = ScenarioBase.activeScenario;
|
||||
if (scenario)
|
||||
scenario.tagManager.RemoveTag(GetType(), gameObject);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 1a4fbe784c3d410988a620711a78a68c
|
||||
timeCreated: 1600717080
|
|
@ -0,0 +1,44 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace UnityEngine.Experimental.Perception.Randomization.Randomizers
|
||||
{
|
||||
/// <summary>
|
||||
/// Organizes RandomizerTags attached to GameObjects in the scene
|
||||
/// </summary>
|
||||
public class RandomizerTagManager
|
||||
{
|
||||
Dictionary<Type, HashSet<GameObject>> m_TagMap = new Dictionary<Type, HashSet<GameObject>>();
|
||||
|
||||
/// <summary>
|
||||
/// Returns a list of all GameObjects in the scene that have a RandomizerTag of the given type
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of RandomizerTag to query for</typeparam>
|
||||
/// <returns>A list of GameObjects with the given RandomizerTag</returns>
|
||||
public GameObject[] Query<T>() where T : RandomizerTag
|
||||
{
|
||||
var type = typeof(T);
|
||||
return m_TagMap.ContainsKey(type) ? m_TagMap[type].ToArray() : new GameObject[0];
|
||||
}
|
||||
|
||||
internal void AddTag(Type tagType, GameObject obj)
|
||||
{
|
||||
if (m_TagMap.ContainsKey(tagType))
|
||||
{
|
||||
m_TagMap[tagType].Add(obj);
|
||||
}
|
||||
else
|
||||
{
|
||||
var newSet = new HashSet<GameObject> { obj };
|
||||
m_TagMap.Add(tagType, newSet);
|
||||
}
|
||||
}
|
||||
|
||||
internal void RemoveTag(Type tagType, GameObject obj)
|
||||
{
|
||||
if (m_TagMap.ContainsKey(tagType))
|
||||
m_TagMap[tagType].Remove(obj);
|
||||
}
|
||||
}
|
||||
}
|
Некоторые файлы не были показаны из-за слишком большого количества измененных файлов Показать больше
Загрузка…
Ссылка в новой задаче