浏览代码

Added constant transform randomizer

Randomizer is useful to reset a scene's gameobjects each frame
/main
Steven Borkman 4 年前
当前提交
3dd61215
共有 4 个文件被更改,包括 48 次插入0 次删除
  1. 28
      com.unity.perception/Runtime/Randomization/Randomizers/RandomizerExamples/Randomizers/ConstantTransformRandomizer.cs
  2. 3
      com.unity.perception/Runtime/Randomization/Randomizers/RandomizerExamples/Randomizers/ConstantTransformRandomizer.cs.meta
  3. 14
      com.unity.perception/Runtime/Randomization/Randomizers/RandomizerExamples/Tags/ConstantTransformRandomizerTag.cs
  4. 3
      com.unity.perception/Runtime/Randomization/Randomizers/RandomizerExamples/Tags/ConstantTransformRandomizerTag.cs.meta

28
com.unity.perception/Runtime/Randomization/Randomizers/RandomizerExamples/Randomizers/ConstantTransformRandomizer.cs


using System;
using UnityEngine.Experimental.Perception.Randomization.Randomizers.SampleRandomizers.Tags;
namespace UnityEngine.Experimental.Perception.Randomization.Randomizers.SampleRandomizers
{
/// <summary>
/// Sets a gameobject tagged with <see cref="ConstantTransformRandomizerTag"/> to the same transform(location, rotation, scale)
/// each frame. This randomizer is useful to reset a scene to a start state, especially when used in conjunction
/// with other randomizers that may move a gameobject.
/// </summary>
[Serializable]
[AddRandomizerMenu("Perception/Constant Transform Randomizer")]
public class ConstantTransformRandomizer : Randomizer
{
/// <inheritdoc/>
protected override void OnIterationStart()
{
var taggedObjects = tagManager.Query<ConstantTransformRandomizerTag>();
foreach (var taggedObject in taggedObjects)
{
var tag = taggedObject.GetComponent<ConstantTransformRandomizerTag>();
taggedObject.transform.position = tag.position;
taggedObject.transform.rotation = tag.rotation;
taggedObject.transform.localScale = tag.scale;
}
}
}
}

3
com.unity.perception/Runtime/Randomization/Randomizers/RandomizerExamples/Randomizers/ConstantTransformRandomizer.cs.meta


fileFormatVersion: 2
guid: 6a2bb7db515c4b8bb95327b2ef6f3759
timeCreated: 1611261464

14
com.unity.perception/Runtime/Randomization/Randomizers/RandomizerExamples/Tags/ConstantTransformRandomizerTag.cs


namespace UnityEngine.Experimental.Perception.Randomization.Randomizers.SampleRandomizers.Tags
{
/// <summary>
/// Tag to indicate which gameobjects should have the effects of <see cref="ConstantTransformRandomizer"/> applied
/// to them.
/// </summary>
[AddComponentMenu("Perception/RandomizerTags/Constant Transform Randomizer Tag")]
public class ConstantTransformRandomizerTag : RandomizerTag
{
public Vector3 position = Vector3.zero;
public Quaternion rotation;
public Vector3 scale = Vector3.one;
}
}

3
com.unity.perception/Runtime/Randomization/Randomizers/RandomizerExamples/Tags/ConstantTransformRandomizerTag.cs.meta


fileFormatVersion: 2
guid: 4577b7dd026b4d69b2077ac01df61342
timeCreated: 1611261493
正在加载...
取消
保存