// Use this for initialization void Start() { rayPerception = GetComponent <MLAgents.RayPerception>(); AwayNetObservable.RegisterObserver(this); HomeNetObservable.RegisterObserver(this); startingPosition = this.transform.position; startingRotation = this.transform.rotation; academy = FindObjectOfType <MLAgents.Academy>(); rigidBody = GetComponent <Rigidbody>(); }
/// Monobehavior function that is called when the attached GameObject /// becomes enabled or active. void OnEnable() { textureArray = new Texture2D[agentParameters.agentCameras.Count]; for (int i = 0; i < agentParameters.agentCameras.Count; i++) { textureArray[i] = new Texture2D(1, 1, TextureFormat.RGB24, false); } id = gameObject.GetInstanceID(); Academy academy = Object.FindObjectOfType <Academy>() as Academy; OnEnableHelper(academy); }
/// Monobehavior function that is called when the attached GameObject /// becomes disabled or inactive. void OnDisable() { Academy academy = Object.FindObjectOfType <Academy>() as Academy; if (academy != null) { academy.AgentSetStatus -= SetStatus; academy.AgentResetIfDone -= ResetIfDone; academy.AgentSendState -= SendInfo; academy.AgentAct -= AgentStep; academy.AgentForceReset -= _AgentReset; } }
/// Monobehavior function that is called when the attached GameObject /// becomes enabled or active. void OnEnable() { textureArray = new Texture2D[agentParameters.agentCameras.Count]; for (int i = 0; i < brain.brainParameters.cameraResolutions.Length; i++) { textureArray[i] = new Texture2D(brain.brainParameters.cameraResolutions[i].width, brain.brainParameters.cameraResolutions[i].height, TextureFormat.RGB24, false); } id = gameObject.GetInstanceID(); Academy academy = Object.FindObjectOfType <Academy>() as Academy; OnEnableHelper(academy); }
void OnCollisionEnter(Collision collision) { if (collision.collider.CompareTag(Tags.SOCCER_BALL)) { notify(); // TODO: move this somewhere else // if a goal is scored, reset unless it's dribble mode. Then, just ignore. MLAgents.Academy academy = GameObject.FindGameObjectWithTag(Tags.ACADEMY).GetComponentInChildren <MLAgents.Academy>(); if (academy.resetParameters.Count > 0 && (academy.resetParameters[ResetParameters.ADD_ENEMIES] >= 1.0f || academy.resetParameters[ResetParameters.ADD_OBSTACLES] >= 1.0f)) { //academy.Done(); } } }
/// Monobehavior function that is called when the attached GameObject /// becomes enabled or active. void Start() { var textureCount = agentParameters.agentCameras.Count + agentParameters.agentRenderTextures.Count; textureArray = new Texture2D[textureCount]; for (int i = 0; i < textureCount; i++) { textureArray[i] = new Texture2D(1, 1, TextureFormat.RGB24, false); } id = gameObject.GetInstanceID(); Academy academy = Object.FindObjectOfType <Academy>() as Academy; OnEnableHelper(academy); recorder = GetComponent <DemonstrationRecorder>(); }
private void Awake() { movieRecorder = GetComponent <MovieRecorder>(); academy = FindObjectOfType <Academy>(); Camera mCamera = GetComponent <Camera>(); RenderTexture rt = new RenderTexture(resolutionWidth, resolutionHeight, 16, RenderTextureFormat.ARGB32); mCamera.targetTexture = rt; movieRecorder.targetRT = rt; movieRecorder.outputDir = new DataPath(DataPath.Root.Absolute, outputDirectory); movieRecorder.captureAudio = captureAudio; movieRecorder.resolutionUnit = RecorderBase.ResolutionUnit.Percent; movieRecorder.resolutionPercent = 100; movieRecorder.captureControl = RecorderBase.CaptureControl.Manual; movieRecorder.framerateMode = RecorderBase.FrameRateMode.Constant; movieRecorder.fixDeltaTime = false; movieRecorder.waitDeltaTime = false; }
void Awake() { academy = GetComponent <Academy>(); envIds = academy.agentSpawner.spawnableEnvDefinitions.Select(x => x.envId).ToArray(); fontSize = 26; if (Screen.height < 720) { fontSize /= 2; } heightRequirments = (fontSize + 4) * (envIds.Length + 1); if (envIdIdex == -1) { var envId = academy.GetAgentId(); var envDef = academy.agentSpawner.spawnableEnvDefinitions.FirstOrDefault(x => x.envId == envId); envIdIdex = academy.agentSpawner.spawnableEnvDefinitions.IndexOf(envDef); } // exit if we should not dispplay the menu if (academy.ShouldInitalizeOnAwake()) { return; } showPopUp = true; }
/// Helper method for the <see cref="OnEnable"/> event, created to /// facilitate testing. void OnEnableHelper(Academy academy) { m_Info = new AgentInfo(); m_Action = new AgentAction(); m_Sensors = new List <ISensor>(); if (academy == null) { throw new UnityAgentsException( "No Academy Component could be found in the scene."); } academy.AgentSetStatus += SetStatus; academy.AgentResetIfDone += ResetIfDone; academy.AgentSendState += SendInfo; academy.DecideAction += DecideAction; academy.AgentAct += AgentStep; academy.AgentForceReset += _AgentReset; m_PolicyFactory = GetComponent <BehaviorParameters>(); m_Brain = m_PolicyFactory.GeneratePolicy(Heuristic); ResetData(); InitializeAgent(); InitializeSensors(); }
/// Monobehavior function that is called when the attached GameObject /// becomes enabled or active. void OnEnable() { /// Modified by M.Baske to enable frame-stacking. /// /// Changing /// textureArray = new Texture2D[agentParameters.agentCameras.Count]; /// to textureArray = new Texture2D[brain.brainParameters.cameraResolutions.Length]; /// to prevent a runtime error since agentCameras.Count no longer /// matches cameraResolutions.Length /// /// textureArray is not used with frame-stacking. It is replaced by /// TextureManager's input property. for (int i = 0; i < brain.brainParameters.cameraResolutions.Length; i++) { textureArray[i] = new Texture2D(brain.brainParameters.cameraResolutions[i].width, brain.brainParameters.cameraResolutions[i].height, TextureFormat.RGB24, false); } id = gameObject.GetInstanceID(); Academy academy = Object.FindObjectOfType <Academy>() as Academy; OnEnableHelper(academy); }
public override void AgentReset() { hasTouchedBall = false; if (academy == null) { academy = FindObjectOfType <MLAgents.Academy>(); } if (academy.resetParameters.Count > 0) { if (academy.resetParameters[ResetParameters.THREE_V_THREE] >= 1f) { practiceMode = PRACTICE_MODE.THREE_V_THREE; } else if (academy.resetParameters[ResetParameters.ADD_ENEMIES] >= 1.0f) { practiceMode = PRACTICE_MODE.MATCH; } else if (academy.resetParameters[ResetParameters.ADD_OBSTACLES] >= 1.0f) { practiceMode = PRACTICE_MODE.AVOID_OBSTACLES; } else { practiceMode = PRACTICE_MODE.DRIBBLE; } } const float PADDING = 0.5f; float maxWidthStartingPosition = (stadiumMetadata.GetWidth() / 2.0f) - PADDING; if (practiceMode == PRACTICE_MODE.DRIBBLE) { float minDistanceFromBall = 1f; float currentDistanceFromBall = Mathf.Clamp(academy.resetParameters[ResetParameters.START_DISTANCE_FROM_BALL], minDistanceFromBall, maxWidthStartingPosition); this.transform.position = this.transform.parent.position + transform.TransformDirection(PolarToCartesian(currentDistanceFromBall, Random.Range(0, 359))) + new Vector3(0f, 0.5f, 0f); SetRandomXZRotation(); } else if (practiceMode == PRACTICE_MODE.AVOID_OBSTACLES) { //Vector3 avoidObstaclesStartingPosition = startingPosition; //avoidObstaclesStartingPosition.z = Random.Range(-maxWidthStartingPosition, maxWidthStartingPosition); //const float avoidObstaclesStartingXPosition = 2f; // position bot in middle of obstacles //avoidObstaclesStartingPosition.x = avoidObstaclesStartingPosition.x + avoidObstaclesStartingXPosition; //transform.position = avoidObstaclesStartingPosition; //SetRandomXZRotation(); transform.position = startingPosition; transform.rotation = startingRotation; } else if (practiceMode == PRACTICE_MODE.MATCH || practiceMode == PRACTICE_MODE.THREE_V_THREE) { if (academy.resetParameters[ResetParameters.START_RANDOM_Z] >= 1f) { Vector3 startingPositionRandomZ = startingPosition; startingPositionRandomZ.z = Random.Range(-maxWidthStartingPosition, maxWidthStartingPosition); this.transform.position = startingPositionRandomZ; } else { this.transform.position = startingPosition; } this.transform.rotation = startingRotation; } else { Debug.LogWarning("No mode detected"); } this.rigidBody.angularVelocity = Vector3.zero; this.rigidBody.velocity = Vector3.zero; notify(); }
/// <summary> /// Monobehavior function called at the very beginning of environment /// creation. Academy uses this time to initialize internal data /// structures, initialize the environment and check for the existence /// of a communicator. /// </summary> public virtual void Awake() { Instance = this; InitializeEnvironment(); }
/// <summary> /// Initializes the agent, called once when the agent is enabled. Can be /// left empty if there is no special, unique set-up behavior for the /// agent. /// </summary> /// <remarks> /// One sample use is to store local references to other objects in the /// scene which would facilitate computing this agents observation. /// </remarks> public virtual void InitializeAgent(Academy academy) { }