浏览代码

removed parameter and sampler display name attributes

/usim-randomization
Steven Leal 4 年前
当前提交
63c98aa9
共有 23 个文件被更改,包括 40 次插入131 次删除
  1. 2
      com.unity.perception/Editor/Randomization/ParameterConfigurationEditor.cs
  2. 2
      com.unity.perception/Editor/Randomization/ParameterElement.cs
  3. 6
      com.unity.perception/Editor/Randomization/SamplerElement.cs
  4. 46
      com.unity.perception/Editor/Randomization/StaticData.cs
  5. 25
      com.unity.perception/Runtime/Randomization/Parameters/Parameter.cs
  6. 1
      com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/BooleanParameter.cs
  7. 1
      com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/ColorHsvaParameter.cs
  8. 1
      com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/FloatParameter.cs
  9. 1
      com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/GameObjectParameter.cs
  10. 1
      com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/IntegerParameter.cs
  11. 1
      com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/MaterialParameter.cs
  12. 1
      com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/StringParameter.cs
  13. 1
      com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/Vector2Parameter.cs
  14. 1
      com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/Vector3Parameter.cs
  15. 1
      com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/Vector4Parameter.cs
  16. 1
      com.unity.perception/Runtime/Randomization/Samplers/SamplerTypes/ConstantSampler.cs
  17. 1
      com.unity.perception/Runtime/Randomization/Samplers/SamplerTypes/NormalSampler.cs
  18. 1
      com.unity.perception/Runtime/Randomization/Samplers/SamplerTypes/UniformSampler.cs
  19. 5
      com.unity.perception/Runtime/Randomization/Samplers/SamplerUtility.cs
  20. 33
      com.unity.perception/Runtime/Randomization/Parameters/ParameterDisplayName.cs
  21. 3
      com.unity.perception/Runtime/Randomization/Parameters/ParameterDisplayName.cs.meta
  22. 33
      com.unity.perception/Runtime/Randomization/Samplers/SamplerDisplayName.cs
  23. 3
      com.unity.perception/Runtime/Randomization/Samplers/SamplerDisplayName.cs.meta

2
com.unity.perception/Editor/Randomization/ParameterConfigurationEditor.cs


foreach (var parameterType in StaticData.parameterTypes)
{
parameterTypeMenu.menu.AppendAction(
ParameterDisplayName.GetDisplayName(parameterType).displayName,
Parameter.GetDisplayName(parameterType),
a => { AddParameter(parameterType); },
a => DropdownMenuAction.Status.Normal);
}

2
com.unity.perception/Editor/Randomization/ParameterElement.cs


removeButton.RegisterCallback<MouseUpEvent>(evt => paramConfigEditor.RemoveParameter(this));
var parameterTypeLabel = this.Query<Label>("parameter-type-label").First();
parameterTypeLabel.text = parameter.displayName.displayName;
parameterTypeLabel.text = parameter.displayName;
var parameterNameField = this.Q<TextField>("name");
parameterNameField.isDelayed = true;

6
com.unity.perception/Editor/Randomization/SamplerElement.cs


m_Properties = this.Q<VisualElement>("fields-container");
m_SamplerTypeDropdown = this.Q<ToolbarMenu>("sampler-type-dropdown");
m_SamplerTypeDropdown.text = SamplerDisplayName.GetDisplayName(m_Sampler.GetType()).displayName;
m_SamplerTypeDropdown.text = SamplerUtility.GetSamplerDisplayName(m_Sampler.GetType());;
var displayName = SamplerDisplayName.GetDisplayName(samplerType).displayName;
var displayName = SamplerUtility.GetSamplerDisplayName(samplerType);;
m_SamplerTypeDropdown.menu.AppendAction(
displayName,
a => { ReplaceSampler(samplerType); },

void ReplaceSampler(Type samplerType)
{
CreateSampler(samplerType);
m_SamplerTypeDropdown.text = SamplerDisplayName.GetDisplayName(m_Sampler.GetType()).displayName;
m_SamplerTypeDropdown.text = SamplerUtility.GetSamplerDisplayName(samplerType);
CreatePropertyFields();
}

46
com.unity.perception/Editor/Randomization/StaticData.cs


using System;
using System.Collections.Generic;
using System.Reflection;
using UnityEditor;
using UnityEngine.Perception.Randomization.Parameters;
using UnityEngine.Perception.Randomization.Samplers;

static StaticData()
{
GatherParameterAndSamplerTypes();
parameterTypes = GetConstructableDerivedTypes<Parameter>();
samplerTypes = GetConstructableDerivedTypes<ISampler>();
static void GatherParameterAndSamplerTypes()
static Type[] GetConstructableDerivedTypes<T>()
var paramAssembly = typeof(Parameter).Assembly;
var allAssemblies = AppDomain.CurrentDomain.GetAssemblies();
var assemblies = new List<Assembly> { paramAssembly };
foreach (var assembly in allAssemblies)
{
foreach (var asm in assembly.GetReferencedAssemblies())
{
if (asm.FullName == paramAssembly.GetName().FullName)
{
assemblies.Add(assembly);
break;
}
}
}
var parameterTypesList = new List<Type>();
var samplerTypesList = new List<Type>();
foreach (var assembly in assemblies)
var collection = TypeCache.GetTypesDerivedFrom<T>();
var types = new List<Type>();
foreach (var type in collection)
foreach (var type in assembly.GetTypes())
{
var isNotAbstract = (type.Attributes & TypeAttributes.Abstract) == 0;
if (typeof(Parameter).IsAssignableFrom(type) && isNotAbstract &&
ParameterDisplayName.GetDisplayName(type) != null)
parameterTypesList.Add(type);
else if (typeof(ISampler).IsAssignableFrom(type) &&
isNotAbstract && SamplerDisplayName.GetDisplayName(type) != null)
{
samplerTypesList.Add(type);
}
}
if (!type.IsAbstract && !type.IsInterface)
types.Add(type);
parameterTypes = parameterTypesList.ToArray();
samplerTypes = samplerTypesList.ToArray();
return types.ToArray();
}
}
}

25
com.unity.perception/Runtime/Randomization/Parameters/Parameter.cs


[Serializable]
public abstract class Parameter
{
/// <summary>
/// Returns the display name of a parameter type
/// </summary>
/// <param name="type">A subclass of Parameter</param>
/// <returns>A parameter type's display name</returns>
public static string GetDisplayName(Type type)
{
return type.Name.Replace("Parameter", "");
}
[HideInInspector, SerializeField] internal bool collapsed;
/// <summary>

/// </summary>
public bool hasTarget => target.gameObject != null;
/// <summary>
/// Returns meta information regarding this type of parameter
/// </summary>
internal ParameterDisplayName displayName =>
(ParameterDisplayName)Attribute.GetCustomAttribute(GetType(), typeof(ParameterDisplayName));
// /// <summary>
// /// Returns meta information regarding this type of parameter
// /// </summary>
// internal ParameterDisplayName displayName =>
// (ParameterDisplayName)Attribute.GetCustomAttribute(GetType(), typeof(ParameterDisplayName));
/// <summary>
/// The sample type generated by this parameter

/// An array containing a reference to each sampler field in this parameter
/// </summary>
public abstract ISampler[] samplers { get; }
/// <summary>
/// The display name of this parameter's sample type
/// </summary>
public virtual string displayName => GetDisplayName(GetType());
/// <summary>
/// Constructs a new parameter

1
com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/BooleanParameter.cs


/// A numeric parameter for generating boolean samples
/// </summary>
[Serializable]
[ParameterDisplayName("Bool")]
public class BooleanParameter : NumericParameter<bool>
{
/// <summary>

1
com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/ColorHsvaParameter.cs


/// A numeric parameter for generating Color samples
/// </summary>
[Serializable]
[ParameterDisplayName("ColorHSVA")]
public class ColorHsvaParameter : NumericParameter<Color>
{
/// <summary>

1
com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/FloatParameter.cs


/// A numeric parameter for generating float samples
/// </summary>
[Serializable]
[ParameterDisplayName("Float")]
public class FloatParameter : NumericParameter<float>
{
/// <summary>

1
com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/GameObjectParameter.cs


/// A categorical parameter for generating GameObject samples
/// </summary>
[Serializable]
[ParameterDisplayName("GameObject")]
public class GameObjectParameter : CategoricalParameter<GameObject> { }
}

1
com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/IntegerParameter.cs


/// A numeric parameter for generating integer samples
/// </summary>
[Serializable]
[ParameterDisplayName("Int")]
public class IntegerParameter : NumericParameter<int>
{
/// <summary>

1
com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/MaterialParameter.cs


/// A categorical parameter for generating Material samples
/// </summary>
[Serializable]
[ParameterDisplayName("Material")]
public class MaterialParameter : CategoricalParameter<Material> {}
}

1
com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/StringParameter.cs


/// A categorical parameter for generating string samples
/// </summary>
[Serializable]
[ParameterDisplayName("String")]
public class StringParameter : CategoricalParameter<string> {}
}

1
com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/Vector2Parameter.cs


/// A numeric parameter for generating Vector2 samples
/// </summary>
[Serializable]
[ParameterDisplayName("Vector2")]
public class Vector2Parameter : NumericParameter<Vector2>
{
/// <summary>

1
com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/Vector3Parameter.cs


/// A numeric parameter for generating Vector3 samples
/// </summary>
[Serializable]
[ParameterDisplayName("Vector3")]
public class Vector3Parameter : NumericParameter<Vector3>
{
/// <summary>

1
com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/Vector4Parameter.cs


/// A numeric parameter for generating Vector4 samples
/// </summary>
[Serializable]
[ParameterDisplayName("Vector4")]
public class Vector4Parameter : NumericParameter<Vector4>
{
/// <summary>

1
com.unity.perception/Runtime/Randomization/Samplers/SamplerTypes/ConstantSampler.cs


/// Returns a constant value when sampled
/// </summary>
[Serializable]
[SamplerDisplayName("Constant")]
public struct ConstantSampler : ISampler
{
/// <summary>

1
com.unity.perception/Runtime/Randomization/Samplers/SamplerTypes/NormalSampler.cs


/// https://en.wikipedia.org/wiki/Truncated_normal_distribution
/// </summary>
[Serializable]
[SamplerDisplayName("Normal")]
public struct NormalSampler : ISampler, IRandomRangedSampler
{
Unity.Mathematics.Random m_Random;

1
com.unity.perception/Runtime/Randomization/Samplers/SamplerTypes/UniformSampler.cs


/// Returns uniformly distributed random values within a designated range.
/// </summary>
[Serializable]
[SamplerDisplayName("Uniform")]
public struct UniformSampler : ISampler, IRandomRangedSampler
{
Unity.Mathematics.Random m_Random;

5
com.unity.perception/Runtime/Randomization/Samplers/SamplerUtility.cs


internal const uint largePrime = 0x202A96CF;
const int k_SamplingBatchSize = 64;
internal static string GetSamplerDisplayName(Type sampleType)
{
return sampleType.Name.Replace("Sampler", string.Empty);
}
/// <summary>
/// Non-deterministically generates a random seed
/// </summary>

33
com.unity.perception/Runtime/Randomization/Parameters/ParameterDisplayName.cs


using System;
namespace UnityEngine.Perception.Randomization.Parameters
{
/// <summary>
/// Defines the label used to identify a parameter types in a parameter configuration
/// </summary>
[AttributeUsage(AttributeTargets.Class)]
public class ParameterDisplayName : Attribute
{
/// <summary>
/// Returns the ParameterDisplayName attribute annotating a particular parameter type
/// </summary>
/// <param name="type">The type of parameter</param>
/// <returns>A ParameterDisplayName attribute</returns>
public static ParameterDisplayName GetDisplayName(Type type) =>
(ParameterDisplayName)GetCustomAttribute(type, typeof(ParameterDisplayName));
/// <summary>
/// The parameter label string
/// </summary>
public string displayName;
/// <summary>
/// Constructs a new ParameterDisplayName attribute
/// </summary>
/// <param name="displayName">The parameter label string</param>
public ParameterDisplayName(string displayName)
{
this.displayName = displayName;
}
}
}

3
com.unity.perception/Runtime/Randomization/Parameters/ParameterDisplayName.cs.meta


fileFormatVersion: 2
guid: 3f3c59805737435194cbbba3039a8805
timeCreated: 1594662345

33
com.unity.perception/Runtime/Randomization/Samplers/SamplerDisplayName.cs


using System;
namespace UnityEngine.Perception.Randomization.Samplers
{
/// <summary>
/// Defines the label used to identify a sampler types in the sampler drop down menu
/// </summary>
[AttributeUsage(AttributeTargets.Struct)]
public class SamplerDisplayName : Attribute
{
/// <summary>
/// Returns the SamplerDisplayName attribute annotating a particular sampler type
/// </summary>
/// <param name="type">The type of sampler</param>
/// <returns>A SamplerDisplayName attribute</returns>
public static SamplerDisplayName GetDisplayName(Type type) =>
(SamplerDisplayName)GetCustomAttribute(type, typeof(SamplerDisplayName));
/// <summary>
/// The sampler label string
/// </summary>
public string displayName;
/// <summary>
/// Constructs a new SamplerDisplayName attribute
/// </summary>
/// <param name="displayName">The sampler label string</param>
public SamplerDisplayName(string displayName)
{
this.displayName = displayName;
}
}
}

3
com.unity.perception/Runtime/Randomization/Samplers/SamplerDisplayName.cs.meta


fileFormatVersion: 2
guid: 2cfbfa48978f48da96d34db042c288c4
timeCreated: 1594663765
正在加载...
取消
保存