Neodroid  0.2.0
Machine Learning Environment Prototyping Tool
ChildSelectorConfigurable.cs
Go to the documentation of this file.
1 using Boo.Lang;
4 using UnityEngine;
5 
6 namespace droid.Runtime.Prototyping.Configurables {
10  [AddComponentMenu(ConfigurableComponentMenuPath._ComponentMenuPath
11  + "ChildSelector"
12  + ConfigurableComponentMenuPath._Postfix)]
15  [SerializeField] GameObject active;
16  [SerializeField] GameObject[] children;
17  [SerializeField] int len;
18 
22  public override void PostEnvironmentSetup() {
23  if (!Application.isPlaying) {
24  return;
25  }
26 
27  var la = new List<GameObject>();
28  foreach (Transform child in this.transform) {
29  var o = child.gameObject;
30  o.SetActive(false);
31  this.active = o;
32  la.Add(o);
33  }
34 
35  this.children = la.ToArray();
36 
37  this.len = this.transform.childCount;
38 
39  this.active.SetActive(true);
40  }
41 
42  public override ISpace ConfigurableValueSpace { get; }
43 
48  public override void ApplyConfiguration(IConfigurableConfiguration configuration) {
49  if (!Application.isPlaying) {
50  return;
51  }
52 
53  if (this.active) {
54  this.active.SetActive(false);
55  }
56 
57  if (this.children != null && (int)configuration.ConfigurableValue < this.len) {
58  this.CurrentCategoryValue = (int)configuration.ConfigurableValue;
59  this.active = this.children[this.CurrentCategoryValue];
60  }
61 
62  this.active.SetActive(true);
63  }
64 
65  public override Configuration[] SampleConfigurations() {
66  return new[] {new Configuration(this.Identifier, int.Parse(Random.Range(0, this.len).ToString()))};
67  }
68 
69  public int CurrentCategoryValue { get; set; }
70  }
71 }
override void ApplyConfiguration(IConfigurableConfiguration configuration)