Neodroid  0.2.0
Machine Learning Environment Prototyping Tool
SimulationConfigurable.cs
Go to the documentation of this file.
1 using System;
7 using UnityEngine;
8 
9 namespace droid.Runtime.Prototyping.Configurables {
13  [AddComponentMenu(ConfigurableComponentMenuPath._ComponentMenuPath
14  + "Simulation"
15  + ConfigurableComponentMenuPath._Postfix)]
16  [RequireComponent(typeof(PausableManager))]
18  string _fullscreen;
19  string _height;
20 
21  string _quality_level;
22  string _target_frame_rate;
23  string _time_scale;
24  string _width;
25 
28  public override string PrototypingTypeName { get { return "SimulationConfigurable"; } }
29 
32  protected override void PreSetup() {
33  this._quality_level = this.Identifier + "QualityLevel";
34  this._target_frame_rate = this.Identifier + "TargetFrameRate";
35  this._time_scale = this.Identifier + "TimeScale";
36  this._width = this.Identifier + "Width";
37  this._height = this.Identifier + "Height";
38  this._fullscreen = this.Identifier + "Fullscreen";
39  }
40 
43  protected override void RegisterComponent() {
44  this.ParentEnvironment =
45  NeodroidUtilities.RegisterComponent(this.ParentEnvironment,
46  (Configurable)this,
47  this._quality_level);
48  this.ParentEnvironment =
49  NeodroidUtilities.RegisterComponent(this.ParentEnvironment,
50  (Configurable)this,
51  this._target_frame_rate);
52  this.ParentEnvironment =
53  NeodroidUtilities.RegisterComponent(this.ParentEnvironment, (Configurable)this, this._width);
54  this.ParentEnvironment =
55  NeodroidUtilities.RegisterComponent(this.ParentEnvironment, (Configurable)this, this._height);
56  this.ParentEnvironment =
57  NeodroidUtilities.RegisterComponent(this.ParentEnvironment, (Configurable)this, this._fullscreen);
58  this.ParentEnvironment =
59  NeodroidUtilities.RegisterComponent(this.ParentEnvironment, (Configurable)this, this._time_scale);
60  }
61 
64  protected override void UnRegisterComponent() {
65  if (this.ParentEnvironment == null) {
66  return;
67  }
68 
69  this.ParentEnvironment.UnRegister(this, this._quality_level);
70  this.ParentEnvironment.UnRegister(this, this._target_frame_rate);
71  this.ParentEnvironment.UnRegister(this, this._time_scale);
72  this.ParentEnvironment.UnRegister(this, this._width);
73  this.ParentEnvironment.UnRegister(this, this._height);
74  this.ParentEnvironment.UnRegister(this, this._fullscreen);
75  }
76 
77  public override ISpace ConfigurableValueSpace { get; }
78 
82  public override void ApplyConfiguration(IConfigurableConfiguration simulator_configuration) {
83  #if NEODROID_DEBUG
84  if (this.Debugging) {
85  Debug.Log("Applying " + simulator_configuration + " To " + this.Identifier);
86  }
87  #endif
88 
89  if (simulator_configuration.ConfigurableName == this._quality_level) {
90  QualitySettings.SetQualityLevel((int)simulator_configuration.ConfigurableValue, true);
91  } else if (simulator_configuration.ConfigurableName == this._target_frame_rate) {
92  Application.targetFrameRate = (int)simulator_configuration.ConfigurableValue;
93  } else if (simulator_configuration.ConfigurableName == this._width) {
94  Screen.SetResolution((int)simulator_configuration.ConfigurableValue, Screen.height, false);
95  } else if (simulator_configuration.ConfigurableName == this._height) {
96  Screen.SetResolution(Screen.width, (int)simulator_configuration.ConfigurableValue, false);
97  } else if (simulator_configuration.ConfigurableName == this._fullscreen) {
98  Screen.SetResolution(Screen.width,
99  Screen.height,
100  (int)simulator_configuration.ConfigurableValue != 0);
101  } else if (simulator_configuration.ConfigurableName == this._time_scale) {
102  Time.timeScale = simulator_configuration.ConfigurableValue;
103  }
104  }
105 
110  public override Configuration[] SampleConfigurations() {
111  return new[] {new Configuration(this._time_scale, Space1.ZeroOne.Sample())};
112  }
113  }
114 }
override void ApplyConfiguration(IConfigurableConfiguration simulator_configuration)