https://github.com/reinforcement-learning-kr/Unity_ML_Agents_2.0/tree/main/unity_project
Unity_ML_Agents_2.0/unity_project at main · reinforcement-learning-kr/Unity_ML_Agents_2.0
Repository for implementing Unity ML-Agents 2.0 . Contribute to reinforcement-learning-kr/Unity_ML_Agents_2.0 development by creating an account on GitHub.
github.com
DAgent, DScene, DBall, DArea 4개의 스크립트를 만들어 해당되는 곳에 끌어다 놓습니다. 스크립트이름 앞에 D를 붙인건 Example프로젝트가 많아 중복되는걸 방지하기 위해서 입니다.
맨먼저 DScene.cs를 더블클릭합니다.
AreaNums수 만큼 for문을 돌려 Area Prefab을 생성합니다. 3 x 3개의 Area를 생성합니다. 랜덤 초기화는 Area.cs에서 실행합니다.
AreaNums는 파이썬을 통해 얻어 옵니다. 파이썬 코드에서 설정한 환경파라미터 딕셔너리의 키와 밸류를 GetWidthDefault 로 불러와서 설정합니다.
using System.Collections;
using System.Collections.Generic;
//ML Agent에 필요한 네임스페이스를 설정합니다.
using UnityEngine;
using Unity.MLAgents;
using System.Drawing.Text;
public class DodgeScene : MonoBehaviour
{
public GameObject areaObj = null; //Areal Prefab
private int AreaNums = 9; //분산학습을 위한 환경 총개수
private int rows = 3;
private int interval = 16;
//환경파라미터를 설정하기 위한 변수
EnvironmentParameters m_ResetParams = null;
void Start()
{
//파이썬 코드내 파라미터를 연동시킬수 있습니다.
m_ResetParams = Academy.Instance.EnvironmentParameters;
AreaNums = (int)m_ResetParams.GetWithDefault("AreaNums", AreaNums);
float x = 0;
float z = 0;
for (int i = 0; i < AreaNums; i++)
{
GameObject areaPrefab = Instantiate(areaObj, transform);
if (i % rows == 0 && i != 0)
{
x = 0;
z += interval;
}
areaPrefab.transform.position = new Vector3(x, 0, z);
x += interval;
}
}
}'강화학습 > ML-Agent Unity' 카테고리의 다른 글
| Agent Script - Dodge (0) | 2025.04.28 |
|---|---|
| Dodge Ball Script (0) | 2025.04.28 |
| Dodge 씬 구성 - Unity ML Agent (0) | 2025.04.28 |
| 2차 환경제작 (0) | 2024.08.19 |
| Python 가상환경 종류 (1) | 2024.08.18 |