分离Parameter为Common Parameter和会随着游戏State改变的Parameter。
将不需要public的一些变量改为private。
This commit is contained in:
@@ -5,14 +5,22 @@ using UnityEngine;
|
||||
|
||||
public class AgentController : MonoBehaviour
|
||||
{
|
||||
public GameObject parameterContainerObj;
|
||||
public GameObject environmentObj;
|
||||
public GameObject enemyContainerObj;
|
||||
public GameObject sceneBlockContainerObj;
|
||||
public GameObject environmentUIControlObj;
|
||||
public GameObject targetControllerObj;
|
||||
public GameObject HUDObj;
|
||||
public Camera fpsCam;
|
||||
[SerializeField]
|
||||
private GameObject commonParameterContainerObj;
|
||||
[SerializeField]
|
||||
private GameObject environmentObj;
|
||||
[SerializeField]
|
||||
private GameObject enemyContainerObj;
|
||||
[SerializeField]
|
||||
private GameObject sceneBlockContainerObj;
|
||||
[SerializeField]
|
||||
private GameObject environmentUIControlObj;
|
||||
[SerializeField]
|
||||
private GameObject targetControllerObj;
|
||||
[SerializeField]
|
||||
private GameObject HUDObj;
|
||||
[SerializeField]
|
||||
private Camera fpsCam;
|
||||
|
||||
[Header("GetAxis() Simulate")]
|
||||
public float moveSpeed = 9.0f;
|
||||
@@ -48,25 +56,25 @@ public class AgentController : MonoBehaviour
|
||||
private RaySensors raySensors;
|
||||
|
||||
private CharacterController playerController;
|
||||
private ParameterContainer paramContainer;
|
||||
private CommonParameterContainer commonPramCon;
|
||||
private SceneBlockContainer blockContainer;
|
||||
private TargetController targetCon;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
// initialize scripts
|
||||
paramContainer = parameterContainerObj.GetComponent<ParameterContainer>();
|
||||
commonPramCon = commonParameterContainerObj.GetComponent<CommonParameterContainer>();
|
||||
blockContainer = sceneBlockContainerObj.GetComponent<SceneBlockContainer>();
|
||||
targetCon = targetControllerObj.GetComponent<TargetController>();
|
||||
raySensors = GetComponent<RaySensors>();
|
||||
playerController = this.transform.GetComponent<CharacterController>();
|
||||
|
||||
// initialize Environment parameters
|
||||
lockMouse = paramContainer.lockMouse;
|
||||
damage = paramContainer.damage;
|
||||
fireRate = paramContainer.fireRate;
|
||||
lockCameraX = paramContainer.lockCameraX;
|
||||
lockCameraY = paramContainer.lockCameraY;
|
||||
lockMouse = commonPramCon.lockMouse;
|
||||
damage = commonPramCon.damage;
|
||||
fireRate = commonPramCon.fireRate;
|
||||
lockCameraX = commonPramCon.lockCameraX;
|
||||
lockCameraY = commonPramCon.lockCameraY;
|
||||
|
||||
// initialize remainTime
|
||||
// this agent's tag
|
||||
@@ -226,24 +234,24 @@ public class AgentController : MonoBehaviour
|
||||
{
|
||||
// im shooting at target but didn't hit enemy
|
||||
// Debug.DrawRay(centerRay.origin, viewPoint-centerRay.origin, Color.blue);
|
||||
return paramContainer.shootTargetAreaReward;
|
||||
return commonPramCon.shootTargetAreaReward;
|
||||
}
|
||||
}
|
||||
}
|
||||
shootState = 0;
|
||||
return paramContainer.shootReward;
|
||||
return commonPramCon.shootReward;
|
||||
}
|
||||
else if (shootState != 0 && gunReadyToggle == false)
|
||||
{
|
||||
// shoot without ready
|
||||
shootState = 0;
|
||||
return paramContainer.shootWithoutReadyReward;
|
||||
return commonPramCon.shootWithoutReadyReward;
|
||||
}
|
||||
else
|
||||
{
|
||||
// do not shoot
|
||||
shootState = 0;
|
||||
return paramContainer.nonReward;
|
||||
return commonPramCon.nonReward;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -294,7 +302,7 @@ public class AgentController : MonoBehaviour
|
||||
// facing to an enemy
|
||||
if (hit.collider.tag != myTag && hit.collider.tag != "Wall")
|
||||
{
|
||||
nowReward = paramContainer.facingReward;
|
||||
nowReward = commonPramCon.facingReward;
|
||||
isFacingtoEnemy = true;
|
||||
}
|
||||
}
|
||||
@@ -318,7 +326,7 @@ public class AgentController : MonoBehaviour
|
||||
if (enemyFacingDistance <= lastEnemyFacingDistance)
|
||||
{
|
||||
// closing to enemy
|
||||
nowReward = 1 / MathF.Sqrt(paramContainer.facingInviewEnemyDisCOEF * enemyFacingDistance + 0.00001f);
|
||||
nowReward = 1 / MathF.Sqrt(commonPramCon.facingInviewEnemyDisCOEF * enemyFacingDistance + 0.00001f);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -326,8 +334,8 @@ public class AgentController : MonoBehaviour
|
||||
}
|
||||
// enemy in view Reward
|
||||
lastEnemyFacingDistance = enemyFacingDistance;
|
||||
if (nowReward >= paramContainer.facingReward) nowReward = paramContainer.facingReward; // limit
|
||||
if (nowReward <= -paramContainer.facingReward) nowReward = -paramContainer.facingReward; // limit
|
||||
if (nowReward >= commonPramCon.facingReward) nowReward = commonPramCon.facingReward; // limit
|
||||
if (nowReward <= -commonPramCon.facingReward) nowReward = -commonPramCon.facingReward; // limit
|
||||
// Debug.Log("ninimum = " + nowReward);
|
||||
}
|
||||
break;
|
||||
@@ -341,12 +349,12 @@ public class AgentController : MonoBehaviour
|
||||
if (camCenterToTarget <= blockContainer.nowBlock.firebasesAreaDiameter / 2)
|
||||
{
|
||||
// Debug.DrawRay(centerRay.origin, viewPoint-centerRay.origin, Color.blue);
|
||||
nowReward = paramContainer.facingReward;
|
||||
nowReward = commonPramCon.facingReward;
|
||||
}
|
||||
else
|
||||
{
|
||||
// while not facing to target
|
||||
nowReward = (lastTargetFacingDistance - camCenterToTarget) * paramContainer.facingTargetReward;
|
||||
nowReward = (lastTargetFacingDistance - camCenterToTarget) * commonPramCon.facingTargetReward;
|
||||
}
|
||||
}
|
||||
// update lastTargetFacingDistance
|
||||
@@ -357,7 +365,7 @@ public class AgentController : MonoBehaviour
|
||||
if (camCenterToTarget <= camCenterToViewEdge)
|
||||
{
|
||||
// fireArea is in view
|
||||
nowReward = paramContainer.facingReward;
|
||||
nowReward = commonPramCon.facingReward;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -395,23 +403,23 @@ public class AgentController : MonoBehaviour
|
||||
// Penalty
|
||||
// spin penalty
|
||||
spinRecord.Add(mouseX);
|
||||
if (spinRecord.Count >= paramContainer.spinRecordMax)
|
||||
if (spinRecord.Count >= commonPramCon.spinRecordMax)
|
||||
{
|
||||
spinRecord.RemoveAt(0);
|
||||
}
|
||||
float spinPenaltyReward = Math.Abs(spinRecord.ToArray().Sum() * paramContainer.spinPenalty);
|
||||
if (spinPenaltyReward >= paramContainer.spinPenaltyThreshold)
|
||||
float spinPenaltyReward = Math.Abs(spinRecord.ToArray().Sum() * commonPramCon.spinPenalty);
|
||||
if (spinPenaltyReward >= commonPramCon.spinPenaltyThreshold)
|
||||
{
|
||||
epreward -= spinPenaltyReward;
|
||||
}
|
||||
else
|
||||
{
|
||||
epreward -= Math.Abs(mouseX) * paramContainer.mousePenalty;
|
||||
epreward -= Math.Abs(mouseX) * commonPramCon.mousePenalty;
|
||||
}
|
||||
// move penalty
|
||||
if (movement != 0)
|
||||
{
|
||||
epreward -= paramContainer.movePenalty;
|
||||
epreward -= commonPramCon.movePenalty;
|
||||
}
|
||||
return epreward;
|
||||
}
|
||||
|
||||
@@ -2,9 +2,9 @@ using UnityEngine;
|
||||
|
||||
public class EnemyContainer : MonoBehaviour
|
||||
{
|
||||
public GameObject enemyPrefab;
|
||||
public GameObject environmentObj;
|
||||
public GameObject targetControllerObj;
|
||||
[SerializeField] public GameObject enemyPrefab;
|
||||
[SerializeField] private GameObject environmentObj;
|
||||
[SerializeField] private GameObject targetControllerObj;
|
||||
|
||||
private TargetController targetCon;
|
||||
|
||||
|
||||
@@ -0,0 +1,123 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class CommonParameterContainer : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private GameObject hudObj;
|
||||
|
||||
private StartSeneData startSceneData;
|
||||
private MessageBoxController messageCon;
|
||||
|
||||
[Header("Env")]
|
||||
public bool lockMouse = false;
|
||||
|
||||
public float damage = 50; // damage to enemy
|
||||
public float fireRate = 0.5f;
|
||||
public int timeLimit = 30;
|
||||
public bool lockCameraX = false;
|
||||
public bool lockCameraY = true;
|
||||
public bool spawnAgentInAllMap = true;
|
||||
public int spinRecordMax = 40;
|
||||
public float spinPenaltyThreshold = 10;
|
||||
public float facingInviewEnemyDisCOEF = 0.5f;
|
||||
|
||||
[Header("Dynamic Defaut Rewards")]
|
||||
//[Tooltip("Hit Enemy reward")]
|
||||
//public float hitRewardDefault = 60.0f;
|
||||
[Tooltip("Free mode Hit Enemy reward")]
|
||||
public float hitTargetRewardDefault = 25f;
|
||||
//[Tooltip("Enemy down reward")]
|
||||
//public float killRewardDefault = 60.0f;
|
||||
[Tooltip("Enemy down in area Reward")]
|
||||
public float killTargetEnemyRewardDefault = 25f;
|
||||
[Tooltip("stay in firebasesArea reward")]
|
||||
public float inAreaRewardDefault = 12f;
|
||||
[Tooltip("free left time bonus reward. ALLR + leftTime * r")]
|
||||
public float freeTimeBonusPerSec = 1.0f;
|
||||
[Tooltip("target left time bonus reward. ALLR + leftTime * r")]
|
||||
public float targetTimeBonusPerSec = 0.5f;
|
||||
[Tooltip("in area left time bonus reward. ALLR + leftTime * r")]
|
||||
public float areaTimeBonusPerSec = 0.2f;
|
||||
[Tooltip("distance reward reward = r*(1-(nowDis/startDis))")]
|
||||
public float distanceReward = 50.0f;
|
||||
[Tooltip("facing to Target distance reward reward = r*(1-(nowDis/startDis))")]
|
||||
public float facingTargetReward = 10.0f;
|
||||
|
||||
[Space(10)]
|
||||
[Tooltip("Goto Win reward")]
|
||||
public float goWinRewardDefault = 999f;
|
||||
[Tooltip("Attack Win reward")]
|
||||
public float attackWinRewardDefault = 999f;
|
||||
[Tooltip("Defence Win reward")]
|
||||
public float defenceWinRewardDefault = 999f;
|
||||
[Tooltip("free Win reward")]
|
||||
public float freeWinRewardDefault = 999f;
|
||||
|
||||
[Header("Static Rewards")]
|
||||
[Tooltip("Nothing happened reward")]
|
||||
public float nonReward = -1f;
|
||||
[Tooltip("Episode Lose reward")]
|
||||
public float loseReward = -999f;
|
||||
[Tooltip("Agent Do shoot action reward")]
|
||||
public float shootReward = -0.5f;
|
||||
[Tooltip("Hit Not target Enemy reward")]
|
||||
public float hitNonTargetReward = -5f;
|
||||
[Tooltip("Not Target Enemy down reward")]
|
||||
public float killNonTargetReward = -5f;
|
||||
[Tooltip("Agent Do shoot action but gun is not read")]
|
||||
public float shootWithoutReadyReward = -1.15f;
|
||||
[Tooltip("Kill bonus reward stack to nothing happend reward")]
|
||||
public float killBonusReward = 0.0f;
|
||||
[Tooltip("Facing to enemy's reward")]
|
||||
public float facingReward = 5f;
|
||||
[Tooltip("Shoot at target area but didn't hit enemy")]
|
||||
public float shootTargetAreaReward = 10f;
|
||||
|
||||
[Header("Penalty Rewards")]
|
||||
[Tooltip("move Penalty Reward")]
|
||||
public float movePenalty = 0.1f;
|
||||
[Tooltip("spiiiiiiin Panalty Reward")]
|
||||
public float spinPenalty = 0.08f;
|
||||
[Tooltip("while move mouse a little bit's penalty")]
|
||||
public float mousePenalty = 0.06f;
|
||||
|
||||
[NonSerialized] public SceneBlocksSet scenePrefabSet;
|
||||
|
||||
[NonSerialized] public int gameMode; // 0 = trainning mode, 1 = play mode
|
||||
[NonSerialized] public float attackProb = 0f;
|
||||
[NonSerialized] public List<float> attackLevelProbs = new List<float>();
|
||||
[NonSerialized] public float gotoProb = 0f;
|
||||
[NonSerialized] public List<float> gotoLevelProbs = new List<float>();
|
||||
[NonSerialized] public float defenceProb = 0f;
|
||||
[NonSerialized] public List<float> defenceLevelProbs = new List<float>();
|
||||
|
||||
private void Start()
|
||||
{
|
||||
messageCon = hudObj.GetComponent<MessageBoxController>();
|
||||
try
|
||||
{
|
||||
// try get start scene data
|
||||
startSceneData = GameObject.Find("StartSceneDataTransfer").GetComponent<StartSeneData>();
|
||||
messageCon.PushMessage(
|
||||
new List<string> { "ParameterContainer:", "StartSceneDataTransfer found!" },
|
||||
new List<string> { "green", "white" });
|
||||
}
|
||||
catch
|
||||
{
|
||||
// if not found, find dummy StartSeneData
|
||||
startSceneData = GameObject.Find("StartSceneDataTransferDummy").GetComponent<StartSeneData>();
|
||||
messageCon.PushMessage(
|
||||
new List<string> { "ParameterContainer:", "StartSceneDataTransfer not found!Use Dummy." },
|
||||
new List<string> { "orange" });
|
||||
}
|
||||
gameMode = startSceneData.gameMode;
|
||||
attackProb = startSceneData.attackProb;
|
||||
attackLevelProbs = startSceneData.attackLevelProbs;
|
||||
gotoProb = startSceneData.gotoProb;
|
||||
gotoLevelProbs = startSceneData.gotoLevelProbs;
|
||||
defenceProb = startSceneData.defenceProb;
|
||||
defenceLevelProbs = startSceneData.defenceLevelProbs;
|
||||
scenePrefabSet = startSceneData.scenePrefabSet;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 34839c2831b759d4a8347ab655b00f36
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -7,11 +7,12 @@ using UnityEngine;
|
||||
|
||||
public class MLAgentsCustomController : Agent
|
||||
{
|
||||
public GameObject paramContainerObj;
|
||||
public GameObject targetControllerObj;
|
||||
public GameObject environmentUIObj;
|
||||
public GameObject sideChannelObj;
|
||||
public GameObject hudUIObj;
|
||||
[SerializeField] private GameObject paramContainerObj;
|
||||
[SerializeField] private GameObject CommonParameterContainer;
|
||||
[SerializeField] private GameObject targetControllerObj;
|
||||
[SerializeField] private GameObject environmentUIObj;
|
||||
[SerializeField] private GameObject sideChannelObj;
|
||||
[SerializeField] private GameObject hudUIObj;
|
||||
|
||||
[Header("Env")]
|
||||
public bool oneHotRayTag = true;
|
||||
@@ -20,6 +21,7 @@ public class MLAgentsCustomController : Agent
|
||||
private AgentController agentController;
|
||||
|
||||
private ParameterContainer paramContainer;
|
||||
private CommonParameterContainer commonParamCon;
|
||||
private TargetController targetController;
|
||||
private EnvironmentUIControl envUIController;
|
||||
private HUDController hudController;
|
||||
@@ -47,6 +49,7 @@ public class MLAgentsCustomController : Agent
|
||||
agentController = transform.GetComponent<AgentController>();
|
||||
raySensors = transform.GetComponent<RaySensors>();
|
||||
paramContainer = paramContainerObj.GetComponent<ParameterContainer>();
|
||||
commonParamCon = CommonParameterContainer.GetComponent<CommonParameterContainer>();
|
||||
targetController = targetControllerObj.GetComponent<TargetController>();
|
||||
envUIController = environmentUIObj.GetComponent<EnvironmentUIControl>();
|
||||
hudController = hudUIObj.GetComponent<HUDController>();
|
||||
@@ -62,7 +65,7 @@ public class MLAgentsCustomController : Agent
|
||||
step = 0;
|
||||
agentController.UpdateLockMouse();
|
||||
paramContainer.ResetTimeBonusReward();
|
||||
if (paramContainer.gameMode == 0)
|
||||
if (commonParamCon.gameMode == 0)
|
||||
{
|
||||
// train mode
|
||||
Debug.Log("MLAgentCustomController.OnEpisodeBegin: train mode start");
|
||||
@@ -178,7 +181,7 @@ public class MLAgentsCustomController : Agent
|
||||
switch (finishedState)
|
||||
{
|
||||
case (int)TargetController.EndType.Win:
|
||||
sideChannelController.SendSideChannelMessage("Result",targetString+ "|Win");
|
||||
sideChannelController.SendSideChannelMessage("Result", targetString + "|Win");
|
||||
messageBoxController.PushMessage(
|
||||
new List<string> { "Game Win" },
|
||||
new List<string> { "green" });
|
||||
|
||||
@@ -3,110 +3,20 @@ using UnityEngine;
|
||||
|
||||
public class ParameterContainer : MonoBehaviour
|
||||
{
|
||||
public GameObject targetConObj;
|
||||
public GameObject blockConObj;
|
||||
public GameObject agentObj;
|
||||
public GameObject hudObj;
|
||||
[SerializeField] private GameObject targetConObj;
|
||||
[SerializeField] private GameObject blockConObj;
|
||||
[SerializeField] private GameObject agentObj;
|
||||
[SerializeField] private GameObject hudObj;
|
||||
[SerializeField] private GameObject CommonParamObj;
|
||||
|
||||
private TargetController targetCon;
|
||||
private SceneBlockContainer blockCont;
|
||||
private StartSeneData startSceneData;
|
||||
private MessageBoxController messageCon;
|
||||
private CommonParameterContainer commonParamCont;
|
||||
private float agentDistance;
|
||||
private int agentInArea;
|
||||
|
||||
[Header("Env")]
|
||||
public bool lockMouse = false;
|
||||
|
||||
public float damage = 50; // damage to enemy
|
||||
public float fireRate = 0.5f;
|
||||
public int timeLimit = 30;
|
||||
public bool lockCameraX = false;
|
||||
public bool lockCameraY = true;
|
||||
public bool spawnAgentInAllMap = true;
|
||||
public int spinRecordMax = 40;
|
||||
public float spinPenaltyThreshold = 10;
|
||||
public float facingInviewEnemyDisCOEF = 0.5f;
|
||||
|
||||
[Header("Dynamic Defaut Rewards")]
|
||||
//[Tooltip("Hit Enemy reward")]
|
||||
//public float hitRewardDefault = 60.0f;
|
||||
[Tooltip("Free mode Hit Enemy reward")]
|
||||
public float hitTargetRewardDefault = 25f;
|
||||
|
||||
//[Tooltip("Enemy down reward")]
|
||||
//public float killRewardDefault = 60.0f;
|
||||
[Tooltip("Enemy down in area Reward")]
|
||||
public float killTargetEnemyRewardDefault = 25f;
|
||||
|
||||
[Tooltip("stay in firebasesArea reward")]
|
||||
public float inAreaRewardDefault = 12f;
|
||||
|
||||
[Tooltip("free left time bonus reward. ALLR + leftTime * r")]
|
||||
public float freeTimeBonusPerSec = 1.0f;
|
||||
|
||||
[Tooltip("target left time bonus reward. ALLR + leftTime * r")]
|
||||
public float targetTimeBonusPerSec = 0.5f;
|
||||
|
||||
[Tooltip("in area left time bonus reward. ALLR + leftTime * r")]
|
||||
public float areaTimeBonusPerSec = 0.2f;
|
||||
|
||||
[Tooltip("distance reward reward = r*(1-(nowDis/startDis))")]
|
||||
public float distanceReward = 50.0f;
|
||||
|
||||
[Tooltip("facing to Target distance reward reward = r*(1-(nowDis/startDis))")]
|
||||
public float facingTargetReward = 10.0f;
|
||||
|
||||
[Space(10)]
|
||||
[Tooltip("Goto Win reward")]
|
||||
public float goWinRewardDefault = 999f;
|
||||
|
||||
[Tooltip("Attack Win reward")]
|
||||
public float attackWinRewardDefault = 999f;
|
||||
|
||||
[Tooltip("Defence Win reward")]
|
||||
public float defenceWinRewardDefault = 999f;
|
||||
|
||||
[Tooltip("free Win reward")]
|
||||
public float freeWinRewardDefault = 999f;
|
||||
|
||||
[Header("Static Rewards")]
|
||||
[Tooltip("Nothing happened reward")]
|
||||
public float nonReward = -1f;
|
||||
|
||||
[Tooltip("Episode Lose reward")]
|
||||
public float loseReward = -999f;
|
||||
|
||||
[Tooltip("Agent Do shoot action reward")]
|
||||
public float shootReward = -0.5f;
|
||||
|
||||
[Tooltip("Hit Not target Enemy reward")]
|
||||
public float hitNonTargetReward = -5f;
|
||||
|
||||
[Tooltip("Not Target Enemy down reward")]
|
||||
public float killNonTargetReward = -5f;
|
||||
|
||||
[Tooltip("Agent Do shoot action but gun is not read")]
|
||||
public float shootWithoutReadyReward = -1.15f;
|
||||
|
||||
[Tooltip("Kill bonus reward stack to nothing happend reward")]
|
||||
public float killBonusReward = 0.0f;
|
||||
|
||||
[Tooltip("Facing to enemy's reward")]
|
||||
public float facingReward = 5f;
|
||||
|
||||
[Tooltip("Shoot at target area but didn't hit enemy")]
|
||||
public float shootTargetAreaReward = 10f;
|
||||
|
||||
[Header("Penalty Rewards")]
|
||||
[Tooltip("move Penalty Reward")]
|
||||
public float movePenalty = 0.1f;
|
||||
|
||||
[Tooltip("spiiiiiiin Panalty Reward")]
|
||||
public float spinPenalty = 0.08f;
|
||||
|
||||
[Tooltip("while move mouse a little bit's penalty")]
|
||||
public float mousePenalty = 0.06f;
|
||||
|
||||
[Header("Dynamic Rewards")]
|
||||
[Tooltip("Free mode Hit Enemy reward")]
|
||||
public float hitTargetReward = 60.0f;
|
||||
@@ -130,28 +40,29 @@ public class ParameterContainer : MonoBehaviour
|
||||
[Tooltip("free Win reward")]
|
||||
public float freeWinReward = 50.0f;
|
||||
|
||||
[Tooltip("Scene Prefab Set")]
|
||||
public SceneBlocksSet scenePrefabSet;
|
||||
|
||||
private float targetTimeBonus = 0f;
|
||||
private float areaTimeBonus = 0f;
|
||||
private float freeTimeBonus = 0f;
|
||||
private float targetInAreaTime = 0f;
|
||||
private float lastFrameTime = 0f;
|
||||
|
||||
[System.NonSerialized] public int gameMode; // 0 = trainning mode, 1 = play mode
|
||||
[System.NonSerialized] public float attackProb = 0f;
|
||||
[System.NonSerialized] public List<float> attackLevelProbs = new List<float>();
|
||||
[System.NonSerialized] public float gotoProb = 0f;
|
||||
[System.NonSerialized] public List<float> gotoLevelProbs = new List<float>();
|
||||
[System.NonSerialized] public float defenceProb = 0f;
|
||||
[System.NonSerialized] public List<float> defenceLevelProbs = new List<float>();
|
||||
private float areaTimeBonusPerSec;
|
||||
private float freeTimeBonusPerSec;
|
||||
private float targetTimeBonusPerSec;
|
||||
private int timeLimit = 30;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
targetCon = targetConObj.GetComponent<TargetController>();
|
||||
blockCont = blockConObj.GetComponent<SceneBlockContainer>();
|
||||
messageCon = hudObj.GetComponent<MessageBoxController>();
|
||||
commonParamCont = CommonParamObj.GetComponent<CommonParameterContainer>();
|
||||
|
||||
areaTimeBonusPerSec = commonParamCont.areaTimeBonusPerSec;
|
||||
freeTimeBonusPerSec = commonParamCont.freeTimeBonusPerSec;
|
||||
targetTimeBonusPerSec = commonParamCont.targetTimeBonusPerSec;
|
||||
timeLimit = commonParamCont.timeLimit;
|
||||
|
||||
areaTimeBonus = areaTimeBonusPerSec * timeLimit;
|
||||
freeTimeBonus = freeTimeBonusPerSec * timeLimit;
|
||||
targetTimeBonus = targetTimeBonusPerSec * timeLimit;
|
||||
@@ -171,14 +82,12 @@ public class ParameterContainer : MonoBehaviour
|
||||
new List<string> { "ParameterContainer:", "StartSceneDataTransfer not found!Use Dummy." },
|
||||
new List<string> { "orange" });
|
||||
}
|
||||
gameMode = startSceneData.gameMode;
|
||||
attackProb = startSceneData.attackProb;
|
||||
attackLevelProbs = startSceneData.attackLevelProbs;
|
||||
gotoProb = startSceneData.gotoProb;
|
||||
gotoLevelProbs = startSceneData.gotoLevelProbs;
|
||||
defenceProb = startSceneData.defenceProb;
|
||||
defenceLevelProbs = startSceneData.defenceLevelProbs;
|
||||
scenePrefabSet = startSceneData.scenePrefabSet;
|
||||
|
||||
// Win Rewards
|
||||
goWinReward = commonParamCont.goWinRewardDefault;
|
||||
attackWinReward = commonParamCont.attackWinRewardDefault;
|
||||
defenceWinReward = commonParamCont.defenceWinRewardDefault;
|
||||
freeWinReward = commonParamCont.freeWinRewardDefault;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
@@ -206,15 +115,9 @@ public class ParameterContainer : MonoBehaviour
|
||||
targetTimeBonus = targetTimeBonusPerSec * targetCon.leftTime;
|
||||
}
|
||||
|
||||
hitTargetReward = hitTargetRewardDefault + targetTimeBonus;
|
||||
killTargetEnemyReward = killTargetEnemyRewardDefault + targetTimeBonus;
|
||||
inAreaReward = inAreaRewardDefault + areaTimeBonus;
|
||||
|
||||
// Win Rewards
|
||||
goWinReward = goWinRewardDefault;
|
||||
attackWinReward = attackWinRewardDefault;
|
||||
defenceWinReward = defenceWinRewardDefault;
|
||||
freeWinReward = freeWinRewardDefault;
|
||||
hitTargetReward = commonParamCont.hitTargetRewardDefault + targetTimeBonus;
|
||||
killTargetEnemyReward = commonParamCont.killTargetEnemyRewardDefault + targetTimeBonus;
|
||||
inAreaReward = commonParamCont.inAreaRewardDefault + areaTimeBonus;
|
||||
}
|
||||
|
||||
public void ResetTimeBonusReward()
|
||||
|
||||
@@ -6,11 +6,11 @@ using UnityEngine;
|
||||
|
||||
public class RaySensors : MonoBehaviour
|
||||
{
|
||||
public Camera agentCam;
|
||||
public Camera TPSCam;
|
||||
public Material lineMeterial;
|
||||
public GameObject rayInfoPrefab;
|
||||
public GameObject agentCanvas;
|
||||
[SerializeField] private Camera agentCam;
|
||||
[SerializeField] private Camera TPSCam;
|
||||
[SerializeField] private Material lineMeterial;
|
||||
[SerializeField] private GameObject rayInfoPrefab;
|
||||
[SerializeField] private GameObject agentCanvas;
|
||||
|
||||
[SerializeField, Range(0, 500)] public float viewDistance = 100; // how long the ray can detect
|
||||
|
||||
|
||||
@@ -2,10 +2,14 @@
|
||||
|
||||
public class SceneBlockContainer : MonoBehaviour
|
||||
{
|
||||
public float sceneSize = 10f;
|
||||
public GameObject environmentObj;
|
||||
public GameObject parameterContainerObj;
|
||||
public GameObject hudObj;
|
||||
[SerializeField]
|
||||
private float sceneSize = 10f;
|
||||
[SerializeField]
|
||||
private GameObject environmentObj;
|
||||
[SerializeField]
|
||||
private GameObject commonParameterContainerObj;
|
||||
[SerializeField]
|
||||
private GameObject hudObj;
|
||||
|
||||
// public GameObject[] attackBlockPrefabs = new GameObject[1];
|
||||
// public GameObject[] goBlockPrefabs = new GameObject[1];
|
||||
@@ -13,11 +17,11 @@ public class SceneBlockContainer : MonoBehaviour
|
||||
|
||||
public SceneBlock nowBlock;
|
||||
private GameObject nowBlockObj;
|
||||
private ParameterContainer paramCon;
|
||||
private CommonParameterContainer commonParamCon;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
paramCon = parameterContainerObj.GetComponent<ParameterContainer>();
|
||||
commonParamCon = commonParameterContainerObj.GetComponent<CommonParameterContainer>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -40,7 +44,7 @@ public class SceneBlockContainer : MonoBehaviour
|
||||
DestroyBlock();
|
||||
}
|
||||
// choose target type
|
||||
nowBlockObj = Instantiate(paramCon.scenePrefabSet.GetPrefab(level, blockType, targetType), blockPosition + environmentObj.transform.position, Quaternion.identity, transform);
|
||||
nowBlockObj = Instantiate(commonParamCon.scenePrefabSet.GetPrefab(level, blockType, targetType), blockPosition + environmentObj.transform.position, Quaternion.identity, transform);
|
||||
nowBlock = nowBlockObj.GetComponent<SceneBlock>();
|
||||
nowBlock.group1Tag = tag1;
|
||||
nowBlock.group2Tag = tag2;
|
||||
|
||||
@@ -5,14 +5,24 @@ using Random = UnityEngine.Random;
|
||||
|
||||
public class TargetController : MonoBehaviour
|
||||
{
|
||||
public GameObject environmentObj;
|
||||
public GameObject agentObj;
|
||||
public GameObject HUDObj;
|
||||
public GameObject sceneBlockContainerObj;
|
||||
public GameObject enemyContainerObj;
|
||||
public GameObject parameterContainerObj;
|
||||
public GameObject environmentUIObj;
|
||||
public GameObject worldUIObj;
|
||||
[SerializeField]
|
||||
private GameObject environmentObj;
|
||||
[SerializeField]
|
||||
private GameObject agentObj;
|
||||
[SerializeField]
|
||||
private GameObject HUDObj;
|
||||
[SerializeField]
|
||||
private GameObject sceneBlockContainerObj;
|
||||
[SerializeField]
|
||||
private GameObject enemyContainerObj;
|
||||
[SerializeField]
|
||||
private GameObject parameterContainerObj;
|
||||
[SerializeField]
|
||||
private GameObject commonParameterContainerObj;
|
||||
[SerializeField]
|
||||
private GameObject environmentUIObj;
|
||||
[SerializeField]
|
||||
private GameObject worldUIObj;
|
||||
|
||||
// area
|
||||
public GameObject edgeUp;
|
||||
@@ -62,10 +72,12 @@ public class TargetController : MonoBehaviour
|
||||
public Vector3 targetPosition;
|
||||
private bool firstRewardFlag = true;
|
||||
private bool targetEnemySpawnFinish = false;
|
||||
|
||||
private SceneBlockContainer sceneBlockCon;
|
||||
private EnemyContainer enemyCon;
|
||||
private EnvironmentUIControl envUICon;
|
||||
private ParameterContainer paramCon;
|
||||
private CommonParameterContainer commonParamCon;
|
||||
private CharacterController agentCharaCon;
|
||||
private WorldUIController worldUICon;
|
||||
private HUDController hudCon;
|
||||
@@ -77,6 +89,7 @@ public class TargetController : MonoBehaviour
|
||||
// Start is called before the first frame update
|
||||
private void Start()
|
||||
{
|
||||
commonParamCon = commonParameterContainerObj.GetComponent<CommonParameterContainer>();
|
||||
sceneBlockCon = sceneBlockContainerObj.GetComponent<SceneBlockContainer>();
|
||||
envUICon = environmentUIObj.GetComponent<EnvironmentUIControl>();
|
||||
enemyCon = enemyContainerObj.GetComponent<EnemyContainer>();
|
||||
@@ -87,10 +100,10 @@ public class TargetController : MonoBehaviour
|
||||
messageBoxCon = HUDObj.GetComponent<MessageBoxController>();
|
||||
|
||||
// get parameter from ParameterContainer
|
||||
gamemode = paramCon.gameMode;
|
||||
attackProb = paramCon.attackProb;
|
||||
gotoProb = paramCon.gotoProb;
|
||||
defenceProb = paramCon.defenceProb;
|
||||
gamemode = commonParamCon.gameMode;
|
||||
attackProb = commonParamCon.attackProb;
|
||||
gotoProb = commonParamCon.gotoProb;
|
||||
defenceProb = commonParamCon.defenceProb;
|
||||
|
||||
// initialize spawn area
|
||||
minEnemyAreaX = edgeLeft.transform.localPosition.x + 1.0f;
|
||||
@@ -105,8 +118,8 @@ public class TargetController : MonoBehaviour
|
||||
|
||||
freeProb = 1 - attackProb - gotoProb - defenceProb;
|
||||
targetNum = (int)Targets.Num;
|
||||
gotoLevelNum = paramCon.scenePrefabSet.GetLevelNumber(Targets.Go);
|
||||
attackLevelNum = paramCon.scenePrefabSet.GetLevelNumber(Targets.Attack);
|
||||
gotoLevelNum = commonParamCon.scenePrefabSet.GetLevelNumber(Targets.Go);
|
||||
attackLevelNum = commonParamCon.scenePrefabSet.GetLevelNumber(Targets.Attack);
|
||||
if (freeProb < 0)
|
||||
{
|
||||
Debug.LogError("TargetController.Start: target percentage wrong");
|
||||
@@ -130,13 +143,13 @@ public class TargetController : MonoBehaviour
|
||||
// if gamemode is play, then time will keep paramCon.timeLimit
|
||||
if (gamemode == 1)
|
||||
{
|
||||
leftTime = paramCon.timeLimit;
|
||||
leftTime = commonParamCon.timeLimit;
|
||||
// print out time
|
||||
// Debug.Log("Playing Time: " + leftTime);
|
||||
}
|
||||
else
|
||||
{
|
||||
leftTime = paramCon.timeLimit - Time.time + startTime;
|
||||
leftTime = commonParamCon.timeLimit - Time.time + startTime;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -152,7 +165,7 @@ public class TargetController : MonoBehaviour
|
||||
public void RollNewScene()
|
||||
{
|
||||
startTime = Time.time;// Reset StartTime as now time
|
||||
leftTime = paramCon.timeLimit - Time.time + startTime;
|
||||
leftTime = commonParamCon.timeLimit - Time.time + startTime;
|
||||
float randTargetType = UnityEngine.Random.Range(0f, 1f);
|
||||
if (randTargetType <= gotoProb)
|
||||
{
|
||||
@@ -205,7 +218,7 @@ public class TargetController : MonoBehaviour
|
||||
{
|
||||
float randX = UnityEngine.Random.Range(minAgentAreaX, maxAgentAreaX); ;
|
||||
float randZ = 0f;
|
||||
if (paramCon.spawnAgentInAllMap)
|
||||
if (commonParamCon.spawnAgentInAllMap)
|
||||
{
|
||||
// spawn agent in all around map
|
||||
randZ = UnityEngine.Random.Range(minAgentAreaZ, maxEnemyAreaZ);
|
||||
@@ -257,8 +270,8 @@ public class TargetController : MonoBehaviour
|
||||
private void RandomSpawnSceneBlock(Targets targetType)
|
||||
{
|
||||
randLevel = RollRandomLevelIndex(targetType);
|
||||
randBlockType = Random.Range(0, paramCon.scenePrefabSet.GetBlockNumber(randLevel,targetType));
|
||||
sceneBlockSize = paramCon.scenePrefabSet.GetBlockSize(randLevel, randBlockType, targetType);
|
||||
randBlockType = Random.Range(0, commonParamCon.scenePrefabSet.GetBlockNumber(randLevel,targetType));
|
||||
sceneBlockSize = commonParamCon.scenePrefabSet.GetBlockSize(randLevel, randBlockType, targetType);
|
||||
|
||||
float randX = UnityEngine.Random.Range(minEnemyAreaX + sceneBlockSize / 2 + 1f, maxEnemyAreaX - sceneBlockSize / 2 - 1f);
|
||||
float randZ = UnityEngine.Random.Range(minEnemyAreaZ + sceneBlockSize / 2 + 1f, maxEnemyAreaZ - sceneBlockSize / 2 - 1f);
|
||||
@@ -308,7 +321,7 @@ public class TargetController : MonoBehaviour
|
||||
{
|
||||
// time out lose
|
||||
nowReward = areaTargetReward;
|
||||
endReward = paramCon.loseReward;
|
||||
endReward = commonParamCon.loseReward;
|
||||
endTypeInt = (int)EndType.Lose;
|
||||
}
|
||||
else
|
||||
@@ -338,7 +351,7 @@ public class TargetController : MonoBehaviour
|
||||
{
|
||||
// time out lose
|
||||
nowReward = 0;
|
||||
endReward = paramCon.loseReward;
|
||||
endReward = commonParamCon.loseReward;
|
||||
//nowReward = (paramCon.inAreaReward * inArea) + getSceneReward(nowDistance);
|
||||
endTypeInt = (int)EndType.Lose;
|
||||
targetEnemySpawnFinish = false;
|
||||
@@ -370,7 +383,7 @@ public class TargetController : MonoBehaviour
|
||||
else if (sceneBlockCon.nowBlock.firebasesBelong <= sceneBlockCon.nowBlock.belongMaxPoint)
|
||||
{
|
||||
// lost area lose
|
||||
nowReward = paramCon.loseReward;
|
||||
nowReward = commonParamCon.loseReward;
|
||||
//nowReward = (paramCon.inAreaReward * inArea) + getSceneReward(nowDistance);
|
||||
endTypeInt = (int)EndType.Lose;
|
||||
}
|
||||
@@ -405,7 +418,7 @@ public class TargetController : MonoBehaviour
|
||||
// lose
|
||||
//nowReward = paramCon.loseReward;
|
||||
nowReward = 0;
|
||||
endReward = paramCon.loseReward;
|
||||
endReward = commonParamCon.loseReward;
|
||||
endTypeInt = (int)EndType.Lose;
|
||||
}
|
||||
else
|
||||
@@ -447,7 +460,7 @@ public class TargetController : MonoBehaviour
|
||||
{
|
||||
// out of area
|
||||
// nowSeneReward = paramCon.distanceReward * Math.Clamp(lastDistance - nowDistance, 0, 100);
|
||||
nowSeneReward = paramCon.distanceReward * (lastDistance - nowDistance);
|
||||
nowSeneReward = commonParamCon.distanceReward * (lastDistance - nowDistance);
|
||||
}
|
||||
lastDistance = nowDistance;
|
||||
return nowSeneReward;
|
||||
@@ -473,7 +486,7 @@ public class TargetController : MonoBehaviour
|
||||
}
|
||||
else
|
||||
{
|
||||
nowKillReward = paramCon.killNonTargetReward;
|
||||
nowKillReward = commonParamCon.killNonTargetReward;
|
||||
}
|
||||
}
|
||||
else if (targetTypeInt == (int)Targets.Free)
|
||||
@@ -484,7 +497,7 @@ public class TargetController : MonoBehaviour
|
||||
else
|
||||
{
|
||||
// goto & defence
|
||||
nowKillReward = paramCon.killNonTargetReward;
|
||||
nowKillReward = commonParamCon.killNonTargetReward;
|
||||
}
|
||||
return nowKillReward;
|
||||
}
|
||||
@@ -510,7 +523,7 @@ public class TargetController : MonoBehaviour
|
||||
else
|
||||
{
|
||||
// hit not in area enemy
|
||||
nowHitReward = paramCon.hitNonTargetReward;
|
||||
nowHitReward = commonParamCon.hitNonTargetReward;
|
||||
}
|
||||
}
|
||||
else if (targetTypeInt == (int)Targets.Free)
|
||||
@@ -521,7 +534,7 @@ public class TargetController : MonoBehaviour
|
||||
else
|
||||
{
|
||||
// goto & defence
|
||||
nowHitReward = paramCon.hitNonTargetReward;
|
||||
nowHitReward = commonParamCon.hitNonTargetReward;
|
||||
}
|
||||
return nowHitReward;
|
||||
}
|
||||
@@ -645,13 +658,13 @@ public class TargetController : MonoBehaviour
|
||||
switch (target)
|
||||
{
|
||||
case Targets.Attack:
|
||||
targetProbs = paramCon.attackLevelProbs;
|
||||
targetProbs = commonParamCon.attackLevelProbs;
|
||||
break;
|
||||
case Targets.Go:
|
||||
targetProbs = paramCon.gotoLevelProbs;
|
||||
targetProbs = commonParamCon.gotoLevelProbs;
|
||||
break;
|
||||
case Targets.Defence:
|
||||
targetProbs = paramCon.defenceLevelProbs;
|
||||
targetProbs = commonParamCon.defenceLevelProbs;
|
||||
break;
|
||||
default:
|
||||
messageBoxCon.PushMessage(
|
||||
|
||||
Reference in New Issue
Block a user