Steven Leal
4 年前
当前提交
62e505d4
共有 12 个文件被更改,包括 333 次插入 和 38 次删除
-
194com.unity.perception/Editor/Randomization/RunInUSimWindow.cs
-
15com.unity.perception/Editor/Randomization/Uxml/RunInUSimWindow.uxml
-
3com.unity.perception/Editor/Unity.Perception.Editor.asmdef
-
7com.unity.perception/Runtime/Randomization/Scenarios/Scenario.cs
-
10com.unity.perception/Runtime/Randomization/Scenarios/ScenarioBase.cs
-
1com.unity.perception/Tests/Runtime/Randomization/ScenarioTests.cs
-
59com.unity.perception/Editor/Randomization/PositiveIntegerField.cs
-
3com.unity.perception/Editor/Randomization/PositiveIntegerField.cs.meta
-
30com.unity.perception/Runtime/Randomization/Scenarios/FixedFrameCountScenario.cs
-
3com.unity.perception/Runtime/Randomization/Scenarios/FixedFrameCountScenario.cs.meta
-
43com.unity.perception/Runtime/Randomization/Scenarios/USimScenario.cs
-
3com.unity.perception/Runtime/Randomization/Scenarios/USimScenario.cs.meta
|
|||
<UXML xmlns="UnityEngine.UIElements" xmlns:editor="UnityEditor.UIElements"> |
|||
<UXML xmlns="UnityEngine.UIElements" xmlns:editor="UnityEditor.UIElements" xmlns:randEditor="UnityEngine.Perception.Randomization.Editor"> |
|||
<editor:ObjectField allow-scene-objects="false" bindingPath="m_MainScene"/> |
|||
<TextField name="run-name" label="Run Name"/> |
|||
<randEditor:PositiveIntegerField name="total-iterations" label="Total Iterations"/> |
|||
<randEditor:PositiveIntegerField name="instance-count" label="Instance Count" max-value="10000"/> |
|||
<editor:ObjectField name="main-scene" label="Main Scene" allow-scene-objects="false"/> |
|||
<editor:ObjectField name="scenario" label="Scenario"/> |
|||
<VisualElement class="unity-base-field"> |
|||
<Label text="USim worker config" class="unity-base-field__label"/> |
|||
<editor:ToolbarMenu name="sys-param" class="unity-base-field__input" style="border-width: 1px;"/> |
|||
</VisualElement> |
|||
<VisualElement style="align-items: center;"> |
|||
<Button name="run-button" text="Build and Run" style="margin-top: 20px; padding: 2 20; font-size: 13px;"/> |
|||
</VisualElement> |
|||
</VisualElement> |
|||
</UXML> |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using Unity.Mathematics; |
|||
using UnityEditor; |
|||
using UnityEditor.UIElements; |
|||
using UnityEngine.UIElements; |
|||
|
|||
namespace UnityEngine.Perception.Randomization.Editor |
|||
{ |
|||
public class PositiveIntegerField : IntegerField |
|||
{ |
|||
public int maxValue = int.MaxValue; |
|||
|
|||
public PositiveIntegerField() |
|||
{ |
|||
RegisterValueClamping(); |
|||
} |
|||
|
|||
public PositiveIntegerField(int maxValue) |
|||
{ |
|||
this.maxValue = maxValue; |
|||
RegisterValueClamping(); |
|||
} |
|||
|
|||
public PositiveIntegerField(SerializedProperty property, int maxValue=int.MaxValue) : this(maxValue) |
|||
{ |
|||
this.BindProperty(property); |
|||
} |
|||
|
|||
void RegisterValueClamping() |
|||
{ |
|||
this.RegisterValueChangedCallback(evt => |
|||
{ |
|||
value = math.clamp(evt.newValue, 0, maxValue); |
|||
evt.StopImmediatePropagation(); |
|||
}); |
|||
} |
|||
|
|||
public new class UxmlFactory : UxmlFactory<PositiveIntegerField, UxmlTraits> { } |
|||
|
|||
public new class UxmlTraits : IntegerField.UxmlTraits |
|||
{ |
|||
UxmlIntAttributeDescription m_Int = new UxmlIntAttributeDescription { name = "max-value", defaultValue = int.MaxValue }; |
|||
|
|||
public override IEnumerable<UxmlChildElementDescription> uxmlChildElementsDescription |
|||
{ |
|||
get { yield break; } |
|||
} |
|||
|
|||
public override void Init(VisualElement ve, IUxmlAttributes bag, CreationContext cc) |
|||
{ |
|||
base.Init(ve, bag, cc); |
|||
if (!(ve is PositiveIntegerField positiveIntegerField)) |
|||
return; |
|||
positiveIntegerField.maxValue = m_Int.GetValueFromBag(bag, cc); |
|||
} |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: ddab76638f764bac9bd4b213e5cf8ebe |
|||
timeCreated: 1597168414 |
|
|||
using System; |
|||
|
|||
namespace UnityEngine.Perception.Randomization.Scenarios |
|||
{ |
|||
/// <summary>
|
|||
/// An example scenario where each iteration runs for a fixed number of frames
|
|||
/// </summary>
|
|||
[AddComponentMenu("Randomization/Scenarios/Fixed Frame Count Scenario")] |
|||
public class FixedFrameCountScenario : USimScenario |
|||
{ |
|||
public int framesPerIteration; |
|||
|
|||
public override bool isIterationComplete => currentIterationFrame >= framesPerIteration; |
|||
|
|||
public FixedFrameCountScenario() |
|||
{ |
|||
constants = new USimConstants |
|||
{ |
|||
instanceCount = 1, |
|||
instanceIndex = 0, |
|||
totalIterations = 1000 |
|||
}; |
|||
} |
|||
|
|||
public override void OnInitialize() |
|||
{ |
|||
currentIteration = constants.instanceIndex; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: a5fd9d0784580a747b3764afd636fc5f |
|||
timeCreated: 1589939921 |
|
|||
using System; |
|||
|
|||
namespace UnityEngine.Perception.Randomization.Scenarios |
|||
{ |
|||
public abstract class USimScenario : Scenario<USimConstants> |
|||
{ |
|||
public override bool isScenarioComplete => currentIteration >= constants.totalIterations; |
|||
|
|||
public override void OnInitialize() |
|||
{ |
|||
currentIteration = constants.instanceIndex; |
|||
} |
|||
|
|||
public override void IncrementIteration() |
|||
{ |
|||
currentIteration += constants.instanceCount; |
|||
} |
|||
|
|||
public override void OnFrameStart() |
|||
{ |
|||
Debug.Log($"{currentIteration}: {currentIterationFrame}"); |
|||
} |
|||
|
|||
public override void Deserialize() |
|||
{ |
|||
if (!string.IsNullOrEmpty(Unity.Simulation.Configuration.Instance.SimulationConfig.app_param_uri)) |
|||
{ |
|||
Debug.Log("Reading app-params"); |
|||
constants = Unity.Simulation.Configuration.Instance.GetAppParams<USimConstants>(); |
|||
} |
|||
else |
|||
base.Deserialize(); |
|||
} |
|||
} |
|||
|
|||
[Serializable] |
|||
public struct USimConstants |
|||
{ |
|||
public int totalIterations; |
|||
public int instanceCount; |
|||
public int instanceIndex; |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 1ef5313c07934eeabb46b852ab57ed79 |
|||
timeCreated: 1597102599 |
撰写
预览
正在加载...
取消
保存
Reference in new issue