/
MyLightRandomizer.cs
39 lines (34 loc) · 1.2 KB
/
MyLightRandomizer.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
using System;
using UnityEngine;
using UnityEngine.Perception.Randomization.Parameters;
using UnityEngine.Perception.Randomization.Randomizers;
using UnityEngine.Perception.Randomization.Samplers;
/// <summary>
/// Randomizes the rotation of objects tagged with a LightRandomizerTag
/// </summary>
[Serializable]
[AddRandomizerMenu("Perception/My Light Randomizer")]
public class MyLightRandomizer : Randomizer
{
public FloatParameter lightIntensityParameter;
/// <summary>
/// The range of random rotations to assign to target objects
/// </summary>
[Tooltip("The range of random rotations to assign to target objects.")]
public Vector3Parameter rotation = new Vector3Parameter
{
x = new UniformSampler(0, 360),
y = new UniformSampler(0, 360),
z = new UniformSampler(0, 360)
};
protected override void OnIterationStart()
{
var tags = tagManager.Query<MyLightRandomizerTag>();
foreach (var tag in tags)
{
var light = tag.GetComponent<Light>();
light.intensity = lightIntensityParameter.Sample();
light.transform.rotation = Quaternion.Euler(rotation.Sample()); //x,y: -80:80
}
}
}