浏览代码
Enable the switching of scene to control mode, load the corresponding scene using environment variable (#1956)
Enable the switching of scene to control mode, load the corresponding scene using environment variable (#1956)
* Added the builder script * Removed the menu item * Changed the brainToControl to public * Added the scene for switching * Modified according to the comments * Removed the Builder and BuilderUtils script, made all of the logic into the Startup.cs * Switched back to the previous way using PreExport method * Added the return at the EOF. * Resolved the codacy comments. * Removed one empty line * Resolved the 2 round comments/develop-generalizationTraining-TrainerController
GitHub
6 年前
当前提交
d0efc956
共有 10 个文件被更改,包括 274 次插入 和 0 次删除
-
14UnitySDK/Assets/ML-Agents/Editor/Builder.cs
-
3UnitySDK/Assets/ML-Agents/Editor/Builder.cs.meta
-
44UnitySDK/Assets/ML-Agents/Editor/BuilderUtils.cs
-
3UnitySDK/Assets/ML-Agents/Editor/BuilderUtils.cs.meta
-
8UnitySDK/Assets/ML-Agents/Examples/Startup.meta
-
29UnitySDK/Assets/ML-Agents/Scripts/Startup.cs
-
11UnitySDK/Assets/ML-Agents/Scripts/Startup.cs.meta
-
155UnitySDK/Assets/ML-Agents/Examples/Startup/Startup.unity
-
7UnitySDK/Assets/ML-Agents/Examples/Startup/Startup.unity.meta
|
|||
#if UNITY_CLOUD_BUILD
|
|||
|
|||
namespace MLAgents |
|||
{ |
|||
public static class Builder |
|||
{ |
|||
public static void PreExport() |
|||
{ |
|||
BuilderUtils.SwitchAllLearningBrainToControlMode(); |
|||
} |
|||
} |
|||
} |
|||
|
|||
#endif
|
|
|||
fileFormatVersion: 2 |
|||
guid: 41ad366a346f4fbdaeb7dc8fff9a5025 |
|||
timeCreated: 1555622970 |
|
|||
#if UNITY_CLOUD_BUILD
|
|||
|
|||
using System.Linq; |
|||
using UnityEditor; |
|||
using UnityEditor.SceneManagement; |
|||
using UnityEngine; |
|||
using System.IO; |
|||
|
|||
namespace MLAgents |
|||
{ |
|||
public static class BuilderUtils |
|||
{ |
|||
public static void SwitchAllLearningBrainToControlMode() |
|||
{ |
|||
Debug.Log("The Switching to control mode function is triggered"); |
|||
string[] scenePaths = Directory.GetFiles("Assets/ML-Agents/Examples/", "*.unity", SearchOption.AllDirectories); |
|||
foreach (string scenePath in scenePaths) |
|||
{ |
|||
var curScene = EditorSceneManager.OpenScene(scenePath); |
|||
var aca = SceneAsset.FindObjectOfType<Academy>(); |
|||
if (aca != null) |
|||
{ |
|||
var learningBrains = aca.broadcastHub.broadcastingBrains.Where( |
|||
x => x != null && x is LearningBrain); |
|||
foreach (Brain brain in learningBrains) |
|||
{ |
|||
if (!aca.broadcastHub.IsControlled(brain)) |
|||
{ |
|||
Debug.Log("Switched brain in scene " + scenePath); |
|||
aca.broadcastHub.SetControlled(brain, true); |
|||
} |
|||
} |
|||
EditorSceneManager.SaveScene(curScene); |
|||
} |
|||
else |
|||
{ |
|||
Debug.Log("scene " + scenePath + " doesn't have a Academy in it"); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
#endif
|
|
|||
fileFormatVersion: 2 |
|||
guid: 08deb8536161410982b88716adb02f69 |
|||
timeCreated: 1555623012 |
|
|||
fileFormatVersion: 2 |
|||
guid: a5f5656214b6a4a46b061a58aa89b46c |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using System.Linq; |
|||
using UnityEngine; |
|||
using UnityEngine.SceneManagement; |
|||
|
|||
namespace MLAgents |
|||
{ |
|||
public class Startup: MonoBehaviour |
|||
{ |
|||
void Awake() |
|||
{ |
|||
string sceneName = Environment.GetEnvironmentVariable("SCENE_NAME"); |
|||
SwitchScene(sceneName); |
|||
} |
|||
|
|||
private static void SwitchScene(string sceneName) |
|||
{ |
|||
if (sceneName == null) |
|||
{ |
|||
throw new ArgumentException("You didn't specified the SCENE_NAME environment variable"); |
|||
} |
|||
if (SceneUtility.GetBuildIndexByScenePath(sceneName) < 0) |
|||
{ |
|||
throw new ArgumentException("The scene " + sceneName + " doesn't exist within your build. "); |
|||
} |
|||
SceneManager.LoadSceneAsync(sceneName); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 23f416cde2a4347bebfbe2efe69d19b8 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
%YAML 1.1 |
|||
%TAG !u! tag:unity3d.com,2011: |
|||
--- !u!29 &1 |
|||
OcclusionCullingSettings: |
|||
m_ObjectHideFlags: 0 |
|||
serializedVersion: 2 |
|||
m_OcclusionBakeSettings: |
|||
smallestOccluder: 5 |
|||
smallestHole: 0.25 |
|||
backfaceThreshold: 100 |
|||
m_SceneGUID: 00000000000000000000000000000000 |
|||
m_OcclusionCullingData: {fileID: 0} |
|||
--- !u!104 &2 |
|||
RenderSettings: |
|||
m_ObjectHideFlags: 0 |
|||
serializedVersion: 8 |
|||
m_Fog: 0 |
|||
m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1} |
|||
m_FogMode: 3 |
|||
m_FogDensity: 0.01 |
|||
m_LinearFogStart: 0 |
|||
m_LinearFogEnd: 300 |
|||
m_AmbientSkyColor: {r: 0.212, g: 0.227, b: 0.259, a: 1} |
|||
m_AmbientEquatorColor: {r: 0.114, g: 0.125, b: 0.133, a: 1} |
|||
m_AmbientGroundColor: {r: 0.047, g: 0.043, b: 0.035, a: 1} |
|||
m_AmbientIntensity: 1 |
|||
m_AmbientMode: 0 |
|||
m_SubtractiveShadowColor: {r: 0.42, g: 0.478, b: 0.627, a: 1} |
|||
m_SkyboxMaterial: {fileID: 10304, guid: 0000000000000000f000000000000000, type: 0} |
|||
m_HaloStrength: 0.5 |
|||
m_FlareStrength: 1 |
|||
m_FlareFadeSpeed: 3 |
|||
m_HaloTexture: {fileID: 0} |
|||
m_SpotCookie: {fileID: 10001, guid: 0000000000000000e000000000000000, type: 0} |
|||
m_DefaultReflectionMode: 0 |
|||
m_DefaultReflectionResolution: 128 |
|||
m_ReflectionBounces: 1 |
|||
m_ReflectionIntensity: 1 |
|||
m_CustomReflection: {fileID: 0} |
|||
m_Sun: {fileID: 0} |
|||
m_IndirectSpecularColor: {r: 0.3731316, g: 0.38074902, b: 0.3587254, a: 1} |
|||
--- !u!157 &3 |
|||
LightmapSettings: |
|||
m_ObjectHideFlags: 0 |
|||
serializedVersion: 11 |
|||
m_GIWorkflowMode: 0 |
|||
m_GISettings: |
|||
serializedVersion: 2 |
|||
m_BounceScale: 1 |
|||
m_IndirectOutputScale: 1 |
|||
m_AlbedoBoost: 1 |
|||
m_TemporalCoherenceThreshold: 1 |
|||
m_EnvironmentLightingMode: 0 |
|||
m_EnableBakedLightmaps: 1 |
|||
m_EnableRealtimeLightmaps: 1 |
|||
m_LightmapEditorSettings: |
|||
serializedVersion: 9 |
|||
m_Resolution: 2 |
|||
m_BakeResolution: 40 |
|||
m_TextureWidth: 1024 |
|||
m_TextureHeight: 1024 |
|||
m_AO: 0 |
|||
m_AOMaxDistance: 1 |
|||
m_CompAOExponent: 1 |
|||
m_CompAOExponentDirect: 0 |
|||
m_Padding: 2 |
|||
m_LightmapParameters: {fileID: 0} |
|||
m_LightmapsBakeMode: 1 |
|||
m_TextureCompression: 1 |
|||
m_FinalGather: 0 |
|||
m_FinalGatherFiltering: 1 |
|||
m_FinalGatherRayCount: 256 |
|||
m_ReflectionCompression: 2 |
|||
m_MixedBakeMode: 2 |
|||
m_BakeBackend: 0 |
|||
m_PVRSampling: 1 |
|||
m_PVRDirectSampleCount: 32 |
|||
m_PVRSampleCount: 500 |
|||
m_PVRBounces: 2 |
|||
m_PVRFilterTypeDirect: 0 |
|||
m_PVRFilterTypeIndirect: 0 |
|||
m_PVRFilterTypeAO: 0 |
|||
m_PVRFilteringMode: 1 |
|||
m_PVRCulling: 1 |
|||
m_PVRFilteringGaussRadiusDirect: 1 |
|||
m_PVRFilteringGaussRadiusIndirect: 5 |
|||
m_PVRFilteringGaussRadiusAO: 2 |
|||
m_PVRFilteringAtrousPositionSigmaDirect: 0.5 |
|||
m_PVRFilteringAtrousPositionSigmaIndirect: 2 |
|||
m_PVRFilteringAtrousPositionSigmaAO: 1 |
|||
m_ShowResolutionOverlay: 1 |
|||
m_LightingDataAsset: {fileID: 0} |
|||
m_UseShadowmask: 1 |
|||
--- !u!196 &4 |
|||
NavMeshSettings: |
|||
serializedVersion: 2 |
|||
m_ObjectHideFlags: 0 |
|||
m_BuildSettings: |
|||
serializedVersion: 2 |
|||
agentTypeID: 0 |
|||
agentRadius: 0.5 |
|||
agentHeight: 2 |
|||
agentSlope: 45 |
|||
agentClimb: 0.4 |
|||
ledgeDropHeight: 0 |
|||
maxJumpAcrossDistance: 0 |
|||
minRegionArea: 2 |
|||
manualCellSize: 0 |
|||
cellSize: 0.16666667 |
|||
manualTileSize: 0 |
|||
tileSize: 256 |
|||
accuratePlacement: 0 |
|||
debug: |
|||
m_Flags: 0 |
|||
m_NavMeshData: {fileID: 0} |
|||
--- !u!1 &520360983 |
|||
GameObject: |
|||
m_ObjectHideFlags: 0 |
|||
m_PrefabParentObject: {fileID: 0} |
|||
m_PrefabInternal: {fileID: 0} |
|||
serializedVersion: 5 |
|||
m_Component: |
|||
- component: {fileID: 520360985} |
|||
- component: {fileID: 520360984} |
|||
m_Layer: 0 |
|||
m_Name: GameObject |
|||
m_TagString: Untagged |
|||
m_Icon: {fileID: 0} |
|||
m_NavMeshLayer: 0 |
|||
m_StaticEditorFlags: 0 |
|||
m_IsActive: 1 |
|||
--- !u!114 &520360984 |
|||
MonoBehaviour: |
|||
m_ObjectHideFlags: 0 |
|||
m_PrefabParentObject: {fileID: 0} |
|||
m_PrefabInternal: {fileID: 0} |
|||
m_GameObject: {fileID: 520360983} |
|||
m_Enabled: 1 |
|||
m_EditorHideFlags: 0 |
|||
m_Script: {fileID: 11500000, guid: 23f416cde2a4347bebfbe2efe69d19b8, type: 3} |
|||
m_Name: |
|||
m_EditorClassIdentifier: |
|||
--- !u!4 &520360985 |
|||
Transform: |
|||
m_ObjectHideFlags: 0 |
|||
m_PrefabParentObject: {fileID: 0} |
|||
m_PrefabInternal: {fileID: 0} |
|||
m_GameObject: {fileID: 520360983} |
|||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} |
|||
m_LocalPosition: {x: 0, y: 0, z: 0} |
|||
m_LocalScale: {x: 1, y: 1, z: 1} |
|||
m_Children: [] |
|||
m_Father: {fileID: 0} |
|||
m_RootOrder: 0 |
|||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} |
|
|||
fileFormatVersion: 2 |
|||
guid: 4e253b26ff06f4e22aba1d43ed181ada |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue