浏览代码

fixed scenario UI for configuration asset

/generic-asset-sources
sleal-unity 4 年前
当前提交
bab36e16
共有 4 个文件被更改,包括 21 次插入30 次删除
  1. 2
      com.unity.perception/Editor/Randomization/Editors/ScenarioBaseEditor.cs
  2. 7
      com.unity.perception/Editor/Randomization/Uxml/ScenarioBaseElement.uxml
  3. 38
      com.unity.perception/Runtime/Randomization/Randomizers/AssetSources/AssetSource.cs
  4. 4
      com.unity.perception/Runtime/Randomization/Scenarios/ScenarioBase.cs

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


m_HasConstantsField = true;
UIElementsEditorUtilities.CreatePropertyFields(iterator.Copy(), m_ConstantsListVisualContainer);
break;
case "configuration":
break;
default:
{
foundProperties = true;

7
com.unity.perception/Editor/Randomization/Uxml/ScenarioBaseElement.uxml


class="scenario__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="constants-container">
<editor:PropertyField
name="configuration-asset"
label="Configuration"
binding-path="configuration"
style="margin-left: 13 px;"
tooltip="References a JSON configuration text asset to load at runtime before the scenario starts executing. Scenario configuration files can be created using the Generate JSON Config button below."/>
<editor:PropertyField name="configuration-file-name" label="Constants File Name" binding-path="serializedConstantsFileName"/>
<VisualElement style="flex-direction: row;">
<Button name="generate-json-config" text="Generate JSON Config" style="flex-grow: 1;"
tooltip="Serializes scenario constants and randomizer settings to a JSON configuration file"/>

38
com.unity.perception/Runtime/Randomization/Randomizers/AssetSources/AssetSource.cs


[SerializeReference] public AssetSourceLocation assetSourceLocation = new LocalAssetSourceLocation();
bool m_Initialized;
UniformSampler m_Sampler = new UniformSampler();
/// <summary>
/// The archetype used to preprocess assets from this source

public int Count => assetSourceLocation.Count;
/// <summary>
/// Execute setup steps for this AssetSource
/// Execute setup steps for this AssetSource. It is often unnecessary to call this API directly since all other
/// relevant APIs in this class will Initialize() this AssetSource if it hasn't been already.
assetSourceLocation.Initialize(archetype);
m_Initialized = true;
if (!m_Initialized)
{
assetSourceLocation.Initialize(archetype);
m_Initialized = true;
}
}
/// <summary>

public T LoadRawAsset(int index)
{
CheckIfInitialized();
if (Count == 0)
return null;
return assetSourceLocation.LoadAsset<T>(index);
}

/// <returns>All assets that can be loaded from this AssetSource</returns>
public T[] LoadAllRawAssets()
{
CheckIfInitialized();
var array = new T[Count];
for (var i = 0; i < Count; i++)
array[i] = LoadRawAsset(i);

/// <returns>Instantiated instances from every loadable asset</returns>
public T[] CreateProcessedInstances()
{
CheckIfInitialized();
}
/// <summary>
/// Returns a uniformly random sampled asset from this AssetSource
/// </summary>
/// <returns>The randomly sampled asset</returns>
public T SampleAsset()
{
CheckIfInitialized();
if (Count == 0)
return null;
return assetSourceLocation.LoadAsset<T>((int)(m_Sampler.Sample() * Count));
}
/// <summary>
/// Instantiates and preprocesses a uniformly random sampled asset from this AssetSource
/// </summary>
/// <returns>The generated random instance</returns>
public T SampleInstance()
{
CheckIfInitialized();
return CreateProcessedInstance(SampleAsset());
}
/// <summary>

4
com.unity.perception/Runtime/Randomization/Scenarios/ScenarioBase.cs


/// <summary>
/// The list of randomizers managed by this scenario
/// </summary>
[HideInInspector, SerializeReference] List<Randomizer> m_Randomizers = new List<Randomizer>();
[SerializeReference] List<Randomizer> m_Randomizers = new List<Randomizer>();
[HideInInspector] public TextAsset configuration;
public TextAsset configuration;
/// <summary>
/// Enumerates over all enabled randomizers

正在加载...
取消
保存