浏览代码

Added xml documentation

/parameter-bahaviours
Steven Leal 4 年前
当前提交
f1666ab3
共有 25 个文件被更改,包括 208 次插入82 次删除
  1. 2
      com.unity.perception/Editor/Randomization/Editors/ParameterBehaviourEditor.cs
  2. 2
      com.unity.perception/Editor/Randomization/PropertyDrawers/ColorHsvaDrawer.cs
  3. 2
      com.unity.perception/Editor/Randomization/PropertyDrawers/ParameterDrawer.cs
  4. 2
      com.unity.perception/Editor/Randomization/VisualElements/ParameterListItemElement.cs
  5. 15
      com.unity.perception/Runtime/Randomization/ParameterBehaviours/Configuration/ParameterList.cs
  6. 8
      com.unity.perception/Runtime/Randomization/ParameterBehaviours/Configuration/ParameterTarget.cs
  7. 60
      com.unity.perception/Runtime/Randomization/ParameterBehaviours/ParameterBehaviour.cs
  8. 4
      com.unity.perception/Runtime/Randomization/Parameters/NumericParameter.cs
  9. 2
      com.unity.perception/Tests/Runtime/Randomization/ScenarioTests.cs
  10. 44
      com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/ColorParameters/ColorHsvaParameter.cs
  11. 2
      com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/ColorParameters/ColorRgbParameter.cs
  12. 3
      com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/ColorParameters.meta
  13. 107
      com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/ColorParameters/ColorHsva.cs
  14. 3
      com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/ColorParameters/ColorHsva.cs.meta
  15. 10
      com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/ColorParameters/ColorHsvaCategoricalParameter.cs
  16. 10
      com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/ColorParameters/ColorRgbCategoricalParameter.cs
  17. 7
      com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/ColorHsvaCategoricalParameter.cs
  18. 7
      com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/ColorRgbCategoricalParameter.cs
  19. 0
      /com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/ColorParameters/ColorHsvaParameter.cs.meta
  20. 0
      /com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/ColorParameters/ColorHsvaCategoricalParameter.cs.meta
  21. 0
      /com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/ColorParameters/ColorHsvaParameter.cs
  22. 0
      /com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/ColorParameters/ColorRgbCategoricalParameter.cs.meta
  23. 0
      /com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/ColorParameters/ColorRgbParameter.cs
  24. 0
      /com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/ColorParameters/ColorRgbParameter.cs.meta

2
com.unity.perception/Editor/Randomization/Editors/ParameterBehaviourEditor.cs


namespace UnityEngine.Perception.Randomization.Editor
{
[CustomEditor(typeof(ParameterBehaviour), true)]
public class ParameterBehaviourEditor : UnityEditor.Editor
class ParameterBehaviourEditor : UnityEditor.Editor
{
public override VisualElement CreateInspectorGUI()
{

2
com.unity.perception/Editor/Randomization/PropertyDrawers/ColorHsvaDrawer.cs


namespace UnityEngine.Perception.Randomization.Editor.PropertyDrawers
{
[CustomPropertyDrawer(typeof(ColorHsva), true)]
public class ColorHsvaDrawer : PropertyDrawer
class ColorHsvaDrawer : PropertyDrawer
{
public override VisualElement CreatePropertyGUI(SerializedProperty property)
{

2
com.unity.perception/Editor/Randomization/PropertyDrawers/ParameterDrawer.cs


namespace UnityEngine.Perception.Randomization.Editor.PropertyDrawers
{
[CustomPropertyDrawer(typeof(Parameter), true)]
public class ParameterDrawer : PropertyDrawer
class ParameterDrawer : PropertyDrawer
{
public override VisualElement CreatePropertyGUI(SerializedProperty property)
{

2
com.unity.perception/Editor/Randomization/VisualElements/ParameterListItemElement.cs


FillPropertySelectMenu();
var frequencyField = this.Q<EnumField>("application-frequency");
frequencyField.Init(ParameterApplicationFrequency.OnIterationStart);
frequencyField.Init(ParameterApplicationFrequency.EveryIteration);
var applicationFrequency = m_Target.FindPropertyRelative("applicationFrequency");
frequencyField.BindProperty(applicationFrequency);

15
com.unity.perception/Runtime/Randomization/ParameterBehaviours/Configuration/ParameterList.cs


{
[SerializeReference] internal List<ParameterListItem> configuredParameters = new List<ParameterListItem>();
/// <summary>
/// The parameters contained within this ParameterList
/// </summary>
public override IEnumerable<Parameter> parameters
{
get

return null;
}
/// <summary>
/// Applies parameter samples to their targets at the start of each scenario iteration
/// </summary>
if (configParameter.target.applicationFrequency == ParameterApplicationFrequency.OnIterationStart)
if (configParameter.target.applicationFrequency == ParameterApplicationFrequency.EveryIteration)
/// <summary>
/// Applies parameter samples to their targets at the start of every frame
/// </summary>
public override void OnFrameStart()
{
foreach (var configParameter in configuredParameters)

/// <summary>
/// Validates the settings of each parameter within this ParameterList
/// </summary>
/// <exception cref="ParameterListException"></exception>
public override void Validate()
{
var parameterNames = new HashSet<string>();

8
com.unity.perception/Runtime/Randomization/ParameterBehaviours/Configuration/ParameterTarget.cs


[SerializeField] internal Component component;
[SerializeField] internal string propertyName = string.Empty;
[SerializeField] internal FieldOrProperty fieldOrProperty = FieldOrProperty.Field;
[SerializeField] internal ParameterApplicationFrequency applicationFrequency = ParameterApplicationFrequency.OnIterationStart;
[SerializeField] internal ParameterApplicationFrequency applicationFrequency = ParameterApplicationFrequency.EveryIteration;
/// <summary>
/// Assigns a new target

public enum ParameterApplicationFrequency
{
/// <summary>
/// Applies a parameter once at the beginning of every iteration
/// Applies a parameter at the beginning of every iteration
OnIterationStart,
EveryIteration,
/// Applies a parameter once every frame
/// Applies a parameter at the beginning of every frame
/// </summary>
EveryFrame
}

60
com.unity.perception/Runtime/Randomization/ParameterBehaviours/ParameterBehaviour.cs


namespace Randomization.ParameterBehaviours
{
/// <summary>
/// The base class for all randomization scripts
/// </summary>
public abstract class ParameterBehaviour : MonoBehaviour
{
static HashSet<ParameterBehaviour> s_ActiveBehaviours = new HashSet<ParameterBehaviour>();

}
}
/// <summary>
/// The parameters employed by this parameter behaviour
/// </summary>
protected virtual void OnEnable()
/// <summary>
/// This method is called when the ParameterBehaviour is enabled
/// </summary>
protected void OnEnable()
OnInitialize();
protected virtual void OnDisable()
/// <summary>
/// This method is called when the ParameterBehaviour is disabled
/// </summary>
protected void OnDisable()
protected virtual void OnInitialize() { }
/// <summary>
/// OnFrameStart is called at the start of every frame if the ParameterBehaviour is enabled
/// </summary>
/// <summary>
/// OnIterationStart is called at the start of every iteration if the ParameterBehaviour is enabled
/// </summary>
/// <summary>
/// OnIterationEnd is called at the end of every iteration if the ParameterBehaviour is enabled
/// </summary>
/// <summary>
/// Run when the scenario completes
/// </summary>
public virtual void Validate() { }
/// <summary>
/// Validate all parameters employed by this ParameterBehaviour
/// </summary>
public virtual void Validate()
{
foreach (var parameter in parameters)
parameter.Validate();
}
/// <summary>
/// Reset to default values in the Editor
/// </summary>
protected virtual void Reset()
{
foreach (var parameter in parameters)
foreach (var sampler in parameter.samplers)
sampler.baseSeed = SamplerUtility.GenerateRandomSeed();
}
/// <summary>
/// Resets the state of each sampler on every parameter used by this ParameterBehaviour
/// </summary>
internal void ResetState()
{
foreach (var parameter in parameters)

parameter.IterateState(GetInstanceID());
}
}
public virtual void Reset()
{
foreach (var parameter in parameters)
foreach (var sampler in parameter.samplers)
sampler.baseSeed = SamplerUtility.GenerateRandomSeed();
}
}
}

4
com.unity.perception/Runtime/Randomization/Parameters/NumericParameter.cs


return Sample();
}
/// <summary>
/// Validate the settings of this parameter
/// </summary>
public override void Validate()
{
base.Validate();

2
com.unity.perception/Tests/Runtime/Randomization/ScenarioTests.cs


var prevPosition = new Vector3();
transform.position = prevPosition;
configuredParameter.target.AssignNewTarget(
transform, "position", ParameterApplicationFrequency.OnIterationStart);
transform, "position", ParameterApplicationFrequency.EveryIteration);
yield return CreateNewScenario(2, 2);

44
com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/ColorParameters/ColorHsvaParameter.cs


using Unity.Burst;
using Unity.Collections;
using Unity.Jobs;
using Unity.Mathematics;
/// A numeric parameter for generating Color samples
/// A numeric parameter for generating color samples using HSVA samplers
/// </summary>
[Serializable]
public class ColorHsvaParameter : NumericParameter<Color>

for (var i = 0; i < samples.Length; i++)
samples[i] = new ColorHsva(hueRng[i], satRng[i], valRng[i], alphaRng[i]);
}
}
}
[Serializable]
public struct ColorHsva
{
public float h;
public float s;
public float v;
public float a;
public ColorHsva(float h, float s, float v, float a)
{
this.h = h;
this.s = s;
this.v = v;
this.a = a;
}
public static implicit operator float4(ColorHsva c) => new float4(c.h, c.s, c.v, c.a);
public static implicit operator ColorHsva(float4 f) => new ColorHsva(f.x, f.y, f.z, f.w);
public static implicit operator Vector4(ColorHsva c) => new float4(c.h, c.s, c.v, c.a);
public static implicit operator ColorHsva(Vector4 f) => new ColorHsva(f.x, f.y, f.z, f.w);
public static explicit operator Color(ColorHsva c)
{
var color = Color.HSVToRGB(c.h, c.s, c.v);
color.a = c.a;
return color;
}
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);
}
public override string ToString()
{
return $"ColorHsva({h}, {s}, {v}, {a})";
}
}
}

2
com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/ColorParameters/ColorRgbParameter.cs


namespace UnityEngine.Perception.Randomization.Parameters
{
/// <summary>
/// A numeric parameter for generating Color samples
/// A numeric parameter for generating RGBA color samples
/// </summary>
[Serializable]
public class ColorRgbParameter : NumericParameter<Color>

3
com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/ColorParameters.meta


fileFormatVersion: 2
guid: ce91e289cdaa4ccc849a0c287aefd34d
timeCreated: 1598326361

107
com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/ColorParameters/ColorHsva.cs


using System;
using Unity.Mathematics;
namespace UnityEngine.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})";
}
}
}

3
com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/ColorParameters/ColorHsva.cs.meta


fileFormatVersion: 2
guid: ccdce8798ec146649d4714046529de2c
timeCreated: 1598326388

10
com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/ColorParameters/ColorHsvaCategoricalParameter.cs


using System;
namespace UnityEngine.Perception.Randomization.Parameters
{
/// <summary>
/// A categorical parameter for generating ColorHsva samples
/// </summary>
[Serializable]
public class ColorHsvaCategoricalParameter : CategoricalParameter<ColorHsva> { }
}

10
com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/ColorParameters/ColorRgbCategoricalParameter.cs


using System;
namespace UnityEngine.Perception.Randomization.Parameters
{
/// <summary>
/// A categorical parameter for generating RGBA color samples
/// </summary>
[Serializable]
public class ColorRgbCategoricalParameter : CategoricalParameter<Color> { }
}

7
com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/ColorHsvaCategoricalParameter.cs


using System;
namespace UnityEngine.Perception.Randomization.Parameters
{
[Serializable]
public class ColorHsvaCategoricalParameter : CategoricalParameter<ColorHsva> { }
}

7
com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/ColorRgbCategoricalParameter.cs


using System;
namespace UnityEngine.Perception.Randomization.Parameters
{
[Serializable]
public class ColorRgbCategoricalParameter : CategoricalParameter<Color> { }
}

/com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/ColorHsvaParameter.cs.meta → /com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/ColorParameters/ColorHsvaParameter.cs.meta

/com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/ColorHsvaCategoricalParameter.cs.meta → /com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/ColorParameters/ColorHsvaCategoricalParameter.cs.meta

/com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/ColorHsvaParameter.cs → /com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/ColorParameters/ColorHsvaParameter.cs

/com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/ColorRgbCategoricalParameter.cs.meta → /com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/ColorParameters/ColorRgbCategoricalParameter.cs.meta

/com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/ColorRgbParameter.cs → /com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/ColorParameters/ColorRgbParameter.cs

/com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/ColorRgbParameter.cs.meta → /com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/ColorParameters/ColorRgbParameter.cs.meta

正在加载...
取消
保存