Add ParameterContainer
Add Parameter Container. make environment parameter adjustment easier.
This commit is contained in:
@@ -15,6 +15,7 @@ using System.Linq;
|
||||
|
||||
public class AgentWithGun : Agent
|
||||
{
|
||||
public GameObject ParameterContainerObj;
|
||||
public GameObject EnviromentObj;
|
||||
public GameObject EnemyContainerObj;
|
||||
public GameObject thisAgentObj;
|
||||
@@ -30,34 +31,6 @@ public class AgentWithGun : Agent
|
||||
public GameObject edgeAgent_Enemy;
|
||||
|
||||
|
||||
[Header("Rewards")]
|
||||
[Tooltip("Nothing happened reward")]
|
||||
public float nonRewardDefault = -0.05f;
|
||||
[Tooltip("Agent Do shoot action reward")]
|
||||
public float shootRewardDefault = -0.1f;
|
||||
[Tooltip("Agent Do shoot action but gun is not read")]
|
||||
public float shootWithoutReadyRewardDefault = -0.15f;
|
||||
[Tooltip("Hit Enemy reward")]
|
||||
public float hitRewardDefault = 2.0f;
|
||||
[Tooltip("Episode Win reward")]
|
||||
public float winRewardDefault = 10.0f;
|
||||
[Tooltip("Episode Lose reward")]
|
||||
public float loseRewardDefault = -0.05f;
|
||||
[Tooltip("Enemy down reward")]
|
||||
public float killRewardDefault = 5.0f;
|
||||
[Tooltip("Kill bonus reward stack to nothing happend reward")]
|
||||
public float killBonusRewardDefault = 1.0f;
|
||||
|
||||
[Header("Env")]
|
||||
public bool lockMouse = false;
|
||||
public float Damage = 50; // damage to enemy
|
||||
public float fireRate = 0.5f;
|
||||
public int enemyNum = 3;
|
||||
public int timeLimit = 30;
|
||||
public bool lockCameraX = false;
|
||||
public bool lockCameraY = true;
|
||||
//public Vector3 startPosition = new Vector3(9, 1, 18);
|
||||
|
||||
[Header("GetAxis() Simulate")]
|
||||
public float MoveSpeed = 2.0f;
|
||||
public float vX = 0f;
|
||||
@@ -67,6 +40,16 @@ public class AgentWithGun : Agent
|
||||
public float mouseYSensitivity = 200;
|
||||
public float yRotation = 0.1f;//定义一个浮点类型的量,记录‘围绕’X轴旋转的角度
|
||||
|
||||
[Header("Env")]
|
||||
private bool lockMouse;
|
||||
private float Damage;
|
||||
private float fireRate;
|
||||
private int enemyNum;
|
||||
private int timeLimit;
|
||||
private bool lockCameraX;
|
||||
private bool lockCameraY;
|
||||
//public Vector3 startPosition = new Vector3(9, 1, 18);
|
||||
|
||||
private float startTime = 0;
|
||||
private int shoot = 0;
|
||||
private float lastShootTime = 0.0f;
|
||||
@@ -78,6 +61,7 @@ public class AgentWithGun : Agent
|
||||
private bool gunReadyToggle = true;
|
||||
private RaySensors rayScript;
|
||||
private EnviromentUIControl EnvUICon;
|
||||
private parameterContainer paramContainer;
|
||||
|
||||
[System.NonSerialized] public float minEnemyAreaX;
|
||||
[System.NonSerialized] public float maxEnemyAreaX;
|
||||
@@ -102,17 +86,26 @@ public class AgentWithGun : Agent
|
||||
|
||||
private void Start()
|
||||
{
|
||||
paramContainer = ParameterContainerObj.GetComponent<parameterContainer>();
|
||||
EnvUICon = EnvironmentUIControlObj.GetComponent<EnviromentUIControl>();
|
||||
rayScript = GetComponent<RaySensors>();
|
||||
// give default Reward to Reward value will be used.
|
||||
nonReward = nonRewardDefault;
|
||||
shootReward = shootRewardDefault;
|
||||
shootWithoutReadyReward = shootWithoutReadyRewardDefault;
|
||||
hitReward = hitRewardDefault;
|
||||
winReward = winRewardDefault;
|
||||
loseReward = loseRewardDefault;
|
||||
killReward = killRewardDefault;
|
||||
killBonusReward = killBonusRewardDefault;
|
||||
nonReward = paramContainer.nonRewardDefault;
|
||||
shootReward = paramContainer.shootRewardDefault;
|
||||
shootWithoutReadyReward = paramContainer.shootWithoutReadyRewardDefault;
|
||||
hitReward = paramContainer.hitRewardDefault;
|
||||
winReward = paramContainer.winRewardDefault;
|
||||
loseReward = paramContainer.loseRewardDefault;
|
||||
killReward = paramContainer.killRewardDefault;
|
||||
killBonusReward = paramContainer.killBonusRewardDefault;
|
||||
// Environment parameters
|
||||
lockMouse = paramContainer.lockMouse;
|
||||
Damage = paramContainer.Damage;
|
||||
fireRate = paramContainer.fireRate;
|
||||
enemyNum = paramContainer.enemyNum;
|
||||
timeLimit = paramContainer.timeLimit;
|
||||
lockCameraX = paramContainer.lockCameraX;
|
||||
lockCameraY = paramContainer.lockCameraY;
|
||||
//initialize remainTime
|
||||
remainTime = (int)(timeLimit - Time.time + startTime);
|
||||
|
||||
@@ -330,9 +323,9 @@ public class AgentWithGun : Agent
|
||||
// destroyEnemy消除EnemyContainer内所有Enemy
|
||||
public void destroyAllEnemys()
|
||||
{
|
||||
foreach(Transform childObj in EnemyContainerObj.transform)
|
||||
foreach (Transform childObj in EnemyContainerObj.transform)
|
||||
{
|
||||
if(childObj.tag == "Enemy")
|
||||
if (childObj.tag == "Enemy")
|
||||
{
|
||||
Destroy(childObj.gameObject);
|
||||
}
|
||||
@@ -439,14 +432,6 @@ public class AgentWithGun : Agent
|
||||
nowEnemyNum = getEnemyNum(); // Reset Enemy number
|
||||
// give default Reward to Reward value will be used.
|
||||
EnvUICon.initChart();
|
||||
nonReward = nonRewardDefault;
|
||||
shootReward = shootRewardDefault;
|
||||
shootWithoutReadyReward = shootWithoutReadyRewardDefault;
|
||||
hitReward = hitRewardDefault;
|
||||
winReward = winRewardDefault;
|
||||
loseReward = loseRewardDefault;
|
||||
killReward = killRewardDefault;
|
||||
killBonusReward = killBonusRewardDefault;
|
||||
}
|
||||
|
||||
// ML-AGENTS处理-------------------------------------------------------------------------------------------ML-AGENTS
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class gameFlowController : MonoBehaviour
|
||||
{
|
||||
public GameObject Agent;
|
||||
AgentWithGun agentWithGun;
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
agentWithGun = Agent.GetComponent<AgentWithGun>();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
if (Input.GetKey(KeyCode.Escape))
|
||||
{
|
||||
Application.Quit();
|
||||
}
|
||||
if (Input.GetKey(KeyCode.L))
|
||||
{
|
||||
agentWithGun.lockMouse = !agentWithGun.lockMouse;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9a8fb4d12d4b8fc4784f3e142e7fdcf8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user